1.grafana introduction
Grafana is an open source metric analytics & visualization suite. It is most commonly used for visualizing time series data for infrastructure and application analytics but many use it in other domains including industrial sensors, home automation, weather, and process control.
这是官方原话,个人理解,grafana就是一个实时监控及可视化的工具;当然grafana还有很多功能,还有待深入学习;
2.Installation grafana
因为我们生产上使用的是4.1.2这个版本,所以这里就用这个版本来demo:
[root@sht-sgmhadoopcm-01 local]#wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.1.2-1486989747.linux-x64.tar.gz
[root@sht-sgmhadoopcm-01 local]#tar -zxvf grafana-4.1.2-1486989747.linux-x64.tar.gz
[root@sht-sgmhadoopcm-01 local]#mv grafana-4.1.2-1486989747 grafana
[root@sht-sgmhadoopcm-01 local]#mkdir -p /usr/local/grafana/data/{log,plugins}
grafana has a number of configuration options, but we only need update a part of parameter, other can default.
grafana配置文件有很多参数,但是我们只需要注意和修改以下几个,其他默认即可
[root@sht-sgmhadoopcm-01 grafana]# vim conf/defaults.ini app_mode = production instance_name = ${HOSTNAME} [paths] data = data logs = data/log plugins = data/plugins [server] protocol = http http_port = 3000 domain = localhost [database] type = sqlite3 host = 127.0.0.1:3306 name = grafana user = root path = grafana.db [session] provider = file provider_config = sessions cookie_name = grafana_sess cookie_secure = false session_life_time = 86400 gc_interval_time = 86400 [security] admin_user = admin admin_password = admin
Start grafana 启动grafana:
[root@sht-sgmhadoopcm-01 grafana]# ./bin/grafana-server web &
Note:
如果你没有使用默认的参数,启动grafana的使用需要指定参数启动
The custom configuration file path can be overridden using the -config parameter
[root@sht-sgmhadoopcm-01 grafana]# bin/grafana-server web -config conf/custom.ini &
3. Adding the Data Source
这里所使用到的源数据是ES,在上一篇博客中有介绍如何使用ES,请参考链接:http://blog.51cto.com/darrenmemos/2125317
grafana展示的数据来源就是通过query ES,除了ES,grafana还支持Graphite,Prometheus,InfluxDB,OpenTSDB,MySQL,AWS Cloudwatch等;
添加源数据的Step:
(1) Open the side menu by clicking the Grafana icon in the top header.
(2) In the side menu under the Dashboards link you should find a link named Data Sources.
(3) Click the + Add data source button in the top header.
(4) Select Elasticsearch from the Type dropdown.
4.Creating Dashboard and panel
创建Dashboard比较简单,这里不再演示,一旦dashboard创建好,我们就可以同时选择一个panel;
panel有这么几种:Graph,Singlestat,Table,Test,Alert List等,常用的是前三种;
具体可以参考链接:http://docs.grafana.org/v4.1/features/datasources/graphite/
5.Case: 实时展示系统每1分钟的负载
实现功能:实时展示系统每1分钟的负载,这里共有三个instance:
6.case:实时展示系统memory已使用百分比
7.case:实时展示系统磁盘使用百分比
这里每个instance只选择使用百分比最大的挂载点展示
8.case:实时展示error log:
8.1 先创建template变量
create templating :hostname 和log_type
8.2 创建panel
8.3 Test
[root@sht-sgmhadoopcm-01 log]# echo "Error" >> /var/log/messages
[root@sht-sgmhadoopnn-02 log]# echo "Error" >> messages
9. 最后调整一下面板,再展示一下整体效果图