Class: Fluent::Plugin::Prometheus::Metric
- Inherits:
-
Object
- Object
- Fluent::Plugin::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) ⇒ Object
Constructor Details
#initialize(element, registry, labels) ⇒ Metric
Returns a new instance of Metric.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/fluent/plugin/prometheus.rb', line 141 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::Plugin::Prometheus.parse_labels_elements(element) @base_labels = labels.merge(@base_labels) end |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
139 140 141 |
# File 'lib/fluent/plugin/prometheus.rb', line 139 def desc @desc end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
138 139 140 |
# File 'lib/fluent/plugin/prometheus.rb', line 138 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
137 138 139 |
# File 'lib/fluent/plugin/prometheus.rb', line 137 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
136 137 138 |
# File 'lib/fluent/plugin/prometheus.rb', line 136 def type @type end |
Class Method Details
.get(registry, name, type, docstring) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/fluent/plugin/prometheus.rb', line 168 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) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fluent/plugin/prometheus.rb', line 156 def labels(record, ) label = {} @base_labels.each do |k, v| if v.is_a?(String) label[k] = .(v) else label[k] = v.call(record) end end label end |