Filter with part of tag name

image

Dears ,
Am using influx + Grafana and trying to collect some data in which i need Filter some feild based on first 3 digit of Name field (srting)

As in the snapshot i need the results starting with name for eg staring with “AJB”. But am not able to filter it . Can someone please help me to achive this

Hello @danishv,
Have you tried using RegEx?
Something like:

from(bucket: "default")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "cpu")
  |> filter(fn: (r) => r._field == /"usage"/)
  |> filter(fn: (r) => r.cpu == "cpu-total") 

Can you please give me example with my query am new to this
This is the query currently am running

SELECT last(“SiteStatus”) as STATE FROM “idirect” WHERE “agent_host” = ‘91.151.164.6’ AND ( SiteStatus = 2 OR SiteStatus = 3) AND time >= now() -1m GROUP BY NodeName

So maybe this? I don’t know what your field key is.

SELECT last(“SiteStatus”) as STATE FROM “idirect” WHERE “agent_host” = ‘91.151.164.6’ AND ( SiteStatus = 2 OR SiteStatus = 3) AND "your_field_key"=~ /AJB/  AND time >= now() -1m GROUP BY NodeName

Also If that doesn’t yield what you want, I suggest playing with you system stats to see how this query works. It might help you gain a better understanding of InfluxQL.

SELECT mean("usage_system") AS "mean_usage_system", mean("usage_steal") AS "mean_usage_steal" FROM "telegraf"."autogen"."cpu" WHERE time > :dashboardTime: AND "cpu"=~ /cpu/ GROUP BY time(:interval:) FILL(null)

Dear Anaisdg,
My field key “your_field_key” is NodeName itself. Since we already grouped with NodeName it showing all the results .

I tried the query you provided its not returning any data

Query used:
SELECT last(“SiteStatus”) as STATE FROM “idirect” WHERE “agent_host” = ‘91.151.164.6’ AND ( SiteStatus = 2 OR SiteStatus = 3) AND “NodeName” =~ /AJB/ AND time >= now() -1m GROUP BY NodeName

Dear Anaisdg,

Since am using Grafana i tried to add my tag value “NodeName” as variable and tried below query but still am not able to fetch any data
Query Used:
SELECT last(“SiteStatus”) FROM “idirect” WHERE (“agent_host” = ‘91.151.164.6’ AND “NodeName” =~ /^cust/) AND time >= now() -1m GROUP BY “NodeName”

Below is variable used

can you please help me to figure out what the issue ?

@danishv,
I’m not a grafana user, so I’m not sure how helpful I can be on that end. However, if you are able to share some data with me in line protocol, then I can create the query you’re looking for. Have you tried the similar system stats query yet?/been able to understand how that works?

This was correct, I missed one expression, THANK YOU VERY MUCH

1 Like