Module: Fluent::PluginHelper::Metrics
Instance Attribute Summary collapse
Instance Method Summary
collapse
#system_config, #system_config_override
Instance Attribute Details
#_metrics ⇒ Object
31
32
33
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 31
def _metrics
@_metrics
end
|
Instance Method Details
#after_shutdown ⇒ Object
112
113
114
115
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 112
def after_shutdown
metrics_operate(:after_shutdown)
super
end
|
#before_shutdown ⇒ Object
102
103
104
105
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 102
def before_shutdown
metrics_operate(:before_shutdown)
super
end
|
#close ⇒ Object
117
118
119
120
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 117
def close
metrics_operate(:close)
super
end
|
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 39
def configure(conf)
super
@plugin_type_or_id = if self.plugin_id_configured?
self.plugin_id
else
if type = (conf["@type"] || conf["type"])
"#{type}.#{self.plugin_id}"
else
"#{self.class.to_s.split("::").last.downcase}.#{self.plugin_id}"
end
end
end
|
#initialize ⇒ Object
33
34
35
36
37
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 33
def initialize
super
@_metrics_started = false
@_metrics = {} end
|
#metrics_create(namespace: "fluentd", subsystem: "metrics", name:, help_text:, labels: {}, prefer_gauge: false) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 53
def metrics_create(namespace: "fluentd", subsystem: "metrics", name:, help_text:, labels: {}, prefer_gauge: false)
metrics = if system_config.metrics
Fluent::Plugin.new_metrics(system_config.metrics[:@type], parent: self)
else
Fluent::Plugin.new_metrics(Fluent::Plugin::Metrics::DEFAULT_TYPE, parent: self)
end
config = if system_config.metrics
system_config.metrics.corresponding_config_element
else
Fluent::Config::Element.new('metrics', '', {'@type' => Fluent::Plugin::Metrics::DEFAULT_TYPE}, [])
end
metrics.use_gauge_metric = prefer_gauge
metrics.configure(config)
if Fluent::Engine.system_config.workers > 1
labels.merge!(worker_id: fluentd_worker_id.to_s)
end
labels.merge!(plugin: @plugin_type_or_id)
metrics.create(namespace: namespace, subsystem: subsystem, name: name, help_text: help_text, labels: labels)
@_metrics["#{@plugin_type_or_id}_#{namespace}_#{subsystem}_#{name}"] = metrics
metrics
end
|
#metrics_operate(method_name, &block) ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 78
def metrics_operate(method_name, &block)
@_metrics.each_pair do |key, m|
begin
block.call(s) if block_given?
m.__send__(method_name)
rescue => e
log.error "unexpected error while #{method_name}", key: key, metrics: m, error: e
end
end
end
|
#shutdown ⇒ Object
107
108
109
110
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 107
def shutdown
metrics_operate(:shutdown)
super
end
|
#start ⇒ Object
89
90
91
92
93
94
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 89
def start
super
metrics_operate(:start)
@_metrics_started = true
end
|
#stop ⇒ Object
96
97
98
99
100
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 96
def stop
super
metrics_operate(:stop)
end
|
#terminate ⇒ Object
122
123
124
125
126
|
# File 'lib/fluent/plugin_helper/metrics.rb', line 122
def terminate
metrics_operate(:terminate)
@_metrics = {}
super
end
|