prometheus+telegraf+grafana监控学习(二)

2020-12-10 10:53:34 浏览数 (3)

一、telegraf搭建

通过上一篇prometheus telegraf grafana监控学习(一)已经启动了prometheus,那么现在我们需要在被监控机器上部署telegraf。

解压telegraf

被监控机器上创建/opt/monitor/文件夹并将telegraf安装包解压

代码语言:javascript复制
tar xvf telegraf-1.11.1_linux_amd64.tar.gz

修改配置文件

代码语言:javascript复制
[root@bigdata3 telegraf]# pwd
/opt/monitor/telegraf/etc/telegraf
[root@bigdata3 telegraf]# cp telegraf.conf telegraf.conf.bak

可清空原配置,拷贝下方配置

代码语言:javascript复制
vi /opt/telegraf/etc/telegraf/telegraf.conf
[global_tags]
  dc = "host-test"   #切记此dc
[agent]
  interval = "60s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  debug = false
  quiet = false
  logfile = "/opt/monitor/telegraf/logs/telegraf.log"    #日志目录
  hostname = ""
  omit_hostname = false
[[outputs.prometheus_client]]
  listen = ":9275"
[[aggregators.histogram]]
   period = "60s"
   drop_original = false
[[aggregators.histogram.config]]
  buckets = [0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0]
  measurement_name = "cpu"
  fields = ["usage_user","usage_idle"]
[[aggregators.histogram.config]]
  buckets = [0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0]
  measurement_name = "mem"
  fields = ["used_percent","available_percent"]
[[aggregators.histogram.config]]
  buckets = [0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 120.0, 150.0, 200.0, 300.0]
  measurement_name = "system"
  fields = ["load5"]
[[aggregators.histogram.config]]
  buckets = [0.0, 100.0, 200.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0, 1200.0, 1500.0, 2000.0, 3000.0]
  measurement_name = "processes"
  fields = ["total_threads","total"]
[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
  report_active = false
[[inputs.disk]]
  ignore_fs = ["/","/home/*","/home","/mnt/data*","/data*","/mnt/sata*","/mnt/sd*"]
[[inputs.diskio]]
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.net]]
[[inputs.netstat]]
[[inputs.processes]]
[[inputs.swap]]
[[inputs.system]]

创建启动脚本

代码语言:javascript复制
vi /usr/lib/systemd/system/telegraf.service
[Unit]
Description=The plugin-driven server agent for reporting metrics into InfluxDB
Documentation=https://github.com/influxdata/telegraf
After=network.target
[Service]
EnvironmentFile=-/opt/monitor/telegraf/etc/telegraf
User=telegraf
ExecStart=/opt/monitor/telegraf/usr/bin/telegraf -config=/opt/monitor/telegraf/etc/telegraf/telegraf.conf $TELEGRAF_OPTS
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartForceExitStatus=SIGPIPE
KillMode=control-group
[Install]
WantedBy=multi-user.target

添加进程账号

代码语言:javascript复制
useradd telegraf
echo "telegraf" | passwd --stdin telegraf

更改目录权限

代码语言:javascript复制
chown -R telegraf:telegraf /opt/telegraf

启动telegraf

代码语言:javascript复制
systemctl start telegraf

接下来去prometheus页面进行验证

0 人点赞