Count Metric_A by distinct values of Metric_A

Hi all,

Using the Meraki API, I am trying to get the status of my Meraki APs and Switches. I’ve made a python script to go collect the data and upload it to InfluxDB. in said script, I am converting “online”, “alerting”, “offline”, “dormant” to 1, 2, 3, 4 respectively. Data is well received into InfluxDB. No issues so far

Now here’s the issue.
In Grafana, I’d like a bar/pie graph of how many devices have given a responce of 1, 2, 3, 4 individually. This is what im looking to have

I cannot for the life of me figure out a way of making said graph exist in Grafana.
Any help would be greatly appreciated.

welcome

which version of influx are you using?

I am using InfluxDB version 2.7.1

this might help you with grouping and all.

Try it out and let us know if you get stuck

Also please provide sample data as inline csv (Not a file) into this forum

bucket,measurement,model,status
meraki,network,MR33,1

etc, just type out in the forum itself. that way it helps us help you by having your data in our local influxdb instance

I’ve just tried using this but it isn’t functioning as I’d like. All i get is a single _value of 4.

from(bucket: "Testing Bucket")
    |> range(start: -24h)
    |> filter(fn: (r) => r._measurement == "Meraki_Devices002" and r.Model == "MR33" and r._field == "Status")
    |> group(columns: ["Status"])
    |> sort()
    |> yield()

I feel the issue is trying to sort/group _value instead of _field or any other tag

in that case please provide some sample data

Try adding a Rows to Fields or Labels to Fields transformation and see if that gives you multiple categories on your pie chart.

what is the best way to provide sample data?

csv or line protocol
–csv

measuremeant,fieldname,value,timestamp
foo,boo,32.3,1689675145000000000

–line protocol

sensors,tag1=1 temptype="ambient",celsius=-17.22,fahrenheit=1i 1689675205000000000
sensors,tag1=2 temptype="ambient",celsius=-16.67,fahrenheit=2i 1689675145000000000
sensors,tag1=3 temptype="ambient",celsius=-16.11,fahrenheit=3i 1689675085000000000
sensors,tag1=4 temptype="ambient",celsius=-15.56,fahrenheit=4i 1689675025000000000