Grafana Legend格式:9100删除

问题描述 投票:5回答:2

我的指标结束时出现“:9100”。我在公司使用prometheus数据源,无法更改。有没有人想出如何删除这个?我想的可能是模板或正则表达式,但我还没有成功。

组态:

图例格式= {{hostname}}

结果= myhostname.mydomain.com:9100

grafana prometheus grafana-templating
2个回答
7
投票

据我所知,目前无法格式化Grafana中的图例(有一个开放的PR),但是当你使用Prometheus时,你可以使用它的label_replace()函数,例如:

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

这应该给你:

Legend Format = {{short_hostname}}

Result = myhostname.mydomain.com

See the docs here.


1
投票

我假设您在Prometheus配置文件中静态提及目标如下:

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

在这种情况下,如果您在grafana中看到{{instance_name}},它将为您提供与目标名称['localhost:9100']相同的内容。这是因为它使用static_configs来为您的指标提供标签。

要从标签中删除:9100,您可以使用服务发现来识别目标。

例如:ec2_sd_config,其中标签将从AWS EC2仪表板中提到的标签中获取,file_sd_config您可以在其中提供json或yaml格式的目标及其标签等。

有关详细信息,请参阅link

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.