Import "influxdata/influxdb/schema" Help

import "influxdata/influxdb/schema"

schema.tagValues(
  bucket: "my-bucket",
  tag: "host",
)

Is there a way to filter the above query by hostname? such as “servername1”, “Servername2”
I cant seem to find anything on the site regarding this

Any help appreciated

Hello @ThePeltonian,
I’m a little confused by your question.
The schema.tagValues() function returns a list of tag values from a certain bucket.
If you want to query your data and filter for a specific hostname you can simply:

from(bucket: "mybucket")
|> range(start:-5m)
|> filter( fn: (r) => r.host == "servername1"

Can you please provide some context to your question so I can better understand and help you?

Hi @Anaisdg,

Sorry for the late reply, I have setup a variable of servers within Grafana called Host
Server1, Server2, Server3
This also contains an option for “All”

As Flux cant seem to handle the comma separated value as it stands I am using the /${Host:pipe}/

Query created to call the data

from(bucket: “telegraf”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: ® => r[“host”] =~ /${Host:pipe}/)
|> filter(fn: ® => r[“objectname”] == “Processor”)
|> filter(fn: ® => r["_field"] == “Percent_Processor_Time”)
|> filter(fn: ® => r[“instance”] == “_Total”)
|> filter(fn: ® => r["_measurement"] == “win_cpu”)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: “mean”)

The issue I have is that I get the following error message and dont know why,

“regex parse error: ${Host:pipe} error: repetition quantifier expects a valid decimal(1)”

Can anyone point me in the right direction please?

Hello @ThePeltonian ,
Yes to filter for multiple hosts you would have to:
|> filter( fn: (r) => r.host == "servername1" and r.host == "servername2 and ...)
If you want to search for all of your hosts simply emit that filter.

Hello, thanks for coming back,
Its a shame about that as will have to put the list in every panel query, that could be up to 100 servers.
I was rather hoping I could just use a variable list, when running the above query within Grafana it does pull the data back from InfluxDB - but any alerting fires due to the error received.

@ThePeltonian The problem here is that Flux is trying to parse ${Host:pipe} as a regular expression literal. You can’t use string interpolation inside of an regular expression.

To get around this, define a variable outside of your filter() function that interpolates the Host:pipe variable as a string, then converts it to a regexp type using the regexp.compile() function.

import "regexp"

hostRegex = regexp.compile(v: "${Host:pipe}")

from(bucket: “telegraf”)
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r[“host”] =~ hostRegex)
  |> filter(fn: (r) => r[“objectname”] == “Processor”)
  |> filter(fn: (r) => r["_field"] == “Percent_Processor_Time”)
  |> filter(fn: (r) => r[“instance”] == “_Total”)
  |> filter(fn: (r) => r["_measurement"] == “win_cpu”)
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: “mean”)

Hi Scott,

Many thanks for the information much appreciated