打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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的用法做简单介绍,感兴趣的话可以去官网做进一步了解。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
使用 Prometheus 监控 eKuiper 规则运行状态
使用Prometheus针对自己的服务器采集自定义的参数
你一定需要六款大数据采集平台的架构分析
Promtail Pipeline 日志处理配置
Py之tensorflow-federated:tensorflow-federated的简介、安装、使用方法之详细攻略
gin中间件推荐
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服