# Fluentd & Prometheus ## Installation Install prometheus plugin using gem: ```bash gem install 'fluent-plugin-prometheus' ``` ## Prometheus plugins 1. **prometheus input plugin**: This plugin provides a HTTP endpoint that exposes metrics to Prometheus server on port 24231. 2. **prometheus_monitor input plugin**: This plugin collects internal metrics in Fluentd. This plugin is used to monitor Fluentd itself. 3. **prometheus_output_monitor input plugin**: This plugin collects internal metrics for **output plugin** in Fluentd. ## Configuration Configure a prometheus metrics so that Prometheus can scrape metrics. ```xml <source> @type prometheus </source> ``` Next, create a message that will be transformed to prometheus metrics. In the below example, we will create a message that shows the current CPU usage. ```xml <source> @type exec tag mcnlab command grep 'cpu ' /proc/stat | awk '{print usage=($2+$4)*100/($2+$4+$5)}' <parse> keys usage </parse> run_interval 1s </source> ``` Then, create a Prometheus metrics from the message: ```xml <filter mcnlab> @type prometheus <metric> name mcnlab_cpu_usage type gauge desc The total number of CPU in message. key usage </metric> </filter> ``` Finally, copy the message to stdout ```xml <match mcnlab> @type copy <store> @type stdout </store> </match> ``` ## Sample Configuration file ```xml= <source> @type prometheus </source> <source> @type exec tag mcnlab command grep 'cpu ' /proc/stat | awk '{print usage=($2+$4)*100/($2+$4+$5)}' <parse> keys usage </parse> run_interval 1s </source> <filter mcnlab> @type typecast types usage:float </filter> <filter mcnlab> @type prometheus <metric> name mcnlab_cpu_usage type gauge desc The total number of cpu usage in percentage key usage </metric> </filter> <match mcnlab> @type copy <store> @type stdout </store> </match> ``` ```