一、配置文件
进入到如下的配置文件
[[email protected] ~]# VIM /etc/telegraf/telegraf.conf
[global_tags]
[agent]
# 收集数据的间隔
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
# 写入 inflxdb 的时间间隔
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
debug = false
quiet = false
# 日志路径
logfile = "/data/log/telegraf.log"
hostname = ""
omit_hostname = false
[[outputs.influxdb]]
urls = ["http://192.168.227.56:8086"]
database = "telegraf"
username = "admin"
password = "123456"
[[inputs.cpu]]
# 是否采集每个 CPU 的数据
percpu = false
# 是否采集总 CPU 的数据
totalcpu = true
collect_cpu_time = false
report_active = false
二、启动 Telegraf
[[email protected] data]# systemctl start telegraf.service
[[email protected] data]# service telegraf status
开机启动
[[email protected] data]# systemctl enable telegraf.service
三、在 inflxdb 验证数据(inflxdb 数据库所在的机器)
[[email protected] ~]# influx -username 'admin' -password '123456' -database telegraf
select * from CPU limit 3
name: CPU
time CPU host usage_guest usage_guest_nice usage_idle usage_iowait usage_irq usage_nice usage_softirq usage_steal usage_system usage_user
1598452090000000000 cpu-total localhost.localdomain 0 0 97.93294681121132 0.17645576002015695 0.15124779430301213 0 0.07562389715150607 0 0.8822788001008564 0.7814469372322055
1598452090000000000 cpu0 localhost.localdomain 0 0 98.58870967742497 0 0.20161290322583764 0 0 0 0.5040322580645762 0.7056451612904496
1598452090000000000 cpu1 localhost.localdomain 0 0 98.5901309164208 0 0.10070493454176956 0 0.10070493454178744 0 0.5035246727089193 0.70493454179253
四、在 grafana 展示监控 CPU 的数据
- 点击设置选择“data sources"
424 x 661
- 配置数据源
728 x 514 1154 x 814
728 x 230 1107 x 350
703 x 335
- 创建面板
694 x 271
点击 new dashboard 按钮
728 x 279 1411 x 541
点击 Graph 图标
728 x 493 732 x 496
点击“edit”按钮
728 x 375 780 x 402
选择数据源
728 x 411 886 x 500
添加需要关注的指标值:
728 x 350 1068 x 514
百分比占用显示:
728 x 586 752 x 605
五、选择保存默认项
[[email protected] telegraf]# VIM /etc/telegraf/telegraf.conf
对 CPU 只采集的监控项
fieldpass = ["usage_user","usage_idle", "usage_iowait", "usage_system"]
重启 telegraf
[[email protected] telegraf]# systemctl restart telegraf
六、在 inflxdb 上面重新采集数据
[[email protected] ~]# influx -username 'admin' -password '123456' -database telegraf
use telegraf;
drop measurement cpu;
728 x 338 1842 x 855
选择刷新频率和线上的时间段
作者:mike.liu
链接:http://testingpai.com/article/1601096205235
来源:测试论坛