一、Linux安装grafana
wget https://dl.grafana.com/oss/release/grafana-6.4.3-1.x86_64.rpm
sudo yum localinstall grafana-6.4.3-1.x86_64.rpm
sudo /sbin/chkconfig --add grafana-server
sudo service grafana-server start
二、登录grafana
默认端口:3000
地址:http://ip:3000
初始管理员账号:admin,密码:admin
三、连接数据库
四、配置图表显示
左上角 + create dashboard
右上角菜单 add panel
先选择图表类型
选择数据库,写好sql
五、sql demo
select round(REAL_LOAN_DATETIME/1000) as 'time',sum(LOAN_AMOUNT) as '放款金额'
from (select LOAN_AMOUNT,REAL_LOAN_DATETIME,DATE_FORMAT(FROM_UNIXTIME(ROUND(REAL_LOAN_DATETIME/1000)),'%Y-%m-%d') as LOAN_DATE,status
from TABLE) tb
where LOAN_DATE>date_sub(curdate(),interval 10 day) and status='8' group by LOAN_DATE;
select round(REAL_LOAN_DATETIME/1000) as 'time',count(LOAN_AMOUNT) as '放款量'
from (select LOAN_AMOUNT,REAL_LOAN_DATETIME,DATE_FORMAT(FROM_UNIXTIME(ROUND(REAL_LOAN_DATETIME/1000)),'%Y-%m-%d') as LOAN_DATE,status
from TABLE) tb
where LOAN_DATE>date_sub(curdate(),interval 10 day) and status='8' group by LOAN_DATE
select now() as time_sec, other as '自动审批' from TABLE
select now() as time_sec, other as value from TABLE
六、插件扩展
以pie-chart为例
wget -nv https://grafana.com/api/plugins/grafana-piechart-panel/versions/latest/download -O /var/lib/grafana/plugins/grafana-piechart-panel.zip
cd /var/lib/grafana/plugins/
unzip grafana-piechart-panel.zip
service grafana-server restart