I think I am missing something very basic here and perhaps someone can help me: I would like to exclude stats coming from all non-production servers in graphs on my dashboard. Right now I do it by explicitly filtering by hostname in each query using:
|> filter(fn: (r) => r["host"] == "prod-server-1"
or r["host"] == "prod-server-2"
or ... )
but this looks wrong and I’d like to store the list of production servers (or the whole filter expression) in one place and instead in each query do something like:
so that whenever a production server is added, I need to modify one place only. Unfortunately I haven’t been able to find a way to define a global function or variable, accessible in all queries, but I would be surprised if it wasn’t possible. Can anyone point me in the right direction?
Hello, Disclaimer: I’ve not used Flux or the built in dashboards with Influx 2.0 but…you might be able to do this with global tags
Assuming telegraf is installed on each machine with it’s config, say
And in there you have your main config, create a directory in there called configd (or a name of your choosing) and add a file called tags.conf (again, could be any name you choose).
In that file
Environment = "PRODUCTION"
then you should be able to filter by “Environment” instead of “host” - any new prod servers, add that config file and they will be tagged as production, hopefully showing with your query without needing to add a load “or” statements.
You could set the global tags in your main config, but if this config is shared between prod and dev then every server would just be tagged as prod
I’m assuming telegraf works the same way as before though, with the config files stored on each machine. If that’s not the case then I’m not sure.
EDIT: Just in case it doesn’t pick up the config, if you’re running this as a windows service you might need to update your service definition to include the --config-directory parameter and pass the path to “configd” (don’t leave a trailing / or specify any particular file)
If you’re on Linux, I think this is set at installation. the paths would be /etc/telegraf/config.conf and /etc/telegraf/telegraf.d/ (may vary on different distros)
Restart the service after adding the additional config parameters
Thanks, I think I can use it as a workaround for now
Although, I still think that there has to be a way to do it inside influxdata somehow…
No worries hope it helps.
I’m not sure how you could do it within influx, you’d need a way to tell which was dev/prod which you’d be getting from your metrics. we’re using the older TICK stack. We use tags like that to filter our queries in Grafana to show info from specific system types