一、配置文件

进入到如下的配置文件

[[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 的数据

  1. 点击设置选择“data sources"

Telegraf 采集 CPU 数据

 

  1. 配置数据源

Telegraf 采集 CPU 数据

 

Telegraf 采集 CPU 数据

 

Telegraf 采集 CPU 数据

 

  1. 创建面板

Telegraf 采集 CPU 数据

 

点击 new dashboard 按钮

Telegraf 采集 CPU 数据

 

点击 Graph 图标

Telegraf 采集 CPU 数据

 

点击“edit”按钮

Telegraf 采集 CPU 数据

 

选择数据源

Telegraf 采集 CPU 数据

 

添加需要关注的指标值:

Telegraf 采集 CPU 数据

 

百分比占用显示:

Telegraf 采集 CPU 数据

 

五、选择保存默认项

[[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;

Telegraf 采集 CPU 数据

选择刷新频率和线上的时间段

本文由柠檬班库里老师原创,转载需注明出处!

想了解更多咨询的同学扫描下方二维码,可以加Q群领取学习资料:753665853  备注:CSDN  

Telegraf 采集 CPU 数据

 

相关文章:

  • 2021-11-29
  • 2021-08-10
  • 2021-12-05
  • 2021-11-29
  • 2021-12-06
  • 2021-06-23
  • 2021-11-26
  • 2021-12-28
猜你喜欢
  • 2021-06-11
  • 2022-12-23
  • 2021-07-27
  • 2021-08-29
  • 2021-12-24
  • 2022-01-02
相关资源
相似解决方案