欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > 云原生之运维监控实践-使用Telegraf、Prometheus与Grafana实现对InfluxDB服务的监测

云原生之运维监控实践-使用Telegraf、Prometheus与Grafana实现对InfluxDB服务的监测

2025/4/20 13:20:11 来源:https://blog.csdn.net/u013810234/article/details/143812112  浏览:    关键词:云原生之运维监控实践-使用Telegraf、Prometheus与Grafana实现对InfluxDB服务的监测

背景

如果你要为应用程序构建规范或用户故事,那么务必先把应用程序每个组件的监控指标考虑进来,千万不要等到项目结束或部署之前再做这件事情。——《Prometheus监控实战》

去年写了一篇在Docker环境下部署若依微服务ruoyi-cloud项目的文章,当时使用的是 docker-compose 在单台机器上部署若依微服务 ruoyi-cloud 项目;在这个基础上,作为演示项目,我们计划实现对所有基础组件和微服务的监控。之前记录了搭建 PrometheusGrafana 监控系统的过程。今天这篇文章主要是记录下对 InfluxDB 的监测,用到的 exporter 是: TelegrafTelegraf 是一个开源的、插件驱动的服务器代理,用于收集、处理、和发送各种性能数据。它是 InfluxData 的一部分,常用于与 InfluxDB 结合使用,但也支持输出到其他存储系统,如 PrometheusGraphiteOpenTSDBElasticSearch 等。。

虚机资源

共用到了2台虚机,1台作为应用服务节点,1台运维监控节点。

主机名IP说明
svc192.168.44.168服务节点
ops192.168.44.169监控节点

基本选用当前最新版本,即将安装的 PrometheusGrafana 及组件版本信息如下:

  • Prometheus版本:v2.54.1
  • Grafana版本:11.2.0
  • Telegraf版本:1.19.3

系统环境

[root@ops ~]# uname -a
Linux ops 5.10.0-182.0.0.95.oe2203sp3.x86_64 #1 SMP Sat Dec 30 13:10:36 CST 2023 x86_64 x86_64 x86_64 GNU/Linux
[root@ops ~]# cat /proc/version
Linux version 5.10.0-182.0.0.95.oe2203sp3.x86_64 (root@dc-64g.compass-ci) (gcc_old (GCC) 10.3.1, GNU ld (GNU Binutils) 2.37) #1 SMP Sat Dec 30 13:10:36 CST 2023

ops节点:docker-compose安装Prometheus与Grafana

参考云原生之运维监控实践-OpenEuler22.03SP3上安装Prometheus与Grafana实现主机状态监测

svc节点:docker-compose安装Telegraf

有了 PrometheusGrafana 的基础环境,我们来实现对 InfluxDB 状态的监控:通过 Telegraf 快速采集 InfluxDB 运行数据并以 Prometheus 格式提供,供 Prometheus 进行采集和分析。

Telegraf 是一个高效且灵活的指标收集代理,它支持从多种来源收集数据并将其转发到多个输出目标。无论是服务器监控、应用性能监控,还是云服务、容器和网络设备的监控, Telegraf 都能够满足需求,并且具有极低的性能开销。通过其插件架构, Telegraf 提供了很高的可扩展性和灵活性,非常适合用于现代的监控和 Observability 系统中。

安装Telegraf

在需要监测的主机上,编辑 docker-compose.yml 文件,增加安装 Telegraf 配置。

  • [root@svc monitoring]# vi docker-compose.yml
version: '3'
services:ops-telegraf:image: telegraf:1.19.3container_name: ops-telegrafrestart: unless-stoppedports:- "9273:9273"volumes:- "./telegraf/conf/telegraf.conf:/etc/telegraf/telegraf.conf"
  • telegraf.conf
    通过 http://192.168.44.168:8086/debug/vars 获取 InfluxDB 的基础信息,并配置了用户认证信息。此外,还添加了关于CPU、内存、磁盘、IO等系统参数抓取配置。
