From 8884b9d854627c8021ab15c49906fbf3021fb465 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Mon, 13 Sep 2021 16:56:49 +0900 Subject: [PATCH] out_forward: Use metrics mechanism for node statistics Signed-off-by: Hiroshi Hatake --- lib/fluent/plugin/out_forward.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/fluent/plugin/out_forward.rb b/lib/fluent/plugin/out_forward.rb index 9f09e052ec..a6209b095c 100644 --- a/lib/fluent/plugin/out_forward.rb +++ b/lib/fluent/plugin/out_forward.rb @@ -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) @@ -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? @@ -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