[关闭]
@adonia 2016-07-22T08:46:21.000000Z 字数 3972 阅读 714

influxdb+collectd+grafana构建监控系统

运维


说明:测试环境为centos 6.8

influxdb

安装

或者使用docker镜像,执行docker pull influxdb。(influxdb对接collectd时,需要开启udp端口,待验证)

解压之后,influxdb的安装目录内容如下:

  1. ├── etc
  2.    ├── influxdb
  3.       ├── influxdb.conf
  4.       └── influxdb.conf.template
  5.    └── logrotate.d
  6.    └── influxdb
  7. ├── usr
  8.    ├── bin
  9.       ├── influx
  10.       ├── influxd
  11.       ├── influx_inspect
  12.       ├── influx_stress
  13.       └── influx_tsm
  14.    └── lib
  15.    └── influxdb
  16.    └── scripts
  17.    ├── influxdb.service
  18.    └── init.sh
  19. └── var
  20. ├── lib
  21.    └── influxdb
  22. └── log
  23. └── influxdb

其中,usr/bin/influxdinfluxdb的引导程序;etc/influxdb/influxdb.conf为配置文件。

配置

Tips: 在修改etc/influxdb/influxdb.conf配置之前,先备份一份。

需要注意的是influxdb的三部分配置---adminhttpcollectd,分别是influxdb管理控制台、HTTP API以及对接collectd的配置。其中可以保持adminhttp的配置不动。

Tips: adminhttp使用的端口分别是80838086,只要保证端口不冲突即可。

对接collectd的默认配置如下:

  1. [[collectd]]
  2. enabled = false
  3. # bind-address = ""
  4. # database = ""
  5. # typesdb = ""
  6. # These next lines control how batching works. You should have this enabled
  7. # otherwise you could get dropped metrics or poor performance. Batching
  8. # will buffer points in memory if you have many coming in.
  9. # batch-size = 1000 # will flush if this many points get buffered
  10. # batch-pending = 5 # number of batches that may be pending in memory
  11. # batch-timeout = "1s" # will flush at least this often even if we haven't hit buffer limit
  12. # read-buffer = 0 # UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.

将其修改为:

  1. [[collectd]]
  2. enabled = true
  3. bind-address = ":25826"
  4. database = "collectd"
  5. # typesdb = ""
  6. # These next lines control how batching works. You should have this enabled
  7. # otherwise you could get dropped metrics or poor performance. Batching
  8. # will buffer points in memory if you have many coming in.
  9. # batch-size = 1000 # will flush if this many points get buffered
  10. # batch-pending = 5 # number of batches that may be pending in memory
  11. # batch-timeout = "1s" # will flush at least this often even if we haven't hit buffer limit
  12. # read-buffer = 0 # UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.
  • [collectd][enabled]置为true
  • 设置对接collectd的udp端口为25826
  • 设置influxdb中存储collectd数据的数据库为collectd

启动

influxdb的安装目录下执行:

  1. ./usr/bin/influxd run -config /opt/influxdb/etc/influxdb/influxdb.conf

/opt/influxdbinfluxdb的安装目录,注意替换成实际目录。

或者执行如下命令,将influxd作为后台程序启动:

  1. nohup /opt/influxdb/usr/bin/influxd run -config /opt/influxdb/etc/influxdb/influxdb.conf &

启动之后,查看有无错误日志。

验证

influxdb对接collectd的配置后,在启动influxdb时,会自动创建collectd数据库。

可通过influxdb的管理控制台或者RESTful接口查询其中的数据库来验证。

查询结果应如下:

  1. {
  2. "results": [
  3. {
  4. "series": [
  5. {
  6. "name": "databases",
  7. "columns": [
  8. "name"
  9. ],
  10. "values": [
  11. [
  12. "_internal"
  13. ],
  14. [
  15. "graphite"
  16. ],
  17. [
  18. "collectd"
  19. ]
  20. ]
  21. }
  22. ]
  23. }
  24. ]
  25. }

collectd

安装

参考collectd安装

配置

修改/etc/collectd.conf,如下:

  1. Hostname "localhost"
  2. LoadPlugin interface
  3. LoadPlugin cpu
  4. LoadPlugin memory
  5. LoadPlugin network
  6. LoadPlugin df
  7. <Plugin interface>
  8. Interface "eth0"
  9. IgnoreSelected false
  10. </Plugin>
  11. <Plugin network>
  12. <Server "192.168.102.16" "25826">
  13. </Server>
  14. </Plugin>

25826即为collectd上报数据的udp端口,与influxdb中配置的保持一致。

保存,执行service collectd restart,重启collectd

验证

启动完成之后,collectd会定期收集操作系统的数据,之后,将数据上报至influxdb中。

influxdb的管理控制台---192.168.102.16:8083的菜单栏的Database下拉栏中选择collectd,在Query输入下述查询语句:

grafana

安装

通过docker镜像的方式安装grafana:

  1. docker pull grafana/grafana
  2. docker run -d -p 3000:3000 grafana/grafana

grafana对外暴露的端口是3000,启动时,指定VM的端口与其对应。

设置

访问192.168.102.16:3000,默认账号是 admin/admin

image_1ao698bko2c31t4g1fna13i2o72m.png-52.9kB

Tips:

  • InfluxDB Details指定DatabasecollectdUser为默认的root/root

下面将collectd数据库中的cpu_valuedf_valuememory_value的数据绘制成数据图表。

1) 首先,选择+ New,新建Dashboard,如下:

image_1ao69fnte1v5t1br31ujv1kpv12j913.png-28.2kB

2) 在新建的Dashboard页面,点击+ADD ROW,在左侧选择新建Graph,如下:

image_1ao69lmuu14tk5hu1aq725018uu1g.png-12.8kB

之后,新创建的Graph页面如下:
image_1ao69o8t718v17pj11o02klrpa1t.png-37.8kB

会有个默认数据图表,点击右侧的image_1ao6a1d0a1eev1v1q1djr15lb1u0r3h.png-0.3kB删除。

3) 在Panel data source中选择collectd数据库,点击+ Add Query添加查询语句,如下:

image_1ao69vq2u6qn182aqdv1lha1pcg34.png-9.9kB

image_1ao6a2pjrjla19qf14sl173r1rk3u.png-68.9kB

比如,需要展示剩余的CPU,对应的数据库查询语句为select value from cpu_value where type_instance = 'idle' and type = 'cpu'

  • select measurement选择cpu_value

  • 点击where后的+增加过滤语句

  • 点击第二行(SELECT)的mean()上方位置,会出现x,将其删除

  • 同样操作,将第三行(GROUP BY)的time ($interval)fill (null)移除

最终结果:
image_1ao6aj73u9kf1flp150o1b9lmfh4b.png-15kB

4) 保存Dashboard

image_1ao6akc6itkj10e3umn1dgl76h4o.png-10.7kB

选择菜单栏中的新建的Dashboard,选择新建的Dashboard,就可以看到所有的数据图表了。

image_1ao6an88av3t951aus2ksgoo55.png-18.9kB

效果如下:

image_1ao6apg63tuj10pmhhb34j1b3n5i.png-63.2kB

提取图片

点击Graph的名称,选择share,如下:

1.jpg-70.7kB

2.jpg-40.2kB

Link页签中,包含了访问该图表的链接;在Embed中指明了通过iframe的方式,将该图表嵌入至其他页面的方式。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注