安裝使用環境爲MAC,使用工具安裝:mysql
brew update brew install grafana
配置Grafana鏈接本地安裝的mysql,mysql安裝不作說明,配置文件列表以下:sql
配置文件應該位於/usr/local/etc/grafana/grafana.ini 日誌文件應該位於/usr/local/var/log/grafana/grafana.log 若是你想手動安裝一個插件放在這裏:/usr/local/var/lib/grafana/plugins 默認的sqlite數據庫位於 /usr/local/var/lib/grafana
其中,編輯grafana.ini文件鏈接數據庫,重點配置數據庫的鏈接類型,帳號,密碼,數據庫名(切記數據庫創建對應的數據庫)數據庫
重啓Grafana服務工具
brew tap homebrew/services brew services start grafana
此時網頁訪問localhost:3000即爲Grafana配置數據源頁面(默認帳號密碼:admin / admin)測試
鏈接測試後保存,這樣在圖表展現數據源勾選默認即爲mysql指定數據庫,或者勾選指定鏈接名
spa
數據庫構建表結構,錄入測試數據插件
編輯,鑑於展現目的爲不按照時序排列的柱狀圖,可是Grafana的展現要求有時間字段在列,命名與time相關,故查詢時添加time字段爲當前時間,返回結果能夠爲兩種可用形式,故展現兩種SQL查詢:日誌
select now() as time, case when (score >=80) then '[80, ~)' when (score >=60 and score <80) then '[60, 80)' when (score >=40 and score <60) then '[40, 60)' when (score >=20 and score <40) then '[20, 40)' else '(~, 20)' end grade, count(*) num from grade group by case when (score >=80) then '[80, ~)' when (score >=60 and score <80) then '[60, 80)' when (score >=40 and score <60) then '[40, 60)' when (score >=20 and score <40) then '[20, 40)' else '(~, 20)' end order by 1;
展現結果爲:code
select *, now() as time from (select count(*) as '[80, ~)' from grade g where g.score >=80) a, (select count(*) as '[60, 80)' from grade g where g.score >=60 and g.score <80) b, (select count(*) as '[40, 60)' from grade g where g.score >=40 and g.score <60) c, (select count(*) as '[20, 40)' from grade g where g.score >=20 and g.score <40) d, (select count(*) as '(~, 20)' from grade g where g.score <20) e;
展現結果爲:orm
重要設置,選擇series,選個表明數據是按series分組不是按時間,當前所選時間段進行計算。Y軸仍然表示 值。計算series的avg、min、max、total等。:
效果圖爲:
兩種結果都能正常顯示,根據顯示規律總結爲:
附上官網說明文檔,http://docs.grafana.org/