我在Grafana有一个查询:
$carray = json_decode($data);
$alerts = array_filter($carray->alerts, function($alert) {
return $alert->type1 == 'X';
});
foreach($alerts as $alert) {
//do something;
}
目前,此图表显示了给定时间段内rabbitmq队列中的平均邮件数,每个主机显示每个队列的单独图表。
我想基本上做同样的事情,但每个主机只有一个图表将所有队列加在一起。这意味着在指定的时间段内取所有消息计数的平均值(保持不同的[info] a.e.s.Slf4jLogger - Slf4jLogger started
[info] o.h.v.i.u.Version - HV000001: Hibernate Validator 5.2.4.Final
Oops, cannot start the server.
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) Could not find a suitable constructor in controllers.AppController. Classes
must have either one (and only one) constructor annotated with @Inject or a zero-
argument constructor that is not private.
at controllers.AppController.class(AppController.scala:18)
while locating controllers.AppController
for parameter 5 at router.Routes.<init>(Routes.scala:59)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>
(HttpRequestHandler.scala:200)
while locating play.api.http.JavaCompatibleHttpRequestHandler
while locating play.api.http.HttpRequestHandler
for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221)
at play.api.DefaultApplication.class(Application.scala:221)
while locating play.api.DefaultApplication
while locating play.api.Application
s,SELECT mean(value) FROM "queues_value" WHERE "host" =~ /$host/ AND "type" = 'rabbitmq_messages' AND $timeFilter GROUP BY time($interval), "host", "instance"
和时间间隔分开),然后将它们相加(这次只保持不同{{ 1}} s和时间间隔分开)。
问题是,instance
或host
等每个汇总函数只会影响整个查询,似乎没有办法将host
语句应用于一个聚合函数。
如果有可能,我会做这样的事情:
mean
或者这个:
sum
但这些都不是有效的语法。
本质上,我试图在给定时间段内首先处理在一个特定主机上包含一个特定队列的聚合,然后尝试处理由每个主机上的计算结果组成的聚合时间段。
有没有办法在Influxdb或grafana中完成我想要的东西?
答案 0 :(得分:2)
有一种方法可以使用InfluxDB,但这是一个两步过程。
首先,创建计算平均值的连续查询
CREATE CONTINUOUS QUERY <name> ON <database>
BEGIN
SELECT mean(value) AS value
INTO "mean_queue_value" FROM "queues_value"
WHERE "host" =~ /<host>/
AND "type" = 'rabbitmq_messages'
GROUP BY time(<interval>), "host"
END
然后只需发出查询
SELECT sum(value) FROM "mean_queue_value" GROUP BY time(<interval>), "host"