InfluxDB Query to get last 1 hour status of Device (Online/Offline)

I am sending some tag values via telegraf as hostname (PC Name), status (Online) to InfluxDB.
If there are 2 PCs running Telegraf to send this data and I stop Telegraf service there is only 1 PC that is writing “PC2”, “Online” to the database now. I want to show the status on Grafana using a query that returns to me the following use case:

If in the last 1 hour, I do not receive any data from PC1, the query returns to me that PC1 is Offline, and as PC2 is still sending me data, I receive Online in the query result. The query result should be group by host. In this case PC1 is not making any entry in the database.

I am using Influx version 1.8.9

Hello @Innovation_Lab,
Welcome!
are you using Flux or InfluxQL to query?

Depending on your Flux version the following might work (It would work in 2.x but I’m not sure that it will work in 1.x).

data =

from(bucket: "example-bucket")
    |> range(start: -1h)
    |> filter(
        fn: (r) => tag == "PC1" or tag == "PC2"
    )
   |> group()
   |> pivot(rowKey: ["_time"], columnKey: ["tag"], valueColumn: "_value")
   |> fill(value: "offline", column: "PC1")
   |> fill(value: "offline", column: "PC2")
    )

@Innovation_Lab,
Alternatively you could look into using the execd processor plugin to add the offline status when you need it.
I’d probbaly suggest this.

Here’s an example
https://www.google.com/search?q=tg+brew+anamoly+influxdb&rlz=1C5CHFA_enUS970US973&oq=&aqs=chrome.4.69i57j46i175i199i512j0i22i30l2j69i59j69i64l3.3620j0j4&sourceid=chrome&ie=UTF-8