• Stars
    star
    253
  • Rank 160,776 (Top 4 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fluent plugin that collects metrics and exposes for Prometheus.

fluent-plugin-prometheus, a plugin for Fluentd

Build Status

A fluent plugin that instruments metrics from records and exposes them via web interface. Intended to be used together with a Prometheus server.

Requirements

fluent-plugin-prometheus fluentd ruby
1.x.y >= v1.9.1 >= 2.4
1.[0-7].y >= v0.14.8 >= 2.1
0.x.y >= v0.12.0 >= 1.9

Since v1.8.0, fluent-plugin-prometheus uses http_server helper to launch HTTP server. If you want to handle lots of connections, install async-http gem.

Installation

Add this line to your application's Gemfile:

gem 'fluent-plugin-prometheus'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fluent-plugin-prometheus

Usage

fluentd-plugin-prometheus includes 6 plugins.

  • prometheus input plugin
  • prometheus_monitor input plugin
  • prometheus_output_monitor input plugin
  • prometheus_tail_monitor input plugin
  • prometheus output plugin
  • prometheus filter plugin

See sample configuration, or try tutorial.

prometheus input plugin

You have to configure this plugin to expose metrics collected by other Prometheus plugins. This plugin provides a metrics HTTP endpoint to be scraped by a Prometheus server on 24231/tcp(default).

With following configuration, you can access http://localhost:24231/metrics on a server where fluentd running.

<source>
  @type prometheus
</source>

More configuration parameters:

  • bind: binding interface (default: '0.0.0.0')
  • port: listen port (default: 24231)
  • metrics_path: metrics HTTP endpoint (default: /metrics)
  • aggregated_metrics_path: metrics HTTP endpoint (default: /aggregated_metrics)

When using multiple workers, each worker binds to port + fluent_worker_id. To scrape metrics from all workers at once, you can access http://localhost:24231/aggregated_metrics.

TLS setting

Use <trasnport tls>. See transport config article for more details.

<source>
  @type prometheus
  <transport tls>
    # TLS parameters...
  </transport
</source>

prometheus_monitor input plugin

This plugin collects internal metrics in Fluentd. The metrics are similar to/part of monitor_agent.

Exposed metrics

  • fluentd_status_buffer_queue_length
  • fluentd_status_buffer_total_bytes
  • fluentd_status_retry_count
  • fluentd_status_buffer_newest_timekey from fluentd v1.4.2
  • fluentd_status_buffer_oldest_timekey from fluentd v1.4.2

Configuration

With following configuration, those metrics are collected.

<source>
  @type prometheus_monitor
</source>

More configuration parameters:

  • <labels>: additional labels for this metric (optional). See Labels
  • interval: interval to update monitor_agent information in seconds (default: 5)

prometheus_output_monitor input plugin

This plugin collects internal metrics for output plugin in Fluentd. This is similar to prometheus_monitor plugin, but specialized for output plugin. There are Many metrics prometheus_monitor does not include, such as num_errors, retry_wait and so on.

Exposed metrics

Metrics for output

  • fluentd_output_status_retry_count
  • fluentd_output_status_num_errors
  • fluentd_output_status_emit_count
  • fluentd_output_status_retry_wait
    • current retry_wait computed from last retry time and next retry time
  • fluentd_output_status_emit_records
  • fluentd_output_status_write_count
  • fluentd_output_status_rollback_count
  • fluentd_output_status_flush_time_count in milliseconds from fluentd v1.6.0
  • fluentd_output_status_slow_flush_count from fluentd v1.6.0

Metrics for buffer

  • fluentd_output_status_buffer_total_bytes
  • fluentd_output_status_buffer_stage_length from fluentd v1.6.0
  • fluentd_output_status_buffer_stage_byte_size from fluentd v1.6.0
  • fluentd_output_status_buffer_queue_length
  • fluentd_output_status_buffer_queue_byte_size from fluentd v1.6.0
  • fluentd_output_status_buffer_newest_timekey from fluentd v1.6.0
  • fluentd_output_status_buffer_oldest_timekey from fluentd v1.6.0
  • fluentd_output_status_buffer_available_space_ratio from fluentd v1.6.0

Configuration

With following configuration, those metrics are collected.

<source>
  @type prometheus_output_monitor
</source>

More configuration parameters:

  • <labels>: additional labels for this metric (optional). See Labels
  • interval: interval to update monitor_agent information in seconds (default: 5)
  • gauge_all: Specify metric type. If true, use gauge type. If false, use counter type. Since v2, this parameter will be removed and use counter type.

prometheus_tail_monitor input plugin

This plugin collects internal metrics for in_tail plugin in Fluentd. in_tail plugin holds internal state for files that the plugin is watching. The state is sometimes important to monitor plugins work correctly.

This plugin uses internal class of Fluentd, so it's easy to break.

Exposed metrics

  • fluentd_tail_file_position: Current bytes which plugin reads from the file
  • fluentd_tail_file_inode: inode of the file
  • fluentd_tail_file_closed: Number of closed files
  • fluentd_tail_file_opened: Number of opened files
  • fluentd_tail_file_rotated: Number of rotated files

Default labels:

  • plugin_id: a value set for a plugin in configuration.
  • type: plugin name. in_tail only for now.
  • path: file path

Configuration

With following configuration, those metrics are collected.

<source>
  @type prometheus_tail_monitor
</source>

More configuration parameters:

  • <labels>: additional labels for this metric (optional). See Labels
  • interval: interval to update monitor_agent information in seconds (default: 5)

prometheus output/filter plugin

Both output/filter plugins instrument metrics from records. Both plugins have no impact against values of each records, just read.

Assuming you have following configuration and receiving message,

<match message>
  @type stdout
</match>
message {
  "foo": 100,
  "bar": 200,
  "baz": 300
}

In filter plugin style,

<filter message>
  @type prometheus
  <metric>
    name message_foo_counter
    type counter
    desc The total number of foo in message.
    key foo
  </metric>
</filter>

<match message>
  @type stdout
</match>

In output plugin style:

<filter message>
  @type prometheus
  <metric>
    name message_foo_counter
    type counter
    desc The total number of foo in message.
    key foo
  </metric>
</filter>

<match message>
  @type copy
  <store>
    @type prometheus
    <metric>
      name message_foo_counter
      type counter
      desc The total number of foo in message.
      key foo
    </metric>
  </store>
  <store>
    @type stdout
  </store>
</match>

With above configuration, the plugin collects a metric named message_foo_counter from key foo of each records.

You can access nested keys in records via dot or bracket notation (https://docs.fluentd.org/plugin-helper-overview/api-plugin-helper-record_accessor#syntax), for example: $.kubernetes.namespace, $['key1'][0]['key2']. The record accessor is enable only if the value starts with $. or $[.

See Supported Metric Type and Labels for more configuration parameters.

Supported Metric Types

For details of each metric type, see Prometheus documentation. Also see metric name guide.

counter type

<metric>
  name message_foo_counter
  type counter
  desc The total number of foo in message.
  key foo
  <labels>
    tag ${tag}
    host ${hostname}
    foo bar
  </labels>
</metric>
  • name: metric name (required)
  • type: metric type (required)
  • desc: description of this metric (required)
  • key: key name of record for instrumentation (optional)
  • initialized: boolean controlling initilization of metric (optional). See Metric initialization
  • <labels>: additional labels for this metric (optional). See Labels
  • <initlabels>: labels to use for initialization of ReccordAccessors/Placeholder labels (optional). See Metric initialization

If key is empty, the metric values is treated as 1, so the counter increments by 1 on each record regardless of contents of the record.

gauge type

<metric>
  name message_foo_gauge
  type gauge
  desc The total number of foo in message.
  key foo
  <labels>
    tag ${tag}
    host ${hostname}
    foo bar
  </labels>
</metric>
  • name: metric name (required)
  • type: metric type (required)
  • desc: description of metric (required)
  • key: key name of record for instrumentation (required)
  • initialized: boolean controlling initilization of metric (optional). See Metric initialization
  • <labels>: additional labels for this metric (optional). See Labels
  • <initlabels>: labels to use for initialization of ReccordAccessors/Placeholder labels (optional). See Metric initialization

summary type

<metric>
  name message_foo
  type summary
  desc The summary of foo in message.
  key foo
  <labels>
    tag ${tag}
    host ${hostname}
    foo bar
  </labels>
</metric>
  • name: metric name (required)
  • type: metric type (required)
  • desc: description of metric (required)
  • key: key name of record for instrumentation (required)
  • initialized: boolean controlling initilization of metric (optional). See Metric initialization
  • <labels>: additional labels for this metric (optional). See Labels
  • <initlabels>: labels to use for initialization of ReccordAccessors/Placeholder labels (optional). See Metric initialization

histogram type

<metric>
  name message_foo
  type histogram
  desc The histogram of foo in message.
  key foo
  buckets 0.1, 1, 5, 10
  <labels>
    tag ${tag}
    host ${hostname}
    foo bar
  </labels>
</metric>
  • name: metric name (required)
  • type: metric type (required)
  • desc: description of metric (required)
  • key: key name of record for instrumentation (required)
  • initialized: boolean controlling initilization of metric (optional). See Metric initialization
  • buckets: buckets of record for instrumentation (optional)
  • <labels>: additional labels for this metric (optional). See Labels
  • <initlabels>: labels to use for initialization of ReccordAccessors/Placeholder labels (optional). See Metric initialization

Labels

See Prometheus Data Model first.

You can add labels with static value or dynamic value from records. In prometheus_monitor input plugin, you can't use label value from records.

labels section

<labels>
  key1 value1
  key2 value2
</labels>

All labels sections has same format. Each lines have key/value for label.

You can access nested fields in records via dot or bracket notation (https://docs.fluentd.org/plugin-helper-overview/api-plugin-helper-record_accessor#syntax), for example: $.kubernetes.namespace, $['key1'][0]['key2']. The record accessor is enable only if the value starts with $. or $[. Other values are handled as raw string as is and may be expanded by placeholder described later.

You can use placeholder for label values. The placeholders will be expanded from reserved values and records. If you specify ${hostname}, it will be expanded by value of a hostname where fluentd runs. The placeholder for records is deprecated. Use record accessor syntax instead.

Reserved placeholders are:

  • ${hostname}: hostname
  • ${worker_id}: fluent worker id
  • ${tag}: tag name
    • only available in Prometheus output/filter plugin
  • ${tag_parts[N]} refers to the Nth part of the tag.
    • only available in Prometheus output/filter plugin
  • ${tag_prefix[N]} refers to the [0..N] part of the tag.
    • only available in Prometheus output/filter plugin
  • ${tag_suffix[N]} refers to the [tagsize-1-N..] part of the tag.
    • where tagsize is the size of tag which is splitted with . (when tag is 1.2.3, then tagsize is 3)
    • only available in Prometheus output/filter plugin

Metric initialization

You can configure if a metric should be initialized to its zero value before receiving any event. To do so you just need to specify initialized true.

<metric>
  name message_bar_counter
  type counter
  desc The total number of bar in message.
  key bar
  initialized true
  <labels>
    foo bar
  </labels>
</metric>

If your labels contains ReccordAccessors or Placeholders, you must use <initlabels> to specify the values your ReccordAccessors/Placeholders will take. This feature is useful only if your Placeholders/ReccordAccessors contain deterministic values. Initialization will create as many zero value metrics as <initlabels> blocks you defined. Potential reserved placeholders ${hostname} and ${worker_id}, as well as static labels, are automatically added and should not be specified in <initlabels> configuration.

<metric>
  name message_bar_counter
  type counter
  desc The total number of bar in message.
  key bar
  initialized true
  <labels>
    key $.foo
    tag ${tag}
    foo bar
    worker_id ${worker_id}
  </labels>
  <initlabels>
    key foo1
    tag tag1
  </initlabels>
  <initlabels>
    key foo2
    tag tag2
  </initlabels>
</metric>
<labels>
  hostname ${hostname}
</labels>

top-level labels and labels inside metric

Prometheus output/filter plugin can have multiple metric section. Top-level labels section specifies labels for all metrics. Labels section inside metric section specifies labels for the metric. Both are specified, labels are merged.

<filter message>
  @type prometheus
  <metric>
    name message_foo_counter
    type counter
    desc The total number of foo in message.
    key foo
    <labels>
      key foo
      data_type ${type}
    </labels>
  </metric>
  <metric>
    name message_bar_counter
    type counter
    desc The total number of bar in message.
    key bar
    <labels>
      key bar
    </labels>
  </metric>
  <labels>
    tag ${tag}
    hostname ${hostname}
  </labels>
</filter>

In this case, message_foo_counter has tag, hostname, key and data_type labels.

Try plugin with nginx

Checkout repository and setup.

$ git clone git://github.com/fluent/fluent-plugin-prometheus
$ cd fluent-plugin-prometheus
$ bundle install --path vendor/bundle

Download pre-compiled Prometheus binary and start it. It listens on 9090.

$ wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5.2.linux-amd64.tar.gz -O - | tar zxf -
$ ./prometheus-1.5.2.linux-amd64/prometheus -config.file=./misc/prometheus.yaml -storage.local.path=./prometheus/metrics

Install Nginx for sample metrics. It listens on 80 and 9999.

$ sudo apt-get install -y nginx
$ sudo cp misc/nginx_proxy.conf /etc/nginx/sites-enabled/proxy
$ sudo chmod 777 /var/log/nginx && sudo chmod +r /var/log/nginx/*.log
$ sudo service nginx restart

Start fluentd with sample configuration. It listens on 24231.

$ bundle exec fluentd -c misc/fluentd_sample.conf -v

Generate some records by accessing nginx.

$ curl http://localhost/
$ curl http://localhost:9999/

Confirm that some metrics are exported via Fluentd.

$ curl http://localhost:24231/metrics

Then, make a graph on Prometheus UI. http://localhost:9090/

Contributing

  1. Fork it ( https://github.com/fluent/fluent-plugin-prometheus/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Copyright

AuthorMasahiro Sano
CopyrightCopyright (c) 2015- Masahiro Sano
LicenseApache License, Version 2.0

More Repositories

1

fluentd

Fluentd: Unified Logging Layer (project under CNCF)
Ruby
12,329
star
2

fluent-bit

Fast and Lightweight Logs and Metrics processor for Linux, BSD, OSX and Windows
C
5,812
star
3

fluentd-kubernetes-daemonset

Fluentd daemonset for Kubernetes and it Docker image
Ruby
1,210
star
4

fluentd-ui

Web UI for Fluentd
Ruby
596
star
5

fluent-operator

Operate Fluent Bit and Fluentd in the Kubernetes way - Previously known as FluentBit Operator
Go
580
star
6

fluent-bit-kubernetes-logging

Fluent Bit Kubernetes Daemonset
466
star
7

fluentd-docker-image

Docker image for Fluentd
Dockerfile
452
star
8

fluent-logger-python

A structured logger for Fluentd (Python)
Python
424
star
9

fluent-logger-golang

A structured logger for Fluentd (Golang)
Go
380
star
10

helm-charts

Helm Charts for Fluentd and Fluent Bit
Mustache
376
star
11

fluent-plugin-s3

Amazon S3 input and output plugin for Fluentd
Ruby
308
star
12

fluent-plugin-kafka

Kafka input and output plugin for Fluentd
Ruby
298
star
13

fluentd-forwarder

Fluentd Forwarder: Lightweight Data Collector in Golang
Go
283
star
14

fluent-logger-node

A structured logger for Fluentd (Node.js)
JavaScript
257
star
15

fluent-logger-ruby

A structured logger for Fluentd (Ruby)
Ruby
251
star
16

fluent-logger-php

A structured logger for Fluentd (PHP)
PHP
216
star
17

fluent-logger-java

A structured logger for Fluentd (Java)
Java
205
star
18

sigdump

Use signal to show stacktrace of a Ruby process without restarting it
Ruby
183
star
19

fluent-bit-go

Fluent Bit Golang package to build plugins
Go
173
star
20

fluent-plugin-mongo

MongoDB input and output plugin for Fluentd
Ruby
171
star
21

fluent-plugin-rewrite-tag-filter

Fluentd Output filter plugin to rewrite tags that matches specified attribute.
Ruby
168
star
22

fluent-bit-docs

Fluent Bit - Official Documentation
Shell
119
star
23

fluent-plugin-grok-parser

Fluentd's Grok parser
Ruby
103
star
24

fluent-plugin-sql

SQL input/output plugin for Fluentd
Ruby
102
star
25

nginx-fluentd-module

Nginx module for Fluentd data collector
C
85
star
26

fluent-bit-docker-image

Docker image for Fluent Bit
Shell
67
star
27

fluent-plugin-webhdfs

Hadoop WebHDFS output plugin for Fluentd
Ruby
59
star
28

fluent-plugin-opensearch

OpenSearch Plugin for Fluentd
Ruby
49
star
29

fluentd-docs

This repository is deprecated. Go to fluentd-docs-gitbook repository.
Ruby
49
star
30

fluentd-benchmark

Benchmark collection of fluentd use cases
Shell
47
star
31

fluent-logger-scala

A structured logger implementation in Scala.
Shell
45
star
32

NLog.Targets.Fluentd

C#
44
star
33

fluent-logger-perl

A structured logger for Fluentd (Perl)
Perl
43
star
34

fluent-plugin-multiprocess

Multiprocess agent plugin for Fluentd
Ruby
42
star
35

fluentd-docs-gitbook

Fluentd documentation project in Gitbook format
JavaScript
41
star
36

fluent-plugin-splunk

Fluentd Plugin for Splunk
Ruby
38
star
37

fluent-plugin-windows-eventlog

Fluentd plugin to collect windows event logs
Ruby
33
star
38

fluent-plugin-parser-cri

CRI log parser for Fluentd
Ruby
32
star
39

fluent-bit-perf

Fluent Bit Performance Tools
C
31
star
40

fluent-plugin-flume

Flume input and output plugin for Fluentd
Ruby
23
star
41

kafka-connect-fluentd

Kafka Connect for Fluentd
Java
23
star
42

chunkio

Simple library to manage chunks of data in memory and file system
C
21
star
43

fluent-package-builder

td-agent (Fluentd) Building and Packaging System
Shell
21
star
44

fluent-plugin-scribe

Scribe input/output plugin for Fluentd data collector
Ruby
20
star
45

fluent-plugins

18
star
46

cmetrics

A standalone library to create and manipulate metrics in C
C
15
star
47

website

http://fluentd.org/
CSS
14
star
48

fluent-plugin-sanitizer

Ruby
14
star
49

fluent-bit-plugin

Fluent Bit Dynamic Plugin Development
C
13
star
50

fluent-bit-packaging

Fluent Bit Linux Packaging environment using Docker
Dockerfile
12
star
51

fluent-logger-forward-node

A fluent forward protocol implementation for Node.js
TypeScript
11
star
52

fluentd-website

For fluentd.org
CSS
10
star
53

fluent-logger-erlang

A structured logger for Fluentd (Erlang)
Erlang
10
star
54

fluent-bit-ci

CI/CD for Fluent-bit
Shell
8
star
55

fluent-plugin-msgpack-rpc

MessagePack-RPC input plugin for Fluentd data collector
Ruby
8
star
56

fluent-logger-ocaml

A structured logger for Fluentd (OCaml)
OCaml
7
star
57

fluent-plugin-hoop

Hoop (HDFS over HTTP) Plugin for Fluentd data collector
Ruby
6
star
58

data-collection

Data Collection with Fluentd
6
star
59

fluent-logger-d

A structured logger for Fluentd (D)
JavaScript
6
star
60

diagtool

Bringing productivity of trouble shooting to the next level by automating collection of Fluentd configurations, settings and OS parameters as well as masking sensitive information in logs and configurations.
Ruby
5
star
61

fluent-bit-tutorials

Fluent Bit Tutorials, custom articles to get started
5
star
62

m3-workshop-fluentcon

Shell
4
star
63

fluentbit-website-v3

CSS
4
star
64

fluent.github.com

website
JavaScript
4
star
65

fluentd-aggregator-docker-image

A Fluentd container image to be used for log aggregation and based on the official Fluentd Docker image.
Dockerfile
4
star
66

fluent-bit-observability-demo

JavaScript
3
star
67

fluent-bit-docs-stream-processing

Fluent Bit Stream Processing Guide
3
star
68

onigmo

Onigmo library with security and stable patches on top by Fluent maintainers
C
3
star
69

fluent-bit-website

Fluent Bit Website (work in process)
HTML
3
star
70

fluent-plugin-sd-dns

DNS based service discovery plugin for Fluentd
Ruby
2
star
71

fluent-bit-test

Testing infrastructure for Fluent Bit
2
star
72

fluent-bit-labs

Fluent Bit Dev Labs
2
star
73

fluent-bit-website-old

Fluent Bit website
CSS
2
star
74

fluentbit-website-v2

Fluent Bit Website v2
CSS
2
star
75

fluent-plugin-buffer-chunkio

Ruby
2
star
76

fluent-bit-chatops-demo

Demo of using Fluent Bit for ChatOps - created for Cloud Native Rejekts EU 2024 talk
Java
2
star
77

fluent-bit-infra

Automation related to fluent-bit infrastructure
HCL
2
star
78

fluent-plugin-parser-winevt_xml

Fluentd Parser plugin to parse XML rendered windows event log.
Ruby
1
star
79

cfl

Tiny library for data structures management, call it c:\ floppy
C
1
star
80

fluentd-docs-kubernetes

Fluentd DaemonSet Documentation for Kubernetes
1
star
81

fluent-bit-sandbox

A repository to covering the setup and configuration of the Fluent Bit Sandbox.
Shell
1
star
82

fluent-plugin-prometheus_pushgateway

Ruby
1
star
83

fluentd-website-hugo

SCSS
1
star
84

ctraces

Library to create and manipulate traces in C
C
1
star