Filtering N/A values (I really don't need them :) )

Hi everyone,

I’m working on a switch overview dashboard using snmp for getting desired metrics using a dashboard template from grafana switch overview

There are curerntly metrics from 8 switches with varying port numbers. In order to leave all the VLANs out I filtered by using a regex on the total number of port in the port variable:

The variable:

import "influxdata/influxdb/schema"
schema.tagValues(
    bucket: "tigstack",
    tag: "ifIndex"
)

// and the attached regex:
(5[0-4]|[1-4][0-9]|0?[1-9])

The following query takes in a selected switch and iterates over all the ports in order to return the status:

Summary
from(bucket: "tigstack")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) =>
    r._measurement == "InterfaceTable" and
    r.agent_host == "${ip}" and
    r.ifIndex == "${port}" and
    r._field == "ifOperStatus"
   )
  |> aggregateWindow(every:1m, fn: last , createEmpty: false)
  |> yield(name: "last")

But here’s the crux:

The values for non-existent ports are returned with null which is then displayed as N/A (which is intended), but for this and other specific queries I need to eliminate this representation. More on that in the Summary below.

Summary

This is another representation using the ifLastChange field:

This is the associated query:

from(bucket: "tigstack")
  |> range(start:-1m)
  |> filter(fn: (r) =>
    r._measurement == "InterfaceTable" and
    r.agent_host == "${ip}" and
    r.ifIndex == "${port}" and
    r._field == "ifLastChange")
  |> aggregateWindow(every:1h, fn: last , createEmpty: false)
  |> yield(name: "last")

And the same for the field ifSpeed:

from(bucket: "tigstack")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "InterfaceTable")
  |> filter(fn: (r) => r["_field"] == "ifSpeed")
  |> filter(fn: (r) => r["ifIndex"] == "${port}")
  |> filter(fn: (r) => r["agent_host"] == "${ip}")
  |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Is there a way to selectively not show the null values in my queries for the respective fields?

take care
mateo

Grafana draws number of panels based on values of ip (or port) variable, so it doesn’t care about further queries…

may be you consider using one Stat panel in Grafana instead of repeating ones:

repeat

and remove filter by ip (or port) in your query

Or change N/A in Value mappings to space for example, so as these cells would not be so bright:
N/A

Are the non-existent ports actually in the query results or are ports 1-52 manually configured to display in Grafana? If they’re in the query results, my first thought would be to just filter out rows with null values using the exists operator.

// ...
  |> filter(fn: (r) =>
    r._measurement == "InterfaceTable" and
    r.agent_host == "${ip}" and
    r.ifIndex == "${port}" and
    r._field == "ifOperStatus" and
    exists r._value
   )

But is suspect the number of ports listed is on the Grafana side, not the query side.

It is defined by values of this variable:

import "influxdata/influxdb/schema"
schema.tagValues(
    bucket: "tigstack",
    tag: "ifIndex"
)

And then for each value Grafana creates a panel, regardless if it would have data returned by query with filter on port or no…

@scott
Yes they are manually configured to be shown as I tried to trim all ports iterated in the ${ports} variable by all VLANs and I filter the variable itself by the regex: ‘(5[0-4]|[1-4][0-9]|0?[1-9])’

I simply have no other clue on how to make this dashboard work for all our switches that have varying number of ports.

@ebabeshko
I looked for the schema in JSON view of query inspector but couldn’t find it. Is there a way in order to stop the panel creation for returned null values?