Class: RubyScriptExporter::Measurement
- Inherits:
-
Object
- Object
- RubyScriptExporter::Measurement
- Defined in:
- lib/ruby_script_exporter/measurement.rb
Instance Attribute Summary collapse
-
#measurement ⇒ Object
readonly
Returns the value of attribute measurement.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #combined_labels ⇒ Object
- #format_as_open_metric ⇒ Object
-
#initialize(measurement, value, timestamp: nil, probe: nil, **labels) ⇒ Measurement
constructor
A new instance of Measurement.
- #to_s ⇒ Object
Constructor Details
#initialize(measurement, value, timestamp: nil, probe: nil, **labels) ⇒ Measurement
Returns a new instance of Measurement.
7 8 9 10 11 12 13 |
# File 'lib/ruby_script_exporter/measurement.rb', line 7 def initialize(measurement, value, timestamp: nil, probe: nil, **labels) @measurement = measurement @value = value @probe = probe @labels = labels @timestamp = end |
Instance Attribute Details
#measurement ⇒ Object (readonly)
Returns the value of attribute measurement.
4 5 6 |
# File 'lib/ruby_script_exporter/measurement.rb', line 4 def measurement @measurement end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/ruby_script_exporter/measurement.rb', line 5 def value @value end |
Instance Method Details
#combined_labels ⇒ Object
19 20 21 22 23 |
# File 'lib/ruby_script_exporter/measurement.rb', line 19 def combined_labels return @labels unless @probe @probe.combined_labels.merge(@labels) end |
#format_as_open_metric ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_script_exporter/measurement.rb', line 25 def format_as_open_metric line = @measurement.to_s if combined_labels.any? line << '{' line << combined_labels.map do |key, value| "#{key}=\"#{value}\"" end.join(',') line << '}' end line << ' ' line << @value.to_s if @probe&.caches_result? line << ' ' line << @timestamp.to_s end line end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/ruby_script_exporter/measurement.rb', line 15 def to_s "<Measurement #{@measurement} #{@value} #{@labels.inspect}>" end |