想打造 New Relic 那样漂亮的实时监控系统我们只需要 InfluxDB/collectd/Grafana 这三个工具,这三个工具的关系是这样的:

采集数据(collectd)-> 存储数据(InfluxDB) -> 显示数据(Grafana)。

  • InfluxDB 是 Go 语言开发的一个开源分布式时序数据库,非常适合存储指标、事件、分析等数据,看版本号(v0.8.8)就知道这个项目还很年轻;
  • collectd 就不用介绍了吧,C 语言写的一个系统性能采集工具;
  • Grafana 是纯 Javascript 开发的前端工具,用于访问 InfluxDB,自定义报表、显示图表等。

下面的安装和配置步骤在 Ubuntu 14.04 Server 64bit 版上完成。升级整个系统后重启:

  1. $ sudo apt-get update
  2. $ sudo apt-get upgrade
  3. $ sudo reboot

安装 InfluxDB

InfluxDB 是 Go 写的,不依赖任何其他包或库,很干净。安装很容易:

  1. $ wget https://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb
  2. $ sudo dpkg -i influxdb_latest_amd64.deb

启动 InfluxDB:

  1. $ sudo /etc/init.d/influxdb start
  2. Setting ulimit -n 65536
  3. Starting the process influxdb [ OK ]
  4. influxdb process was started [ OK ]

启动后打开 web 管理界面 http://192.168.2.183:8083/ 默认用户名和密码是 root 和 root. InfluxDB 的 Web 管理界面端口是 8083,HTTP API 监听端口是 8086,如果需要更改这些默认设定,修改 InfluxDB 的配置文件 /opt/influxdb/current/config.toml 后重启 InfluxDB 就可以了。

InfluxDB

在刚安装好的 InfluxDB 上创建一个名为 collectd 的数据库,可以用命令行创建,也可以用 Web 管理界面操作:

  1. $ curl "http://192.168.2.183:8086/db?u=root&p=root" -d "{\"name\": \"collectd\"}"

InfluxDB

安装 collectd

安装 collectd:

  1. $ sudo apt-get install collectd

配置 collectd 为客户端,收集到数据后直接发给 InfluxDB:

  1. $ sudo vi /etc/collectd/collectd.conf
  2. ...
  3. LoadPlugin network
  4. ...
  5. <Plugin network>
  6. Server "192.168.2.183" "25826"
  7. </Plugin>
  8. ...

重启 collectd:

  1. $ sudo /etc/init.d/collectd restart

InfluxDB 现在自带一个 collectd 插件来获取 collectd 客户端发来的数据,以前可没这么方便哦,0.8.4 版本以前只能通过 influxdb-collectd-proxy 这样的第三方程序来连接 collectd 和 InfluxDB. 如果你检查一下服务器上打开的端口就会发现 influxdb 插件启动了一个 25826 端口,如果发现 InfluxDB 数据库里没有(收集到)数据,务必检查这个 25826 端口是否正常启动了:

  1. $ sudo netstat -tupln
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 622/sshd
  5. tcp6 0 0 :::8086 :::* LISTEN 668/influxdb
  6. tcp6 0 0 :::22 :::* LISTEN 622/sshd
  7. tcp6 0 0 :::8090 :::* LISTEN 668/influxdb
  8. tcp6 0 0 :::8099 :::* LISTEN 668/influxdb
  9. tcp6 0 0 :::8083 :::* LISTEN 668/influxdb
  10. udp6 0 0 :::25826 :::* 668/influxdb

InfluxDB 自带的 collectd 插件默认是关闭的,需要手动配置打开 enabled = true,并填上 database = “collectd” 这一行,这里的 “collectd” 就是我们上面创建的那个数据库,更改配置后记得重启 InfluxDB:

  1. $ sudo vi /opt/influxdb/current/config.toml
  2. $ sudo vi /opt/influxdb/shared/config.toml
  3. ...
  4. # Configure the collectd api
  5. [input_plugins.collectd]
  6. enabled = true
  7. # address = "0.0.0.0" # If not set, is actually set to bind-address.
  8. # port = 25826
  9. database = "collectd"
  10. # types.db can be found in a collectd installation or on github:
  11. # https://github.com/collectd/collectd/blob/master/src/types.db
  12. # typesdb = "/usr/share/collectd/types.db" # The path to the collectd types.db file
  13. ...
  14. $ sudo /etc/init.d/influxdb restart
  15. Setting ulimit -n 65536
  16. Setting ulimit -n 65536
  17. influxdb process was stopped [ OK ]
  18. Setting ulimit -n 65536
  19. Starting the process influxdb [ OK ]
  20. influxdb process was started [ OK ]

现在 InfluxDB 已经准备好接受和处理 collectd 传来的数据了。用命令行或者 Web 管理界面验证一下数据库里是否有数据:

  1. $ curl -G 'http://192.168.2.183:8086/db/collectd/series?u=root&p=root&q=list+series&pretty=true'
  2. [
  3. {
  4. "name": "list_series_result",
  5. "columns": [
  6. "time",
  7. "name"
  8. ],
  9. "points": [
  10. [
  11. 0,
  12. "192.168.2.183/cpu-0/cpu-idle"
  13. ],
  14. ...
  15. ]
  16. }
  17. ]

InfluxDB

安装 Grafana

