How to count row in a table?

Hi, I am an absolute beginner with Telegraf and InfluxDB. Thanks in advance for your help.

Here’s my current situation: I have configured Telegraf to return information about processes starting with the name “GAME”.

  UseWildcardsExpansion = true
    ObjectName = "Process"
    Counters = ["% Processor Time", "Handle Count", "Private Bytes", "Thread Count", "Virtual Bytes", "Working Set"]
    Instances = ["GAME*"]
    Measurement = "win_proc"

Currently, I have three processes named respectively: GAME1, GAME2, GAME3.

What I am trying to achieve in the InfluxDB dashboard is to display the value 3, since I have 3 processes running. However, for some reason that I don’t understand, the value returned in the single stat is 5.

Below, I have attached a screenshot of the table returned by this Flux query:

data = 
  from(bucket: "bucketdemo")
    |> range(start: -1m)
    |> filter(fn: (r) => 
        r["_measurement"] == "win_proc" and 
        r["_field"] == "Handle_Count" and
        r["host"] == "HOSTX"

  |> count()

Can someone explain to me where I am going wrong? Thank you!

How often do you fetch data with Telegraf?

my guess is interval = 10s, meaning you will have 5 points in 59s (time filters are closed intervals)

HI @Giovanni_Luisotto,

Indeed, the interval = 10s, I have now changed my query to:

from(bucket: "bucketdemo")
|> range(start: -1m)
|> filter(fn: (r) => 
    r["_measurement"] == "win_proc" and 
    r["_field"] == "Handle_Count"and
    r["instance"] =~ /^GAME/
|> last()
|> count()

Raw data result will be:

While single stat value will be 1.0.

Based on your feedback, am I correct in understanding that both my previous query and the current one only return the number of times data has been queried during the interval?

Could you possibly guide me towards obtaining the information I seek? In this instance, I anticipate a return value of 3, as I observe 3 rows in my raw data table. However, I suspect I may not fully grasp how Flux operates.
Thank you.

You are counting the number of data points in the defined “scope/grouping” (that’s probably not the best definition, but count behaves exactly as it does in any other system/database)

I don’t use flux, so I’m unable to give you an exhaustive solution, but you are looking for the count distinct of a tag, try to look around for that.

To me your current result (1) is correct given that the scope of the row is the single process itself, if you want to put a 3 in there you need to do so in a different query that calculates the total, and then join it (with time as the join key)

Sorry for the delay, at the end up I end up not using that data. Thansk for the help. I will close that thread.