如何将此查询influxdb的“错误率”更改为“成功率”以在grafana上显示?

时间:2019-02-04 06:22:02

标签: grafana influxdb

我已经从grafana插件下载了仪表板,仅显示错误率,并且从面板中发现了查询错误率。我计划修改一点查询以在grafana仪表板上显示成功率。如果您不介意,请帮助我修改查询

我已经修改

SELECT sum("count") FROM "$measurement_name" WHERE ( "application" =~ /^$application$/ AND "statut" = 'ok')  AND $timeFilter GROUP BY time($__interval) fill(null)

这是来自grafana插件的原始查询。

SELECT sum("error") / sum("all") FROM (SELECT sum("count") AS "all" FROM "$measurement_name" WHERE "transaction" = 'all' AND "application" =~ /^$application$/ AND $timeFilter GROUP BY time($__interval) fill(null)), (SELECT sum("countError") AS "error" FROM "$measurement_name" WHERE "transaction" = 'all' AND "application" =~ /^$application$/ AND $timeFilter GROUP BY time($__interval) fill(null))

我希望输出成功80%,但实际输出是216400.00%

2 个答案:

答案 0 :(得分:0)

您应该能够完成此操作而无需子查询。首先尝试执行以下操作,以确保count和countError符合您的期望:

returnOjb

然后,您可以在其中进行划分的单个查询:

SELECT sum("count"),sum("countError") 
FROM "$measurement_name" 
WHERE "transaction" = 'all' AND "application" =~ /^$application$/ AND $timeFilter 
GROUP BY time($__interval) fill(null)

答案 1 :(得分:0)

我也在寻找成功率%,因此在获得了有关“ AS”和“子查询”的一些知识之后,我就能够解决。

成功率%的公式:(请求总数/已通过请求总数)* 100

您的问题的答案是以下查询:

    SELECT sum("success") / sum("all") FROM (SELECT sum("count") AS "all" FROM "$measurement_name" WHERE "transaction" = 'all' AND "application" =~ /^$application$/ AND $timeFilter GROUP BY time($__interval) fill(null)), (SELECT sum("count")-sum("countError")  AS "success" FROM "$measurement_name" WHERE "transaction" = 'all' AND "application" =~ /^$application$/ AND $timeFilter GROUP BY time($__interval) fill(null))

在这里,第二个查询将获取“已传递的请求总数”,并使用“ AS”将查询别名为“成功”。

    (SELECT sum("count")-sum("countError")  AS "success" FROM "$measurement_name" WHERE "transaction" = 'all' AND "application" =~ /^$application$/ AND $timeFilter GROUP BY time($__interval) fill(null))

在第一个查询中,您会获取“总请求”,并使用“ AS”将查询别名为“全部”。

    (SELECT sum("count") AS "all" FROM "$measurement_name" WHERE "transaction" = 'all' AND "application" =~ /^$application$/ AND $timeFilter GROUP BY time($__interval) fill(null))

现在,查询的初始部分:

   SELECT sum("success") / sum("all")

实际上将上述两个查询划分为:总请求数/通过的总请求数 并且可以通过选择单位:percent(0.0-0.1)

在grafana图的“可视化”部分中完成“ * 100”

希望,这回答了您的问题!