写个笔记备忘下,防止后面再用到。
直接配置下即可
对应的SQL如下:
SELECT
$__timeGroupAlias(ts,$__interval),
avg(metrics) AS "thread running"
FROM t_thread_running
WHERE
$__timeFilter(ts)
GROUP BY 1
ORDER BY $__timeGroup(ts,$__interval)
t_thread_running表的建表语句如下:
CREATE TABLE `t_thread_running` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`app` varchar(32) NOT NULL DEFAULT '',
`metrics` bigint unsigned NOT NULL,
`ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2445 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
最关键的点就是表里面要有个时间列,这样Grafana上才能基于时间线来绘图
里面数据大致这样子:
id app metrics ts
------ --------------------- ------- ---------------------
1 打码打码_MySQL 5 2022-05-11 17:20:00
2 打码打码_MySQL 4 2022-05-11 17:21:00
3 打码打码_MySQL 6 2022-05-11 17:22:00
4 打码打码_MySQL 5 2022-05-11 22:50:00
5 打码打码_MySQL 4 2022-05-11 22:51:00
6 打码打码_MySQL 3 2022-05-11 22:52:00
7 打码打码_MySQL 5 2022-05-11 22:43:00
20220519补充
绘制YearingSQL每日工单数看板的sql写法
SELECT
UNIX_TIMESTAMP(execute_time) as time_sec,
count(work_id) as "日工单数"
FROM core_sql_orders
WHERE $__timeFilter(execute_time) group BY date_format(execute_time,'%Y-%m-%d')
ORDER BY execute_time ASC