我有一个表格,其中包含许多符合此结构的行:
time acknowledgement crit current_attempt downtime_depth execution_time hostname latency max_check_attempts metric reachable service state state_type value warn
---- --------------- ---- --------------- -------------- -------------- -------- ------- ------------------ ------ --------- ------- ----- ---------- ----- ----
1507171563000000000 999 a01-pdu kw pdu 14.94 999
1507171621000000000 999 a01-pdu kw pdu 14.92 999
1507171678000000000 999 a01-pdu kw pdu 14.45 999
1507171736000000000 999 a01-pdu kw pdu 14.93 999
1507171793000000000 999 a01-pdu kw pdu 14.88 999
1507171852000000000 999 a01-pdu kw pdu 14.92 999
1507171909000000000 999 a01-pdu kw pdu 14.9 999
1507171995000000000 999 a01-pdu kw pdu 14.91 999
1507171999000000000 999 a02-pdu kw pdu 13.41 999
我的目标是将最后一个条目设为hostname =~ /a01-pdu|a02-pdu/
并汇总其value
列
例如,如果我跑:
SELECT last(value) AS last INTO pdu_abcd12 FROM pdu WHERE hostname =~ /a01-pdu/;
SELECT last(value) AS last INTO pdu_abcd12 FROM pdu WHERE hostname =~ /a02-pdu/;
SELECT sum(last) FROM (SELECT * FROM pdu_abcd12 ORDER BY DESC LIMIT 8)
time sum
---- ---
0 105.97
我能够得到这两个值的总和,但这需要我每次想要查看数据时都运行上面的InfluxQL命令。有没有办法让命令定期运行,以便我可以在Grafana中可视化实时数据?
答案 0 :(得分:0)
创建continuous queries,例如:
CREATE CONTINUOUS QUERY last_sum ON <db name>
BEGIN
SELECT last(value) AS last INTO pdu_abcd12
FROM pdu
WHERE hostname =~ /a01-pdu/
GROUP BY time(1h), hostname
END
请注意,CQ需要group by
。主机名也包含在上面的组中,以考虑正则表达式匹配的多个主机名。否则他们的价值将被一起选择。
另一个选项是Kapacitor,它更灵活,但也更复杂,流处理语法。