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.

Signed-off-by: Steven McDonald <steven.mcdonald@usabilla.com>
  • Loading branch information
stevenjm committed Aug 7, 2019
1 parent fc060aa commit 02bacd6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
16 changes: 15 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,19 @@ 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

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

Expand Down
12 changes: 12 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,12 @@ def update_monitor_info
end
end

timekeys = info["buffer_timekeys"]
if timekeys && !timekeys.empty?
@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 02bacd6

Please sign in to comment.