1.本文简介
本文章简单介绍如何利用Glances、InfluxDB以及Grafana搭建一个图形化的监测系统。
安装过程中出现问题请参考第6章问题总结
搭建环境:ubuntu 16.04
2.Glances
Glances是一种跨平台监控工具,它使用python语言开发,旨在通过curses或基于Web的界面呈现大量监控信息。信息根据用 户界面的大小动态调整.
2.1)资料介绍
https://github.com/nicolargo/glances
https://pypi.org/project/Glances/
https://glances.readthedocs.io/en/stable/install.html
2.2)安装
本文选择Glances3.1.0安装
Requirements
-
python 2.7,>=3.4
-
psutil>=5.3.0
-
bottle (for Web server mode)
sudo apt-get install python-dev
sudo apt-get install python-pip
sudo apt-get install glances
2.3) 使用
详细请参考下面手册
https://glances.readthedocs.io/en/stable/quickstart.html
本文只使用以下几个命令:
glances -V 查看版本
jlinux@jlinux-virtual-machine:~$ glances -V
Glances v3.1.0 with psutil v5.6.2
glances 终端显示
glances -w 启动网页服务
3.InfluxDB
InfluxDB 是一个开源分布式时序、事件和指标数据库。使用 Go 语言编写,无需外部依赖。其设计目标是实现分布式和水平伸缩扩展
3.1)资料介绍
https://docs.influxdata.com/influxdb/v1.7/introduction/installation/
3.2) 安装
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,}
${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update && sudo apt-get install influxdb
sudo pip install influxdb (python语言需要)
3.3) 使用
4. Grafana
Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知
4.1)资料介绍
https://grafana.com/docs/installation/debian/
4.2)安装
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install grafana
4.3) 使用
sudo service grafana-server start
登录grafana网页
用户:密码默认 admin:admin
登录后的界面:
点击Add data source添加数据源:
添加面板:
运行glances –export influxdb,然后需要修改下面板
下面可以看见cpu 栏有图形在汇画
最后配置好面板,可成功显示下面界面(有关如何配置grafana,请参考官方问题,下一章将详细讲解图形配置)
5.参考文章
https://www.tecmint.com/install-glances-influxdb-grafana-to-monitor-centos-7/
http://feixiao.github.io/2015/10/08/glances/
http://www.andremiller.net/content/grafana-and-influxdb-quickstart-on-ubuntu
6.问题总结
1. glances --export influxdb 无反应,直接退出(正常会显示glances界面)
A:是因为glances 无配置文件,需要自己添加
https://glances.readthedocs.io/en/stable/config.html
http://note.youdao.com/noteshare?id=b55ee265654bd44e7af5ef4a98754ec0
2.“ImportError:No module named influxdb”
A:未安装Python influxDB,需要sudo pip install influxdb
A:https://www.cnblogs.com/EasonJim/p/7343892.html
4."gpg: no valid OpenPGP data found."
A:关闭终端,重新开启一个
5."Bottle module not found. Glances cannot start in web server mode"
A:sudo pip install bottle
6.ImportError: No module named 'ConfigParser'
7. I got "AttributeError: 'InfluxDBClient' object has no attribute 'get_database_list'"
https://github.com/nicolargo/glances/issues/753
A: 6和7问题都是因为python与glances版本依赖关系不对引起的,使用apt-get安装glances容易出现该问题
8.kernel too old?
A:内核需要加入io accounting
9.glances 运行出现 _curses.error: use_default_colors() returned ERR
A:终端不支持颜色绘制功能