Ubuntu 16.04 安装Grafana并配置监控(Graf
安装Grafana:
安装完成后,通过以下命令启动服务:
sudo service grafana-server start
通过地址 http://{IP}:3000 进行访问,默认用户名/密码 为 admin/admin
![](https://img.haomeiwen.com/i4853806/2e2f9d026f7f285c.png)
安装插件:
使用命令查看已有的插件列表:grafana-cli plugins list-remote
![](https://img.haomeiwen.com/i4853806/302551f0cd9ecf30.png)
可以看到插件列表大致分为三类:面板(panel),数据源(datasource)和 应用(app),我们可以通过以下命令安装插件:
sudo grafana-cli plugins install {插件名称}
service grafana-server restart #安装完成需要重启Grafana 服务
![](https://img.haomeiwen.com/i4853806/212484926b7567f3.png)
![](https://img.haomeiwen.com/i4853806/f85450ba6c4336df.png)
![](https://img.haomeiwen.com/i4853806/9d1ca1317bdf57f0.png)
如何使用Grafana+zabbix 去搭建炫丽的服务器监控,网上已经有很多教程,此处就不再赘述,这里主要交接一下如何自己创建数据库表(MySQL),并结合Grafana 来渲染展示。
创建数据库 及 相关表:
create databases log_mon;
create table montor_info (
IP varchar(12) not null,
chain_tag varchar(32) not null,
height bigint(32) not null,
diff_value varchar(32) not null,
base_diff_value varchar(32) not null,
block_txnum int(8) not null,
create_block_time varchar(32) not null,
write_block_time varchar(32) not null,
orgbatch_len int(8) not null,
peer_num int(8) not null,
minner varchar(32) not null,
system_date TIMESTAMP default now()
)
表中的数据由监控脚本实时插入数据库。
Grafana创建MySQL数据源:
进入 home -> Data Source:
![](https://img.haomeiwen.com/i4853806/2585c5f348ebb48a.png)
![](https://img.haomeiwen.com/i4853806/4c254b6abce162e5.png)
![](https://img.haomeiwen.com/i4853806/a829d91e3888ca94.png)
新增仪表板
![](https://img.haomeiwen.com/i4853806/a4ce45562b89ae6b.png)
![](https://img.haomeiwen.com/i4853806/34103285e305db1d.png)
![](https://img.haomeiwen.com/i4853806/ce5272c96c54880c.png)
新增table面板
![](https://img.haomeiwen.com/i4853806/af12e83b0d91e529.png)
![](https://img.haomeiwen.com/i4853806/d437e9bc8df96737.png)
![](https://img.haomeiwen.com/i4853806/8e10932b48faab35.png)
![](https://img.haomeiwen.com/i4853806/9e6a746cc66a5bf1.png)
可以看到,查询出来的了数据被展示在了上面的面板中,可是数据的展示格式有问题,我们可以在 Column Styles 中进行设置:
![](https://img.haomeiwen.com/i4853806/95d530b48455a2b6.png)
![](https://img.haomeiwen.com/i4853806/d196c455c205427a.png)
绘制曲线图:
![](https://img.haomeiwen.com/i4853806/29de829b46897aa1.png)
![](https://img.haomeiwen.com/i4853806/d386ed4399f2ada6.png)
![](https://img.haomeiwen.com/i4853806/bbcdd6edebd1f448.png)
![](https://img.haomeiwen.com/i4853806/084daa05755d620d.png)
新增单一统计展示:
![](https://img.haomeiwen.com/i4853806/75682dbf67cdc283.png)
![](https://img.haomeiwen.com/i4853806/e63f36e99d94ac23.png)
singlestat面板只能展示单一值
![](https://img.haomeiwen.com/i4853806/f3eb0b70d49db82e.png)
![](https://img.haomeiwen.com/i4853806/d1e8398dd624fcdf.png)
value to text 选项 下设置的是查询出来的数据如果为null,默认显示的值
rang to text 选项下设置的是在某一区间内 默认显示的值
分组监控设置:
很多情况下,我们需要监控多台服务器或者按条件分组监控,那么我们可以增加templating 来设置分组条件:
![](https://img.haomeiwen.com/i4853806/ae5d254b73beeb33.png)
![](https://img.haomeiwen.com/i4853806/bcdf640af7892326.png)
![](https://img.haomeiwen.com/i4853806/e17c7a5be04981a6.png)
![](https://img.haomeiwen.com/i4853806/9a7d0cbaf8770760.png)
设置完分组指标之后,为前面已经编辑好的所有监控项的Sql 语句中增加 where 条件 进行过滤
where IP = $IP and chain_tag = $chain_tag
例如下图所示:
![](https://img.haomeiwen.com/i4853806/88eb88ab386b049e.png)
成果:
下面来秀秀我的成果:
不同服务器下同一链的监控
![](https://img.haomeiwen.com/i4853806/5a307adbd0826142.png)
![](https://img.haomeiwen.com/i4853806/017563dc41592a9f.png)
同服务器不同链的监控
![](https://img.haomeiwen.com/i4853806/5a307adbd0826142.png)
![](https://img.haomeiwen.com/i4853806/66913652e770375d.png)