class Fluent::Plugin::Metrics
Constants
- DEFAULT_TYPE
Attributes
has_methods_for_counter[R]
has_methods_for_gauge[R]
use_gauge_metric[R]
Public Class Methods
new()
click to toggle source
Calls superclass method
Fluent::PluginLoggerMixin::new
# File lib/fluent/plugin/metrics.rb, line 42 def initialize super @has_methods_for_counter = false @has_methods_for_gauge = false @use_gauge_metric = false end
Public Instance Methods
add(value)
click to toggle source
# File lib/fluent/plugin/metrics.rb, line 82 def add(value) raise NotImplementedError, "Implement this method in child class" end
configure(conf)
click to toggle source
Calls superclass method
Fluent::PluginLoggerMixin#configure
# File lib/fluent/plugin/metrics.rb, line 50 def configure(conf) super if use_gauge_metric @has_methods_for_gauge = has_methods_for_gauge? else @has_methods_for_counter = has_methods_for_counter? end end
create(namespace:, subsystem:,name:,help_text:,labels: {})
click to toggle source
# File lib/fluent/plugin/metrics.rb, line 66 def create(namespace:, subsystem:,name:,help_text:,labels: {}) # This API is for cmetrics type. end
dec()
click to toggle source
# File lib/fluent/plugin/metrics.rb, line 78 def dec raise NotImplementedError, "Implement this method in child class" end
get()
click to toggle source
# File lib/fluent/plugin/metrics.rb, line 70 def get raise NotImplementedError, "Implement this method in child class" end
inc()
click to toggle source
# File lib/fluent/plugin/metrics.rb, line 74 def inc raise NotImplementedError, "Implement this method in child class" end
set(value)
click to toggle source
# File lib/fluent/plugin/metrics.rb, line 90 def set(value) raise NotImplementedError, "Implement this method in child class" end
sub(value)
click to toggle source
# File lib/fluent/plugin/metrics.rb, line 86 def sub(value) raise NotImplementedError, "Implement this method in child class" end
use_gauge_metric=(use_gauge_metric=false)
click to toggle source
Some metrics should be counted by gauge. ref: prometheus.io/docs/concepts/metric_types/#gauge
# File lib/fluent/plugin/metrics.rb, line 62 def use_gauge_metric=(use_gauge_metric=false) @use_gauge_metric = use_gauge_metric end
Private Instance Methods
has_methods_for_counter?()
click to toggle source
# File lib/fluent/plugin/metrics.rb, line 96 def has_methods_for_counter? implemented_methods = self.class.instance_methods(false) if [:get, :inc, :add].all? {|e| implemented_methods.include?(e)} && [:set].all?{|e| self.class.method_defined?(e)} true else raise "BUG: metrics plugin on counter mode MUST implement `get`, `inc`, `add` methods. And aliased `set` methods should be aliased from another method" end end
has_methods_for_gauge?()
click to toggle source
# File lib/fluent/plugin/metrics.rb, line 107 def has_methods_for_gauge? implemented_methods = self.class.instance_methods(false) if [:get, :inc, :add].all? {|e| implemented_methods.include?(e)} && [:set, :dec, :sub].all?{|e| self.class.method_defined?(e)} true else raise "BUG: metrics plugin on gauge mode MUST implement `get`, `inc`, and `add` methods. And `dec`, `sub`, and `set` methods should be aliased from other methods" end end