Class: RubyScriptExporter::Type
- Inherits:
-
Object
- Object
- RubyScriptExporter::Type
- Defined in:
- lib/ruby_script_exporter/type.rb
Instance Attribute Summary collapse
-
#global ⇒ Object
readonly
Returns the value of attribute global.
Class Method Summary collapse
- .from_name(name) ⇒ Object
- .register_type(name, type, help = nil, global: false) ⇒ Object
- .reset_types ⇒ Object
- .types ⇒ Object
Instance Method Summary collapse
- #format_for_open_metrics ⇒ Object
-
#initialize(name, type, help = nil, global: false) ⇒ Type
constructor
A new instance of Type.
Constructor Details
#initialize(name, type, help = nil, global: false) ⇒ Type
Returns a new instance of Type.
8 9 10 11 12 13 |
# File 'lib/ruby_script_exporter/type.rb', line 8 def initialize(name, type, help = nil, global: false) @name = name @type = type @help = help @global = global end |
Instance Attribute Details
#global ⇒ Object (readonly)
Returns the value of attribute global.
4 5 6 |
# File 'lib/ruby_script_exporter/type.rb', line 4 def global @global end |
Class Method Details
.from_name(name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_script_exporter/type.rb', line 21 def self.from_name(name) type = @types[name.to_sym] unless type puts "Warning type for measurement #{name} not found, defaulting to gauge." type = register_type(name, :gauge) end type end |
.register_type(name, type, help = nil, global: false) ⇒ Object
15 16 17 18 19 |
# File 'lib/ruby_script_exporter/type.rb', line 15 def self.register_type(name, type, help = nil, global: false) raise ArgumentError, "Type for measurement '#{name}' already registered." if @types.key?(name) @types[name.to_sym] = Type.new(name, type, help, global: global) end |
.reset_types ⇒ Object
36 37 38 |
# File 'lib/ruby_script_exporter/type.rb', line 36 def self.reset_types @types = @types.select { |_, v| v.global } end |
.types ⇒ Object
32 33 34 |
# File 'lib/ruby_script_exporter/type.rb', line 32 def self.types @types end |
Instance Method Details
#format_for_open_metrics ⇒ Object
40 41 42 43 44 45 |
# File 'lib/ruby_script_exporter/type.rb', line 40 def format_for_open_metrics type_description = '' type_description << "# HELP #{@name} #{@help}\n" if @help type_description << "# TYPE #{@name} #{@type}" type_description end |