Skip to content

Commit

Permalink
renaming by taking out _in_disk and _from_disk terms from New Metric …
Browse files Browse the repository at this point in the history
…specific parameters name and restoring back the interval parameter default value to 5

with changed class names for write_watcher plugin and in_prometheus_tail_monitor plugin
  • Loading branch information
pmoogi-redhat committed Mar 3, 2021
1 parent ba3f8d1 commit cdf1430
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
20 changes: 10 additions & 10 deletions fluentd/lib/fluent-plugin-prometheus/in_prometheus_tail_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
require 'fluent/plugin/prometheus'

module Fluent::Plugin
class PrometheusTailMonitorInput < Fluent::Plugin::Input
class PrometheusTailMonitorInputMetric < Fluent::Plugin::Input
Fluent::Plugin.register_input('prometheus_tail_monitor', self)
include Fluent::Plugin::PrometheusLabelParser

helpers :timer

config_param :interval, :time, default: 1
config_param :interval, :time, default: 5
attr_reader :registry

MONITOR_IVARS = [
Expand Down Expand Up @@ -51,11 +51,11 @@ def start
inode: get_gauge(
:fluentd_tail_file_inode,
'Current inode of file.'),
totalbytes_logged_in_disk: get_gauge(
:fluentd_totalbytes_logged_in_disk,
totalbytes_logged: get_gauge(
:fluentd_totalbytes_logged,
'totalbytes logged in disk.'),
totalbytes_collected_from_disk: get_gauge(
:fluentd_totalbytes_collected_from_disk,
totalbytes_collected: get_gauge(
:fluentd_totalbytes_collected,
'totalbytes read or collected from disk.'),
}
timer_execute(:in_prometheus_tail_monitor, @interval, &method(:update_monitor_info))
Expand All @@ -78,13 +78,13 @@ def update_monitor_info
# Access to internal variable of internal class...
# Very fragile implementation
pe = watcher.instance_variable_get(:@pe)
totalbytes_logged_in_disk=watcher.instance_variable_get(:@totalbytes_logged_in_disk)
totalbytes_collected_from_disk=watcher.instance_variable_get(:@totalbytes_collected_from_disk)
totalbytes_logged=watcher.instance_variable_get(:@totalbytes_logged)
totalbytes_collected=watcher.instance_variable_get(:@totalbytes_collected)
label = labels(info, watcher.path)
@metrics[:inode].set(label, pe.read_inode)
@metrics[:position].set(label, pe.read_pos)
@metrics[:totalbytes_logged_in_disk].set(label,totalbytes_logged_in_disk)
@metrics[:totalbytes_collected_from_disk].set(label,totalbytes_collected_from_disk)
@metrics[:totalbytes_logged].set(label,totalbytes_logged)
@metrics[:totalbytes_collected].set(label,totalbytes_collected)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions fluentd/lib/in_tail_metric/in_tail_metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ def on_notify
@line_buffer_timer_flusher.on_notify(self) if @line_buffer_timer_flusher
@io_handler.on_notify if @io_handler
@totalbytes_collected=@write_watcher.update_totalbytes_collected(@path)
@log.debug "TOTALBYTES LOGGED #{@totalbytes_logged} TOTALBYTESCOLLECTED #{@totalbytes_collected}"
end

def on_rotate(stat)
Expand Down
14 changes: 6 additions & 8 deletions fluentd/lib/in_tail_metric/write_watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
require 'fluent/plugin/input'

module Fluent::Plugin
class TailInput < Fluent::Plugin::Input
class WriteWatcher < Fluent::Plugin::Input

class WriteWatcher

def initialize(log)
@notify_count = 0
Expand All @@ -31,19 +30,19 @@ def initialize(log)
# :ino inode number of current file
# :size of current file
# :bytes_logged bytes_logged size of previous files for this path
Entry = Struct.new(:ino, :size,:sum_bytes_collected,:sum_bytes_logged,:prev_bytes_collected)
Entry = Struct.new(:ino, :size,:sum_bytes_collected,:sum_bytes_logged)

def on_notify(path, stat)
info = @map[path]
if !info
@log.debug "GETTING METRICS FOR #{path} new file"
info = Entry.new(nil, 0,0,0,0)
@log.debug "GETTING TOTALBYTES_LOGGED METRICS FOR #{path} new file"
info = Entry.new(nil, 0,0,0)
end
# Accumulate last size if file changed (no stat, new inode or truncated)
if !stat || info.ino != stat.ino || stat.size < info.size
#info.sum_bytes_logged += info.size
info.size = 0
elsif stat.size >= info.size
info.sum_bytes_logged += stat.size if stat
elsif stat.size >= info.size
info.sum_bytes_logged += (stat.size - info.size)
end

Expand Down Expand Up @@ -71,4 +70,3 @@ def update_totalbytes_collected(path)

end
end
end

0 comments on commit cdf1430

Please sign in to comment.