Grafana dashboard count is mismatching in CPU, memory, disk utilization

We are using Grafana OSS 12.1.1, Influx DB.2.7.9 in Oracle linux 8.10

Installed telegraf 1.36.4 in 156 Windows 11 laptops.

In the online its show 145 are online but in the below CPU, Memory and Disk utilization the count is mismatched. We need to rectify the issue

please share the queries behind those visuals.

Total Laptops: import “influxdata/influxdb/schema”

schema.tagValues(

bucket: “telegraf”,

tag: “host”,

start: -90d

)

|> group()

|> count(column: “_value”)

Laptops Online: import “influxdata/influxdb/schema”

schema.tagValues(

bucket: “telegraf”,

tag: “host”,

start: -5m

)

|> distinct()

|> count()

Laptops Offline: import “influxdata/influxdb/schema”

// :one: Get ONLINE hosts in last 5 minutes as array

onlineHosts = schema.tagValues(

bucket: "telegraf",

tag: "host",

start: -5m

)

|> findColumn(fn: (key) => true, column: “_value”)

// :two: Get TOTAL hosts (last 90 days) and filter offline

schema.tagValues(

bucket: "telegraf",

tag: "host",

start: -90d

)

|> filter(fn: (r) => not contains(value: r._value, set: onlineHosts))

|> distinct()

|> count()

Laptop Battery: from(bucket: “telegraf”)

|> range(start: v.timeRangeStart, stop: v.timeRangeStop)

|> filter(fn: (r) =>

  r.\_measurement == "windows_battery" and

  r.\_field == "condition_grade_code"

)

|> last()

// Map numeric code to readable status

|> map(fn: (r) => ({

  r with status:

    if r.\_value == 2 then "Good"

    else if r.\_value == 1 then "Fair"

    else "Poor"

}))

// Group by status and count laptops

|> group(columns: [“status”])

|> count()

// IMPORTANT: force one series per status

|> map(fn: (r) => ({

  \_measurement: "battery_summary",

  \_field: r.status,

  \_value: float(v: r.\_value)

}))

|> group(columns: [“_field”])

CPU: from(bucket: “telegraf”)

|> range(start: -15m)

|> filter(fn: (r) =>

r.\_measurement == "cpu" and

r.\_field == "usage_system" and

r.cpu == "cpu-total"

)

|> group(columns: [“host”])

|> last()

|> map(fn: (r) => ({

  r with

  usage_category:

    if r.\_value <= 10.0 then "0-10%"

    else if r.\_value <= 20.0 then "11-20%"

    else if r.\_value <= 30.0 then "21-30%"

    else if r.\_value <= 40.0 then "31-40%"

    else if r.\_value <= 50.0 then "41-50%"

    else if r.\_value <= 60.0 then "51-60%"

    else if r.\_value <= 70.0 then "61-70%"

    else if r.\_value <= 80.0 then "71-80%"

    else if r.\_value <= 90.0 then "81-90%"

    else "91-100%"

}))

|> group(columns: [“usage_category”])

|> count()

Memory: from(bucket: “telegraf”)

|> range(start: v.timeRangeStart, stop: v.timeRangeStop)

|> filter(fn: (r) =>

  r.\_measurement == "mem" and

  r.\_field == "used_percent"

)

|> group(columns: [“host”])

|> last() // latest value per host

|> map(fn: (r) => ({

    r with band:

      if r.\_value <= 20.0 then "0–20%"

      else if r.\_value <= 40.0 then "21–40%"

      else if r.\_value <= 60.0 then "41–60%"

      else if r.\_value <= 80.0 then "61–80%"

      else "81–100%"

}))

|> group(columns: [“band”])

|> count(column: “_value”) // count laptops in band

|> rename(columns: {_value: “laptops”})

|> keep(columns: [“band”, “laptops”])

Disk: data =

from(bucket: “telegraf”)

|> range(start: -1h)

|> filter(fn: (r) => r._measurement == “disk”)

|> filter(fn: (r) => r._field == “used_percent”)

|> filter(fn: (r) => r.fstype == “NTFS”)

|> filter(fn: (r) => r.device =~ /C:|D:/)

|> group(columns: [“host”])

|> last()

|> keep(columns: [“host”, “_value”])

bands =

data

|> map(fn: (r) => ({

  r with band:

    if r.\_value <= 20.0 then "0–20%"

    else if r.\_value <= 40.0 then "21–40%"

    else if r.\_value <= 60.0 then "41–60%"

    else if r.\_value <= 80.0 then "61–80%"

    else "81–100%"

}))

bands

|> keep(columns: [“host”,“band”])

|> group(columns: [“band”])

|> count(column: “host”)

|> rename(columns: {host: “laptops”})

|> keep(columns: [“band”,“laptops”])

Any suggestions or solutions on the Grafana mismatcing count