InfluxDB sum all latest value based on tag

Viewed 548

I have a database with some DHCP metrics

Tags and examples:

  • Name, e.g. Server network
  • ScopeId, e.g. 10.10.10.0
  • Free, e.g. 1
  • InUse, e.g. 99
  • Reserved, e.g. 10
  • Percentage in use, e.g. 99%

The ScopeId is unique and the Name is not unique.

I'm trying to achieve some panels in Grafana that displays statistics for our DHCP metrics but run into a problem when scope names are not unique.

Example:

I want to know how many IP addresses are free in this scope based on a name. My query looks like this:

SELECT last(Free) FROM "Scope_Stats" WHERE ("Name" = 'Server network') group by ScopeId

which returns:

name: Scope_Stats
tags: ScopeId=10.10.10.0
time                Free
----                ----
1584045598125616200 356

name: Scope_Stats
tags: ScopeId=10.10.20.0
time                Free
----                ----
1584045579287037900 219

How can I sum up all of the Free values into one? I can't figure it out since I only want the last value for each of the ScopeId's.

Example 2:

I don't have any code, but how would I structure a query to get the sum of Free, InUse and Reserved addresses to get total addresses?

0 Answers
Related