本文共 2645 字,大约阅读时间需要 8 分钟。
一、 安装
wget (下载软件)yum localinstall grafana-5.0.0-1.x86_64.rpm (安装软件)/usr/sbin/grafana-server
/etc/init.d/grafana-server
/etc/sysconfig/grafana-server
/etc/grafana/grafana.ini
grafana-server.service
/var/log/grafana/grafana.log
/var/lib/grafana/grafana.db
#默认的配置文件/etc/grafana/grafana.ini启动软件Systemctl daemon-reload (重新载入systend,扫描新的变动单元)Systemctl enable grafana-serber.service (设置开机启动)Systenctl start grafana-server访问grafana启动Granfa之后,进程名称为grafana-server。将会默认使用grafana用户和组运行Granfa进程。默认会开启HTTP的3000端口。启动服务之后直接直接在浏览器访问http://IP:3000就会出现如下界面,默认账号和用户名为admin/admin,在/etc/grafana/grafana.ini配置文件中可修改。二、 图形数据展示
1、 添加数据源点击红色框选按钮我们这里添加MySQL数据源。User Permission
The database user should only be granted SELECT permissions on the specified database & tables you want to query. Grafana does not validate that queries are safe so queries can contain any SQL statement. For example, statements like USE otherdb; and DROP TABLE user; would be executed. To protect against this we Highly recommmend you create a specific MySQL user with restricted permissions. Checkout the MySQL Data Source Docs for more information.最后点击Save & Test按钮,出现OK才可以使用。2、 绘制图形
点击仪表板-->+New新建一个仪表板这里有很多图形绘制选择,我们选择Graph
然后弹出图形,并点击Panel Title
点击编辑。
再Metrics选项列表,
我们要选择我们刚刚添加的数据源注:
Time series:其中MySQL数据库里面必须有一张存储数据的表,且必须含有time_sec (UTC in seconds),value,metric这三个字段,也就是对应的时间,值,显示名称。
我们建立一张表:
root@mysqldb 11:37: [grafana]> create table bomcdata(id char(30),name char(50),id_key int(15),date_time_date timestamp,primary key(id));在表中插入数据:
insert into bomcdata values('20180508105923','测试',3,'2018-05-08 11:01:22');Grafana展示台写入以下查询SQL:
SELECTUNIX_TIMESTAMP(date_time_date) as time_sec, ---时间id_key as value, --id_key字段作为图表的值name as metric --name字段作为图表的名称FROM bomcdataWHERE $__timeFilter(date_time_date)ORDER BY date_time_date ASC以及可以配置Singlestat(状态图),需要配置查询接口。
转载于:https://blog.51cto.com/13728665/2114392