Skip to content

Commit

Permalink
out_forward: Use metrics mechanism for node statistics
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Sep 14, 2021
1 parent 2844355 commit 8c79c99
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/fluent/plugin/out_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def initialize
@usock = nil
@keep_alive_watcher_interval = 5 # TODO
@suspend_flush = false
@healthy_nodes_count_metrics = nil
@registered_nodes_count_metrics = nil
end

def configure(conf)
Expand Down Expand Up @@ -265,6 +267,9 @@ def configure(conf)
end

raise Fluent::ConfigError, "ack_response_timeout must be a positive integer" if @ack_response_timeout < 1
@healthy_nodes_count_metrics = metrics_create(namespace: "fluentd", subsystem: "output", name: "healthy_nodes_count", help_text: "Number of count healthy nodes", prefer_gauge: true)
@registered_nodes_count_metrics = metrics_create(namespace: "fluentd", subsystem: "output", name: "registered_nodes_count", help_text: "Number of count registered nodes", prefer_gauge: true)

end

def multi_workers_ready?
Expand Down Expand Up @@ -418,18 +423,18 @@ def create_transfer_socket(host, port, hostname, &block)
def statistics
stats = super
services = service_discovery_services
healthy_nodes_count = 0
registered_nodes_count = services.size
@healthy_nodes_count_metrics.set(0)
@registered_nodes_count_metrics.set(services.size)
services.each do |s|
if s.available?
healthy_nodes_count += 1
@healthy_nodes_count_metrics.inc
end
end

stats = {
'output' => stats["output"].merge({
'healthy_nodes_count' => healthy_nodes_count,
'registered_nodes_count' => registered_nodes_count,
'healthy_nodes_count' => @healthy_nodes_count_metrics.get,
'registered_nodes_count' => @registered_nodes_count_metrics.get,
})
}
stats
Expand Down

0 comments on commit 8c79c99

Please sign in to comment.