Monitoring by Prometheus

This article describes how to monitor Fluentd via Prometheus.

Since both Prometheus and Fluentd are under CNCF (Cloud Native Computing Foundation), Fluentd project is recommending to use Prometheus by default to monitor Fluentd.

Installation

Install fluent-plugin-prometheus gem:

$ fluent-gem install fluent-plugin-prometheus

For td-agent, use td-agent-gem for installation:

$ sudo td-agent-gem install fluent-plugin-prometheus

This GitHub repository contains a fully working configuration for this article.

Example Fluentd Configuration

To expose Fluentd metrics to Prometheus, we need to configure three (3) parts:

  • Step 1: Counting Incoming Records by Prometheus Filter Plugin

  • Step 2: Counting Outgoing Records by Prometheus Output Plugin

  • Step 3: Expose Metrics by Prometheus Input Plugin via HTTP

Step 1: Counting Incoming Records by Prometheus Filter Plugin

Configure the <filter> section to count the incoming records per tag:

With this configuration, the prometheus filter plugin starts adding the internal counter as the record comes in.

Step 2: Counting Outgoing Records by Prometheus Output Plugin

Configure the copy plugin with prometheus output plugin to count the outgoing records per tag:

With this configuration, the prometheus output plugin starts adding the internal counter as the record goes out.

Step 3: Expose Metrics by Prometheus Input Plugin via HTTP

Configure prometheus input plugin to expose internal counter information via HTTP:

Check the Configuration

After you have done these three (3) changes, restart fluentd:

Let's send some records:

Access http://localhost:24231/metrics to receive the metrics in Prometheus format:

Example Prometheus Configuration

Prepare the configuration file (prometheus.yml):

Launch prometheus:

Now, open this URL http://localhost:9090/ in your browser.

How to use Prometheus to monitor Fluentd?

List of Fluentd Nodes

Go to http://localhost:9090/targets to see the list of Fluentd nodes and their status.

Prometheus Targets

List of Fluentd Metrics

Visit http://localhost:9090/graph to explore Fluentd's internal metrics. You'll see eight (8) metrics in the metric list:

Prometheus Metrics
  • fluentd_input_status_num_records_total

  • fluentd_output_status_buffer_queue_length

  • fluentd_output_status_buffer_total_bytes

  • fluentd_output_status_emit_count

  • fluentd_output_status_num_errors

  • fluentd_output_status_num_records_total

  • fluentd_output_status_retry_count

  • fluentd_output_status_retry_wait

Pick fluentd_input_status_num_records_total and you'll see the total incoming records per tag.

Prometheus Graph

Example Prometheus Queries

Since fluentd_input_status_num_records_total and fluentd_output_status_num_records_total are monotonically increasing numbers, it requires a little bit of calculation by PromQL (Prometheus Query Language) to make them meaningful.

Here are the example PromQLs for common metrics:

Metrics to Monitor

In addition to the traffic metrics introduced above, it is important to monitor the queue length and error count.

If these values are increasing, it means Fluentd cannot flush the buffer to the destination. Thus you will lose the data once the buffer becomes full.

Grafana for Advanced Visualization / Alerting

For more advanced visualization and alerting, we recommend Grafana as a visualization frontend for Prometheus.

Prometheus + Grafana

Further Readings

If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is an open-source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.

Last updated

Was this helpful?