Grafana Legend format :9100 removal

user3149615 picture user3149615 · Nov 14, 2017 · Viewed 13.1k times · Source

I have ":9100" showing up at the end of my metrics. I am using a prometheus datasource with my company and can't change it. Has anyone figured out how to remove this? I was thinking maybe templates or regex but I haven't been successful yet.

Configuration:

Legend Format = {{hostname}}

Result = myhostname.mydomain.com:9100

Answer

zsolt picture zsolt · Feb 28, 2018

As far as I know, currently it is not possible to format the legend in Grafana (there is an open PR for it), however as you are using Prometheus, you can use its label_replace() function, eg.:

label_replace(my_vector, "short_hostname", "$1", "hostname", "(.*):.*")

This should give you:

Legend Format = {{short_hostname}}

Result = myhostname.mydomain.com

See the docs here - label_replace