Grafana + mysql数据源

1.首先去官网下载grafana 传送官网
2.解压后进入conf目录,修改default.ini(虽然官网不推荐直接修改这个文件),要使用mysql作为数据源,需要修改的内容:

[database]
# You can configure the database connection by specifying type, host, name, user and password
# as separate properties or as on string using the url property.

# Either "mysql", "postgres" or "sqlite3", it's your choice
type = mysql
host = 127.0.0.1:3306
name = 
user = 
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password =

官网推荐添加一个有SELECT权限的账号即可,但是根据使用,grafana会创建表,所以还需要CREATE权限,鉴于比较麻烦,直接创建一个ALL权限的数据库账号。
3../bin/grafana-server启动grafana
4.访问localhost:3000首先配置数据源
http://or0f3pi7r.bkt.clouddn.com/17-10-18/19007349.jpg
根据自己选项配置信息。
5.创建dashboard,选一个需要的类型,这里以graph为例。
http://or0f3pi7r.bkt.clouddn.com/17-10-18/84161916.jpg
点击Panel Title(当然点上面一条黑的都可以),会弹出对话框选择edit,弹出一个配置框
http://or0f3pi7r.bkt.clouddn.com/17-10-18/74261133.jpg
根据提示写SQL,<time_column>是一个时间戳,也就是说你的数据里要带有一个这样的字段。
<value column>表示要显示的数据,<series name column>表示要显示哪一些数据,举个例子part字段有2个值,0、1,那么就会有2条线展示数据。$__timeFilter是宏定义,点击show help里面会有描述。之后只要ctrl+s保存配置信息就好。
看一下效果,因为这里只是随便展示,效果不是很好,因为同一个时间段出现了多个数据
http://or0f3pi7r.bkt.clouddn.com/17-10-18/18769398.jpg

猜你喜欢

转载自blog.csdn.net/sweatott/article/details/78278011
今日推荐