grafana数据展示超时解决方案

grafana数据展示超时,
sql如下:

SELECT     adx,     ad_size,     traffictype,     geo_country,     media,     updateday,     sum(map_cnt) as mapCnt,     sum(cnt) as reqCnt,     sum(map_cnt) / sum(cnt) as ratio FROM dsp.retarget_dim_tbl WHERE     updateday >= toDate(1568181967) AND toDateTime(updateday) >= toDateTime(1568181967)     AND adx = 'google' GROUP BY     adx,     ad_size,     traffictype,     geo_country,     media,     updateday

同样的sql在Dbeaver上查询clickhouse就没问题
在grafana上查询就超时不出数据
原因在于Dbeaver上,数据并不是一次全加载出来,而是所谓的懒加载,也就是数据不完全加载而grafana是全加载,所以会超时卡死

查了下结果条数: 为14565534 (1400w)
sql如下

select count(*) from
(
SELECT     adx,     ad_size,     traffictype,     geo_country,     media,     updateday,     sum(map_cnt) as mapCnt,     sum(cnt) as reqCnt,     sum(map_cnt) / sum(cnt) as ratio FROM dsp.retarget_dim_tbl WHERE     updateday >= toDate(1568181967) AND toDateTime(updateday) >= toDateTime(1568181967)     AND adx = 'google' GROUP BY     adx,     ad_size,     traffictype,     geo_country,     media,     updateday
)

1400w数据全部加载出来,不死才怪

考虑到业务主要看 reqCnt mapCnt ratio 量最大的数
所以sql改为:

SELECT * FROM (     SELECT         adx,         ad_size,         traffictype,         geo_country,         media,         updateday,         sum(map_cnt) as mapCnt,         sum(cnt) as reqCnt,         sum(map_cnt) / sum(cnt) as ratio     FROM dsp.retarget_dim_tbl     WHERE         updateday >= toDate(1568185625) AND toDateTime(updateday) >= toDateTime(1568185625)         AND adx = 'google'     GROUP BY         adx,         ad_size,         traffictype,         geo_country,         media,         updateday ) ORDER BY     reqCnt DESC,     mapCnt DESC,     ratio DESC LIMIT 500

排序后,只取500条 这样就不会卡死了,问题解决

改后的生成模板为:

SELECT * FROM
(
SELECT
   ${groupby:csv}, sum(map_cnt) as mapCnt, sum(cnt) as reqCnt, sum(map_cnt)/sum(cnt) as ratio
FROM $table
WHERE $timeFilter 
GROUP BY ${groupby:csv}
) ORDER BY reqCnt DESC,mapCnt DESC ,ratio DESC LIMIT 500

以前的模板为

SELECT
   ${groupby:csv}, sum(map_cnt) as mapCnt, sum(cnt) as reqCnt, sum(map_cnt)/sum(cnt) as ratio
FROM $table
WHERE $timeFilter 
GROUP BY ${groupby:csv}

你可能感兴趣的:(grafana)