grafana之mysql数据源设置变量

行云流水
2022-05-02 / 0 评论 / 1,282 阅读 / 正在检测是否收录...

前言

grafana配置完成后,经常在mysql的数据库内读取数据。有时候采用变量的形式,通过一下方法设置变量。

添加变量

DropCounts

SELECT 'DropCounts' AS __text, ROUND((${__to}+1000-${__from})/6000000) AS __value FROM  report  limit 1

OUT_ITEMS

SELECT 'OUT_ITEMS' AS __text,  '(401,402, 467,468)' as __value

调用变量

变量调用变量

SELECT 'O_OUTRATE' AS __text, SUM(value) as __value
FROM 
(SELECT  
  date_format(from_unixtime(clock), '%Y-%m-%d %H:%i') as time, value  
FROM  history
WHERE itemid IN ${OUT_ITEMS}
AND $__unixEpochFilter(clock)
ORDER BY time
  ) 
AS temp 
GROUP BY time
ORDER by __value 
DESC LIMIT ${DROPCOUNTS},1

Time series 调用

SELECT 
    unix_timestamp(time) as time_sec, 
    ${O_OUTRATE} as value,
    'Out端口流量95值' as metric  
FROM 
(SELECT  date_format(from_unixtime(clock), '%Y-%m-%d %H:%i') as time
FROM  history
WHERE itemid IN ${OUT_ITEMS}
AND   $__unixEpochFilter(clock)
ORDER BY  time) 
AS temp 
GROUP BY time;

评论 (0)

取消
只有登录/注册用户才可评论