Class: Fluent::Prometheus::Metric
- Inherits:
-
Object
- Object
- Fluent::Prometheus::Metric
- Defined in:
- lib/fluent/plugin/prometheus.rb
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(element, registry, labels) ⇒ Metric
constructor
A new instance of Metric.
- #labels(record, expander, placeholders) ⇒ Object
Constructor Details
#initialize(element, registry, labels) ⇒ Metric
Returns a new instance of Metric.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fluent/plugin/prometheus.rb', line 92 def initialize(element, registry, labels) ['name', 'desc'].each do |key| if element[key].nil? raise ConfigError, "metric requires '#{key}' option" end end @type = element['type'] @name = element['name'] @key = element['key'] @desc = element['desc'] @base_labels = Fluent::Prometheus.parse_labels_elements(element) @base_labels = labels.merge(@base_labels) end |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
90 91 92 |
# File 'lib/fluent/plugin/prometheus.rb', line 90 def desc @desc end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
89 90 91 |
# File 'lib/fluent/plugin/prometheus.rb', line 89 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
88 89 90 |
# File 'lib/fluent/plugin/prometheus.rb', line 88 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
87 88 89 |
# File 'lib/fluent/plugin/prometheus.rb', line 87 def type @type end |
Class Method Details
.get(registry, name, type, docstring) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/fluent/plugin/prometheus.rb', line 115 def self.get(registry, name, type, docstring) metric = registry.get(name) # should have same type, docstring if metric.type != type raise AlreadyRegisteredError, "#{name} has already been registered as #{type} type" end if metric.docstring != docstring raise AlreadyRegisteredError, "#{name} has already been registered with different docstring" end metric end |
Instance Method Details
#labels(record, expander, placeholders) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/fluent/plugin/prometheus.rb', line 107 def labels(record, , placeholders) label = {} @base_labels.each do |k, v| label[k] = .(v, placeholders) end label end |