gpt4 book ai didi

monitoring - 如何使用 telegraf 监控系统服务?

转载 作者:行者123 更新时间:2023-12-02 01:38:15 33 4
gpt4 key购买 nike

我创建了一个在我们的系统中运行的 systemd 服务,我想使用我已经安装在实例上的 telegraf 代理来监控它。代理目前正在监控基本的基础设施,我需要为新服务添加监控。

我找不到任何关于如何做到这一点的例子,这很奇怪,我希望 telegraf 有一些基本的插件。

我的服务正在运行一个不公开任何端口的 python 脚本,因此我可以进行正常的 HTTP 健康检查。

我们将不胜感激。

最佳答案

于是我发现确实有一个监控系统服务的插件,名字是systemd_timings .

这是我实现的配置:

# Gather systemd units state
[[inputs.systemd_units]]
## Set timeout for systemctl execution
timeout = "1s"

# Filter for a specific unit type, default is "service", other possible
# values are "socket", "target", "device", "mount", "automount", "swap",
# "timer", "path", "slice" and "scope ":
unittype = "service"

# Filter for a specific pattern, default is "" (i.e. all), other possible
# values are valid pattern for systemctl, e.g. "a*" for all units with
# names starting with "a"
pattern = ""
## pattern = "telegraf* influxdb*"
## pattern = "a*"

在 influxDB 中获取指标后,这是我用来提取所需数据的查询:

from(bucket: "veeva")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_field"] == "active_code")
|> filter(fn: (r) => r["_measurement"] == "systemd_units")
|> filter(fn: (r) => r["active"] == "active")
|> filter(fn: (r) => r["host"] == "10.192.21.66")
|> filter(fn: (r) => r["name"] == "myservice.service")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
[1]:

这就是它在 Grafana 中的样子:

enter image description here https://docs.influxdata.com/telegraf/v1.22/plugins/#systemd_timings

关于monitoring - 如何使用 telegraf 监控系统服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71996440/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com