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

**URL:** <https://community.icinga.com/t/divide-two-metric-values-with-influxdb-and-grafana-and-show-a-single-value-as-result-for-alerting/3733>\
**Category:** Visualization, Metrics & Reporting\
**Tags:** grafana, influxdb\
**Created:** [March 9, 2020, 3:54pm UTC](https://community.icinga.com/t/divide-two-metric-values-with-influxdb-and-grafana-and-show-a-single-value-as-result-for-alerting/3733 "2020-03-09T15:54:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unic](https://community.icinga.com/user_avatar/community.icinga.com/unic/32/200_2.png) [@unic](https://community.icinga.com/u/unic)\
**Post date:** [March 9, 2020, 3:54pm UTC](https://community.icinga.com/t/divide-two-metric-values-with-influxdb-and-grafana-and-show-a-single-value-as-result-for-alerting/3733/1 "2020-03-09T15:54:13Z")

</div>

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](https://community.icinga.com/uploads/default/original/2X/f/f822594e4c21cb5618b8590849d78dcfe4e36ed5.png)

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

---

<div class="post-metadata">

**Author:** ![unic](https://community.icinga.com/user_avatar/community.icinga.com/unic/32/200_2.png) [@unic](https://community.icinga.com/u/unic)\
**Post date:** [March 12, 2020, 8:37am UTC](https://community.icinga.com/t/divide-two-metric-values-with-influxdb-and-grafana-and-show-a-single-value-as-result-for-alerting/3733/2 "2020-03-12T08:37:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nitishgoyal13](https://community.icinga.com/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@nitishgoyal13](https://community.icinga.com/u/nitishgoyal13)\
**Post date:** [September 2, 2020, 12:52pm UTC](https://community.icinga.com/t/divide-two-metric-values-with-influxdb-and-grafana-and-show-a-single-value-as-result-for-alerting/3733/3 "2020-09-02T12:52:55Z")

</div>

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

```auto
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”)

---

<div class="post-metadata">

**Author:** ![unic](https://community.icinga.com/user_avatar/community.icinga.com/unic/32/200_2.png) [@unic](https://community.icinga.com/u/unic)\
**Post date:** [September 4, 2020, 8:04am UTC](https://community.icinga.com/t/divide-two-metric-values-with-influxdb-and-grafana-and-show-a-single-value-as-result-for-alerting/3733/4 "2020-09-04T08:04:04Z")

</div>

Do you get any Error Messages?

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