Grafana Legend format :9100 removal

Viewed 24789

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

3 Answers

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.

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!

Related