Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grafana Legend format :9100 removal

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

like image 444
user3149615 Avatar asked Nov 14 '17 19:11

user3149615


2 Answers

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

like image 63
zsolt Avatar answered Nov 10 '22 12:11

zsolt


In Grafana 8.0, there is Transform menu that can be used to remove text. I hope it is still relevant to this question.

On Dashboard, select the panel > Edit. There are 3 tabs below chart, one of them is Transform. Select Transform > Add Transformation > Rename by Regex, fill the form with these values:

  • Match: ":9100" (without quotes)
  • Replace: keep it empty

Please refer to the link for detailed information.

like image 29
opris Avatar answered Nov 10 '22 13:11

opris