[[outputs.prometheus_client]]listen = ":9273"[[inputs.influxdb]]urls = ["http://192.168.44.168:8086/debug/vars"]username = "admin"password = "you-guess"[[inputs.cpu]]## Whether to report per-cpu stats or notpercpu = true## Whether to report total system cpu stats or nottotalcpu = true## If true, collect raw CPU time metrics.collect_cpu_time = false# Read metrics about disk usage by mount point
[[inputs.disk]]## By default, telegraf gather stats for all mountpoints.## Setting mountpoints will restrict the stats to the specified mountpoints.# mount_points = ["/"]## Ignore some mountpoints by filesystem type. For example (dev)tmpfs (usually## present on /run, /var/run, /dev/shm or /dev).ignore_fs = ["tmpfs", "devtmpfs"]# Read metrics about disk IO by device
[[inputs.diskio]]## By default, telegraf will gather stats for all devices including## disk partitions.## Setting devices will restrict the stats to the specified devices.# devices = ["sda", "sdb"]## Uncomment the following line if you need disk serial numbers.# skip_serial_number = false[[inputs.mem]][[inputs.swap]][[inputs.processes]][[inputs.kernel]][[inputs.system]]

通过命令: docker-compose up -d 完成镜像拉取、并启动 ops-telegraf 服务。

修改Prometheus配置

Prometheus 配置中增加对svc主机上 InfluxDB 运行状态的抓取配置。

  • [root@ops monitoring]# vi ./prometheus/conf/prometheus.yml
scrape_configs:- job_name: 'ops-telegraf'scrape_interval: 15sstatic_configs:- targets:- 192.168.44.168:9273 

重启 Prometheus 容器。

[root@ops monitoring]# docker restart ops-prometheus

验证telegraf安装结果

  • 浏览器验证metrics端点

浏览器访问http://192.168.44.168:9273/metrics

  • Prometheus控制台验证influx相关的指标

2024-11-17-1-InfluxDBIndex.jpg

配置Grafana对主机状态的可视化

浏览器访问http://192.168.44.169:3000。

  • 配置数据源
  1. 点击左侧菜单中的"Add new connection"。
  2. 选择或搜索"Data Sources"。
  3. 点击"Add data source"并选择"Prometheus"。
  4. 在"HTTP"部分输入Prometheus地址,eg:http://192.168.44.169:9090
  5. 点击"Save & Test"确认连接成功。
  • 查看现成的仪表板

https://grafana.com/grafana/dashboards/这个页面是 Grafana 的官方仪表板目录,用户可以在这里找到和共享各种现成的 Grafana 仪表板。这些仪表板覆盖了多种监控需求,包括系统性能、应用监控、网络流量等。用户可以根据自己的需求搜索和导入适合的仪表板,提高监控效率和可视化效果。这里我们搜索 Influx ,结果中有个 InfluxDB ,点击进去可以查看详细的UI效果,复制仪表板的id,此处是11334。

  • 导入现成的仪表板
  1. 在右侧菜单中点击"New"按钮,然后选择"Import"。
  2. 在输入框中,可以直接输入现成仪表板的ID,或者上传JSON文件。常用的主机监控仪表板ID是11334(InfluxDB)。
  3. 点击"Load",随后选择已配置好的数据源。
  4. 点击"Import"完成导入。

2024-11-17-2-InfluxDBImport.jpg

InfluxDB监控效果

2024-11-17-3-InfluxDBDashboard.jpg

小总结

If you can’t measure it, you can’t improve it!

没有度量就没有改进,实际上,监控系统有以下两个客户:技术,业务。上述内容即是对技术组件的监控,方便技术方面的改进与优化。
本文记录了在 Docker 环境下通过 PrometheusGrafana 实现对 InfluxDB 服务的监控。具体步骤包括在服务节点上使用 docker-compose 安装 telegraf ,配置 Prometheus 抓取 InfluxDB 的监控数据,并在 Grafana 中配置数据源和导入现成的监控仪表板,以实现对时序数据库服务的性能监控和可视化。

Reference

  • 使用docker-compose部署时序数据库InfluxDB1.8.4
  • https://grafana.com/grafana/dashboards/

If you have any questions or any bugs are found, please feel free to contact me.

Your comments and suggestions are welcome!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词