一、 安装 wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.0.0-1.x86_64.rpm (下载软件) yum localinstall grafana-5.0.0-1.x86_64.rpm (安装软件)

二进制程序文件

/usr/sbin/grafana-server

init.d脚本

/etc/init.d/grafana-server

安装默认环境变量文件

/etc/sysconfig/grafana-server

配置文件

/etc/grafana/grafana.ini

systemd服务名称

grafana-server.service

日志文件

/var/log/grafana/grafana.log

默认sqlite3数据库

/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数据源。 Name-------------->可以随意取名,做好区分即可。 Type--------------->选择MySQL Host--------------->填写MySQL部署地址,我们这里在本地所以填写127.0.0.1:30050 Database----------->注意,数据库不能随意填写,这里是MySQL数据库里的数据库名字 (这里我们可以先创建好数据库root@mysqldb 11:37: [grafana]>create database grafana;) User--------------->这里的用户需要授予查询,DROP table,create table等权限。

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选项列表, 我们要选择我们刚刚添加的数据源 其中主要的难点是查询SQL SELECT UNIX_TIMESTAMP(<time_column>) as time_sec, <value column> as value, <series name column> as metric FROM <table name> WHERE $__timeFilter(time_column) ORDER BY <time_column> ASC

注: Time series:

  • return column named time_sec (UTC in seconds), use UNIX_TIMESTAMP(column)
  • return column named value for the time point value
  • return column named metric to represent the series name

其中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: SELECT UNIX_TIMESTAMP(date_time_date) as time_sec, ---时间 id_key as value, --id_key字段作为图表的值 name as metric --name字段作为图表的名称 FROM bomcdata WHERE $__timeFilter(date_time_date) ORDER BY date_time_date ASC

以及可以配置Singlestat(状态图),需要配置查询接口。

注: 以下官方文档可进行参考。 http://docs.grafana.org/features/panels/singlestat/