Grafana Legend format :9100 removal
Asked Answered
B

3

25

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

Benedictbenedicta answered 14/11, 2017 at 19:9 Comment(0)
A
44

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

Apathy answered 28/2, 2018 at 20:42 Comment(2)
Where would I type this? I tried in the Legend Format edit box, and I tried defining a variable. I want to do this too, but I can't figure out from your comment how. Thanks.Taciturn
I figured out the answer to my above question . The label_replace() function wraps the original PromQL query, which is referred to as "my_vector" here. This example translates the "hostname" variable and creates a new one called "short_hostname". Then in the Legend Format, you can specify "{{short_hostname}}" to get the translated value, without the ":9100". Thanks!Taciturn
S
11

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.

Stoker answered 12/7, 2021 at 7:30 Comment(0)
L
0

I presume you are statically mentioning targets in the Prometheus config file as follows:

- job_name: "node_exporter"
  static_configs:
    - targets: ['localhost:9100']

In that case, if you see the {{instance_name}} in grafana, it will give you the same as your target name ['localhost:9100']. This is because it uses the static_configs to avail labels for your metrics.

In order to remove the :9100 from the labels, you can use service discovery to recognize targets.

For example: ec2_sd_config where the labels will be availed from labels mentioned in AWS EC2 dashboard, file_sd_config where you can provide the targets and their labels in json or yaml format, etc.

Please refer to the link for detailed information.

Hope this helps!

Lagas answered 15/11, 2017 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.