InfluxDB mathematics across measurements

寵の児 提交于 2021-01-29 02:16:03

问题


I have two measurements in my InfluxDB, say, mem_used and mem_ available.
I tried to query across those measurements and do a mathematics with

SELECT mean("mem_used_value") / mean("mem_available_value") FROM 
    (
     SELECT mean("value") AS "mem_used_value", 
            mean("value") AS "mem_available_value"
     FROM "dbname"."autogen"."mem_used",
          "dbname"."autogen"."mem_available"
     GROUP BY time(1m)
    )
GROUP BY time(1m)

The result of the query is very weird, and I was wondering if it’s possible for InfluxDB to perform a mathematics across measurements.

I have did some research about this feature and found the issue 3552 Mathematics across measurements is still opening. However, it was requested three years ago.

Is there any approach to do this? any advice is welcome.


回答1:


There's no JOINs in Influx QL.

Remember pls: that's NOT a relational DB, the query language may look familiar, but it is a totally different thing.

Here's what you can do.

1) The smartest & legit-iest way: shape your measurement properly.

Currently you didn't: there should not be two measurements, but one, like (in line protocol notation)

memusage,host=yourhost,othertag=something,yetanotertag=anything mem_used=123,mem_available=321 yourtimestamp

2) Use Kapacitor to join your measurements altogether.

There, you can do math right in Kapacitor, or simply write the result of the join back into a single measurement and later do your aggregations in plain InfluxQL.



来源:https://stackoverflow.com/questions/53666199/influxdb-mathematics-across-measurements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!