Divide two metric values with influxdb and grafana and show a single value as result for alerting

HI,

I have not used influxdb queries very often, so consider this question as a newbie question.

I want to divide inBandwidth with outBandwidth from the iftraffic check.

Example Query:

SELECT sum("value") FROM "autogen"."iftraffic64_alias" WHERE ("hostname" =~ /myHost/ AND "service" =~ /Uplink ISP/ AND "metric" =~ /Bandwidth/) AND $timeFilter GROUP BY "metric"

gives:

image

What i want is something like:

SELECT sum("inBandwidth")/sum("outBandwidth") FROM "autogen"."iftraffic64_alias" WHERE ("hostname" =~ /myHost/ AND "service" =~ /Uplink ISP/ AND "metric" =~ /Bandwidth/) AND $timeFilter

Or in plain dEnglish: I want one number as result for alerting, which shows the ratio from up and download for the last 30 Minutes. I have the two metrics in one series.

Thanks for support.
Rafael

Found it:

SELECT sum(inBandwidth) / sum(outBandwidth) AS Ratio
FROM
(
SELECT sum(value) as outBandwidth FROM iftraffic64_alias WHERE “metric” = ‘outBandwidth’ AND Time > now() -30m
)
,
(
SELECT sum(value) as inBandwidth FROM iftraffic64_alias WHERE “metric” = ‘inBandwidth’ AND Time > now() -30m
)
GROUP BY hostname

1 Like

The same query isn’t working for me. I am on influx 1.7 version
Query -

SELECT sum("400") + sum("200")  AS "successRate" FROM (SELECT sum("value") AS "200" FROM "api.overall.200" WHERE time > now() - 100s),( SELECT sum("value") AS "400" FROM "api.overall.400" WHERE time > now() - 10s)  group by time(60s)

Can anyone suggest what is wrong in this query? It works fine when I use single metric like sum(“200”) + sum(“200”)

Do you get any Error Messages?

sadly I’am not that deep into influxdb, i can’t see whats wrong.