下载 grafana 后解压放到 web 服务器上就可用。这里省去配置 Nginx/Apache 之类的麻烦,直接用最简单的 Web 服务器 python -m SimpleHTTPServer 驱动:

  1. $ wget http://grafanarel.s3.amazonaws.com/grafana-1.9.1.tar.gz
  2. $ tar xzvf grafana-1.9.1.tar.gz
  3. $ cd grafana-1.9.1.tar.gz
  4. $ cp config.sample.js config.js
  5. $ vi config.js
  6. ...
  7. // InfluxDB example setup (the InfluxDB databases specified need to exist)
  8. datasources: {
  9. influxdb: {
  10. type: 'influxdb',
  11. url: "http://192.168.2.183:8086/db/collectd",
  12. username: 'root',
  13. password: 'root',
  14. },
  15. ...
  16. },
  17. ...
  18. $ sudo python -m SimpleHTTPServer

用浏览器访问 Grafana,这里的默认端口是 8000:

https://linux.cn/article-5252-1.html

使用 Grafana、collectd 和 InfluxDB 打造现代监控系统的更多相关文章

  1. 【监控】使用 Grafana、collectd 和 InfluxDB 打造现代监控系统

    参考资料:Grafana 是 Graphite 和 InfluxDB 仪表盘和图形编辑器:http://www.oschina.net/p/grafana 使用 Grafana.collectd 和 ...

  2. [经验交流] 试用基于 influxdb+kapacitor 的监控系统

    2017年10月16日: 使用中发现kapacitor的ui过于简单,不能满足实际工作需要,现已切换到grafana --------- 两个月前试用了基于 elasticsearch + xpack ...

  3. collectd+logstash+influxdb+grafana构建windows服务器应用监控系统

    一.背景介绍 本监控方案支持对Windows Server服务器集群的全面监控,方案提供丰富的图表展示, 以及对异常问题进行邮件的实时报警. 本系统由Collectd(操作系统数据搜集).logsta ...

  4. WIndows下使用Grafana+InfluxDB打造监控系统

     前言 对于一个运维DBA来说,了解数据库的TPS.QPS很有必要(QPS:每秒查询数,即对数据库每秒的DML的操作数:TPS:每秒事物处理,即对数据库每秒DDL操作数),通过了解他们,可以掌握一个实 ...

  5. 使用cAdvisor+Influxdb+Grafana监控系统

      今天准备开始研究研究当前非常流行的Grafana+Influxdb监控系统,两者都是非常轻量级的应用但是功能却异常强大,可以说Grafana在作图显示方面真的毫不逊色与Cacti. 组件介绍 cA ...

  6. Telegraf+InfluxDB+Grafana快速搭建实时监控系统 监控postgresql

    Telegraf+InfluxDB+Grafana快速搭建实时监控系统  监控postgresql

  7. Windows下本机简易监控系统搭建(Telegraf+Influxdb+Grafana)

    一.文件准备 1.1 文件名称 telegraf-1.2.1_windows_amd64.zip influxdb-1.2.2_windows_amd64.zip grafana-4.2.0.wind ...

  8. Windows下本机简易监控系统搭建(Telegraf+Influxdb+Grafana)--转

    原文地址:http://www.cnblogs.com/liugh/p/6683488.html 一.文件准备 1.1 文件名称 telegraf-1.2.1_windows_amd64.zip in ...

  9. Telegraf+Influxdb+Grafana(Windows下本机简易监控系统搭建)

    1.文件名称 telegraf-1.5.0_windows_amd64.zip influxdb-1.4.2_windows_amd64.zip grafana-4.6.3.windows-x64.z ...

随机推荐

  1. SQL SERVER获取数据库中所有表名 XTYPE类型

    SELECT (case when a.colorder=1 then d.name else null end) 表名, a.colorder 字段序号,a.name 字段名,  (case whe ...

  2. Fetch from Upstream 变灰失效

    Team——>Remote——>Configure Fetch from Upstream… Team——>Remote——>Configure Push to  Upstre ...

  3. ural 1075. Thread in a Space

    1075. Thread in a Space Time limit: 1.0 secondMemory limit: 64 MB There are three points in a 3-dime ...

  4. 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest D. Do it Right!

    D. Do it Right! time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. BZOJ4380 : [POI2015]Myjnie

    将$c$离散化,设: $f[i][j][k]$为区间$[i,j]$最小值为$k$的最大收益. $g[i][j][k]$为$\max(g[i][j][k..m])$. $h[i][j]$为对于当前DP区 ...

  6. ACM 背包问题

    背包问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 现在有很多物品(它们是可以分割的),我们知道它们每个物品的单位重量的价值v和重量w(1<=v,w< ...

  7. ACM 阶乘之和

    阶乘之和 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 给你一个非负数整数n,判断n是不是一些数(这些数不允许重复使用,且为正数)的阶乘之和,如9=1!+2!+3! ...

  8. 使用Canvas绘制图形的基本教程

    原文地址:http://www.cnblogs.com/picaso/archive/2012/11/26/2789077.html HTML5火的正热,最近有个想法也是要用到HTML的相关功能,所以 ...

  9. Codeforces #Round 376 部分题解

    A: 题目传送门:http://codeforces.com/problemset/problem/731/A 直接根据题意模拟即可 #include "bits/stdc++.h" ...

  10. URAL 1031. Railway Tickets(spfa)

    题目链接 不知为何会在dp里呢...INF取小了,2Y. #include <cstring> #include <cstdio> #include <string> ...