v2.0
Grafana连接时序数据库(MD5模式)
-
数据库密码认证方式必须为MD5。
-
安装grafana。
docker run -d -p 3000: 3000 --name grafana grafana/grafana
-
创建测试表并插入数据。
CREATE TIMESERIES POLICY IF NOT EXISTS tsbs_policy WITH(duration = '1 year', chunkgroupduration = '1 day'); CREATE TIMESERIES TABLE cpu( time timestamp TSTIME, hostname text TSTAG, region text TSTAG, datacenter text TSTAG, rack text TSTAG, os text TSTAG, arch text TSTAG, team text TSTAG, service text TSTAG, service_version text TSTAG, service_environment text TSTAG, usage_user float, usage_system float, usage_idle float, usage_nice float, usage_iowait float, usage_irq float, usage_softirq float, usage_steal float, usage_guest float, usage_guest_nice float ) POLICY tsbs_policy; CREATE INDEX ON cpu USING btree(hostname, time desc) LOCAL;
-
配置Grafana。
a. 增加数据源。
b. 增加dashboard。
点击 “Add a new panel”,Data source 选择数据源。
c. 保证生成的SQL可以运行。
SELECT time_bucket('60 seconds', time) AS minute, max(usage_user) AS max_usage_user FROM cpu WHERE hostname IN ('host_313') AND time >= '2022-01-01 00:36:15.552285 +0000' AND time < '2022-07-04 01:36:15.552285 +000' GROUP BY minute ORDER BY minute ASC; SELECT time_bucket('60 seconds', time) AS minute, max(usage_user) AS max_usage_user FROM cpu WHERE hostname IN ('host_364', 'host_337', 'host_128', 'host_151', 'host_141', 'host_226', 'host_275') AND time >= '2022-07-01 05:56:35.685235 +0000' AND time <= '2022-07-05 00:23:44.331213 +0000' GROUP BY minute ORDER BY minute ASC;
d. 查看执行结果。