Fluentd部署:通过Prometheus监控Fluentd

本文简单介绍一下如何通过Prometheus监控Fluentd。
Prometheus也是CNCF成员项目之一,所以Fluentd官方推荐使用Prometheus作为监控工具。
  1. 安装fluent-plugin-prometheus
    $ sudo td-agent-gem install fluent-plugin-prometheus --version='~>1.6.1'
  2. Fluentd示例配置
    为了向Prometheus暴露Fluentd的统计指标,我们需要对Fluentd做一些配置,主要包含3步:
    1. 使用Prometheus过滤插件对输入消息进行计数
      首先,按照如下配置添加<filter>配置项,该过滤器会按照tag对输入消息计数。
      # source<source> @type forward bind 0.0.0.0 port 24224</source>
      # count number of incoming records per tag<filter company.*> @type prometheus <metric> name fluentd_input_status_num_records_total type counter desc The total number of incoming records <labels> tag ${tag} hostname ${hostname} </labels> </metric></filter>
    2. 使用Prometheus输出插件对输出消息进行计数
      接着,使用copy插件处理输出数据,其中使用Prometheus对输出消息按照tag进行计数。
      # count number of outgoing records per tag<match company.*> @type copy <store> @type forward <server> name myserver1 hostname 192.168.1.3 port 24224 weight 60 </server> </store> <store> @type prometheus <metric> name fluentd_output_status_num_records_total type counter desc The total number of outgoing records <labels> tag ${tag} hostname ${hostname} </labels> </metric> </store></match>
    3. 使用Prometheus输入插件通过HTTP暴露统计指标
      最后,增加如下输入配置,使得Prometheus可以通过HTTP访问Fluentd内部统计信息。
      # expose metrics in prometheus format<source> @type prometheus bind 0.0.0.0 port 24231 metrics_path /metrics</source><source> @type prometheus_output_monitor interval 10 <labels> hostname ${hostname} </labels></source>
    4. 配置检查

      完成以上3步配置之后,重启fluentd。

      # For stand-alone Fluentd installations$ fluentd -c fluentd.conf# For td-agent users$ sudo systemctl restart td-agent

      向fluentd发送测试数据

      $ echo '{"message":"hello"}' | bundle exec fluent-cat company.test1$ echo '{"message":"hello"}' | bundle exec fluent-cat company.test1$ echo '{"message":"hello"}' | bundle exec fluent-cat company.test1$ echo '{"message":"hello"}' | bundle exec fluent-cat company.test2

      访问http://localhost:24231/metrics,可以看到Prometheus格式的Fluentd相关统计指标。

      curl http://localhost:24231/metrics# TYPE fluentd_input_status_num_records_total counter# HELP fluentd_input_status_num_records_total The total number of incoming recordsfluentd_input_status_num_records_total{tag="company.test",host="KZK.local"} 3.0fluentd_input_status_num_records_total{tag="company.test2",host="KZK.local"} 1.0# TYPE fluentd_output_status_num_records_total counter# HELP fluentd_output_status_num_records_total The total number of outgoing recordsfluentd_output_status_num_records_total{tag="company.test",host="KZK.local"} 3.0fluentd_output_status_num_records_total{tag="company.test2",host="KZK.local"} 1.0# TYPE fluentd_output_status_buffer_queue_length gauge# HELP fluentd_output_status_buffer_queue_length Current buffer queue length.fluentd_output_status_buffer_queue_length{hostname="KZK.local",plugin_id="object:3fcbccc6d388",type="forward"} 1.0....
  3. Prometheus示例配置
    现在需要对Prometheus进行配置,准备以下配置文件prometheus.yml
    global: scrape_interval: 10s # Set the scrape interval to every 10 seconds. Default is every 1 minute.
    # A scrape configuration containing exactly one endpoint to scrape:# Here it's Prometheus itself.scrape_configs: - job_name: 'fluentd' static_configs: - targets: ['localhost:24231']
    启动prometheus进程
    $ ./prometheus --config.file="prometheus.yml"

    打开浏览器,访问http://localhost:9090/

  4. 在Prometheus中查看Fluentd监控数据
    1. Fluentd节点列表
      打开http://localhost:9090/targets,就会看到Fluentd节点及其运行状态
    2. Fluentd运作指标列表
      打开http://localhost:9090/graph,就会看到Fluentd运行指标

      可以看到如下指标:

      fluentd_input_status_num_records_totalfluentd_output_status_buffer_queue_lengthfluentd_output_status_buffer_total_bytesfluentd_output_status_emit_countfluentd_output_status_num_errorsfluentd_output_status_num_records_totalfluentd_output_status_retry_countfluentd_output_status_retry_wait
      选择fluentd_input_status_num_records_total,就会看到输入的消息计数。

