Class: Fluent::Plugin::PrometheusTailMonitorInput
- Inherits:
-
Input
- Object
- Input
- Fluent::Plugin::PrometheusTailMonitorInput
- Defined in:
- lib/fluent/plugin/in_prometheus_tail_monitor.rb
Constant Summary collapse
- MONITOR_IVARS =
[ :tails, ]
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ PrometheusTailMonitorInput
constructor
A new instance of PrometheusTailMonitorInput.
- #labels(plugin_info, path) ⇒ Object
- #multi_workers_ready? ⇒ Boolean
- #start ⇒ Object
- #update_monitor_info ⇒ Object
Constructor Details
#initialize ⇒ PrometheusTailMonitorInput
Returns a new instance of PrometheusTailMonitorInput.
18 19 20 21 |
# File 'lib/fluent/plugin/in_prometheus_tail_monitor.rb', line 18 def initialize super @registry = ::Prometheus::Client.registry end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
12 13 14 |
# File 'lib/fluent/plugin/in_prometheus_tail_monitor.rb', line 12 def registry @registry end |
Instance Method Details
#configure(conf) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fluent/plugin/in_prometheus_tail_monitor.rb', line 27 def configure(conf) super hostname = Socket.gethostname = Fluent::Plugin::Prometheus.(log) placeholders = .prepare_placeholders({'hostname' => hostname, 'worker_id' => fluentd_worker_id}) @base_labels = Fluent::Plugin::Prometheus.parse_labels_elements(conf) @base_labels.each do |key, value| unless value.is_a?(String) raise Fluent::ConfigError, "record accessor syntax is not available in prometheus_tail_monitor" end @base_labels[key] = .(value, placeholders) end if defined?(Fluent::Plugin) && defined?(Fluent::Plugin::MonitorAgentInput) # from v0.14.6 @monitor_agent = Fluent::Plugin::MonitorAgentInput.new else @monitor_agent = Fluent::MonitorAgentInput.new end end |
#labels(plugin_info, path) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/fluent/plugin/in_prometheus_tail_monitor.rb', line 86 def labels(plugin_info, path) @base_labels.merge( plugin_id: plugin_info["plugin_id"], type: plugin_info["type"], path: path, ) end |
#multi_workers_ready? ⇒ Boolean
23 24 25 |
# File 'lib/fluent/plugin/in_prometheus_tail_monitor.rb', line 23 def multi_workers_ready? true end |
#start ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fluent/plugin/in_prometheus_tail_monitor.rb', line 48 def start super @metrics = { position: @registry.gauge( :fluentd_tail_file_position, 'Current position of file.'), inode: @registry.gauge( :fluentd_tail_file_inode, 'Current inode of file.'), } timer_execute(:in_prometheus_tail_monitor, @interval, &method(:update_monitor_info)) end |
#update_monitor_info ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fluent/plugin/in_prometheus_tail_monitor.rb', line 62 def update_monitor_info opts = { ivars: MONITOR_IVARS, } agent_info = @monitor_agent.plugins_info_all(opts).select {|info| info['type'] == 'tail'.freeze } agent_info.each do |info| tails = info['instance_variables'][:tails] next if tails.nil? tails.clone.each do |_, watcher| # Access to internal variable of internal class... # Very fragile implementation pe = watcher.instance_variable_get(:@pe) label = labels(info, watcher.path) @metrics[:inode].set(label, pe.read_inode) @metrics[:position].set(label, pe.read_pos) end end end |