Skip to content

Commit

Permalink
Export the oldest and newest timekeys in each buffer
Browse files Browse the repository at this point in the history
A metric listing all timekeys in each buffer was added to fluentd
in <fluent/fluentd#2343>. This exports the
oldest and newest values in that list as Prometheus metrics. See
discussion in
<fluent#89> for
context and rationale.
  • Loading branch information
stevenjm committed May 29, 2019
1 parent fc060aa commit 2122420
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/fluent/plugin/in_prometheus_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def configure(conf)
def start
super

@buffer_newest_timekey = @registry.gauge(
:fluentd_status_buffer_newest_timekey,
'Newest timekey in buffer.')
@buffer_oldest_timekey = @registry.gauge(
:fluentd_status_buffer_oldest_timekey,
'Oldest timekey in buffer.')
buffer_queue_length = @registry.gauge(
:fluentd_status_buffer_queue_length,
'Current buffer queue length.')
Expand All @@ -65,11 +71,18 @@ def start

def update_monitor_info
@monitor_agent.plugins_info_all.each do |info|
label = labels(info)

@monitor_info.each do |name, metric|
if info[name]
metric.set(labels(info), info[name])
metric.set(label, info[name])
end
end

if timekeys = info["buffer_timekeys"]
@buffer_newest_timekey.set(label, timekeys.max)
@buffer_oldest_timekey.set(label, timekeys.min)
end
end
end

Expand Down
11 changes: 11 additions & 0 deletions lib/fluent/plugin/in_prometheus_output_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def start
super

@metrics = {
buffer_newest_timekey: @registry.gauge(
:fluentd_output_status_buffer_newest_timekey,
'Newest timekey in buffer.'),
buffer_oldest_timekey: @registry.gauge(
:fluentd_output_status_buffer_oldest_timekey,
'Oldest timekey in buffer.'),
buffer_queue_length: @registry.gauge(
:fluentd_output_status_buffer_queue_length,
'Current buffer queue length.'),
Expand Down Expand Up @@ -123,6 +129,11 @@ def update_monitor_info
end
end

if timekeys = info["buffer_timekeys"]
@metrics[:buffer_newest_timekey].set(label, timekeys.max)
@metrics[:buffer_oldest_timekey].set(label, timekeys.min)
end

if info['instance_variables']
instance_vars_info.each do |name, metric|
if info['instance_variables'][name]
Expand Down

0 comments on commit 2122420

Please sign in to comment.