这里,我们只对Prometheus的用法做简单介绍,感兴趣的话可以去官网做进一步了解。

(0)

相关推荐

  • Promtail Pipeline 日志处理配置

    Promtail 是 Loki 官方支持的日志采集端,在需要采集日志的节点上运行采集代理,再统一发送到 Loki 进行处理.除了使用 Promtail,社区还有很多采集日志的组件,比如 fluentd ...

  • gin中间件推荐

    中间件推荐 1.1.1. 列表 谷歌翻译欢迎查看原文 https://github.com/gin-gonic/contrib/blob/master/README.md RestGate - RES ...

  • SpringBoot进阶教程(七十一)详解Prometheus+Grafana

    随着容器技术的迅速发展,Kubernetes已然成为大家追捧的容器集群管理系统.Prometheus作为生态圈Cloud Native Computing Foundation(简称:CNCF)中的重 ...

  • Etcd Confd实现配置文件变化自动更新prometheus服务

    一.部署步骤 1.confd部署 # wget https://github.com/kelseyhightower/confd/releases/download/v0.16.0/confd-0.1 ...

  • ASP.NET Core 集成Prometheus+grafana

    相关主页  Prometheus https://prometheus.io/ grafana https://grafana.com/ 安装Prometheus         Linux 可以参考 ...

  • abaqus输出场变量小结

    有限元软件在计算时可以在软件预定义的场变量中选择输出(abaqus中没有的场变量可以自定义),可以按照需求来选择,避免都输出造成输出文件太大,影响计算效率. abaqus中场变量的输出CAE界面如图1 ...

  • Prometheus+Grafana PG监控部署以及自定义监控指标

    Prometheus+Grafana PG监控部署以及自定义监控指标

  • 一招搞定 Spring Boot 可视化监控!

    一招搞定 Spring Boot 可视化监控!

  • Fluentd部署:如何监控Fluentd

    今天的文章主要介绍一下如何监控Fluentd.监控的目的是确保日志采集能稳定高效运行. Fluentd内部运行指标 Fluentd内部保存着一些运行指标,这些指标可通过REST api直接获取,也支持 ...

  • Fluentd部署:错误排查

    本文介绍一下排查Fluentd运行时错误的几种方法. 查看日志 如果感觉Fluentd运行异常,请先查看日志.td-agent安装后,默认日志存放在/var/log/td-agent/td-agent ...

  • Fluentd部署:高可用配置

    对于高访问量的web站点或者服务,我们可以采用Fluentd的高可用配置模式. 消息分发语义 Fluentd设计初衷主要是用作事件日志分发系统的.这类系统支持几种不同的分发模式: 至多一次.消息被立即 ...

  • Fluentd部署:性能优化

    本文提供一些对于单Fluentd进程进行性能优化的建议.如果你的日志请求达到了5000条/秒,这里描述的技术点可用于调优. 检查操作系统配置 在安装Fluentd之前,进行操作系统参数优化.可参考这里 ...

  • Fluentd部署:多Workers进程模式

    本文介绍如何使用Fluentd的多worker模式处理高访问量的日志事件.此模式会运行多个worker进程以最大利用多核CPU. 原理 默认情况下,一个Fluentd实例会运行一个监控进程和一个工作进 ...

  • Fluentd部署:系统配置

    首先,本文"系统配置"指的是Fluentd的全局配置项,诸如开启RPC.使用多worker模式等.可在配置文件中通过<system>进行配置,或通过命令行进行配置. & ...

  • Fluentd部署:日志

    Fluentd是用来处理其他系统产生的日志的,它本身也会产生一些运行时日志.我们一起来了解一下Fluentd本身的日志机制. Fluentd包含两个日志层:全局日志和插件级日志.每个层次的日志都可以进 ...

  • Spring Boot 使用 Micrometer 集成 Prometheus 监控 Java 应用性能

    文章目录 1.Micrometer 介绍 2.环境.软件准备 3.Spring Boot 工程集成 Micrometer 4.配置 Prometheus 监控应用指标 5.配置 Grafana Das ...