简体   繁体   English

基于变量的多个主机的 Grafana Graph CPU

[英]Grafana Graph CPU for multiple hosts based on variable

I am using GrafanaCloud.我正在使用 GrafanaCloud。 I have a dashboard variable to create a list of nodes:我有一个仪表板变量来创建节点列表:

node -> label_values(agent_hostname)

Then I have my query to graph CPU for the selected hostname:然后我要查询所选主机名的 CPU 图形:

instance:node_cpu_utilisation:rate5m{agent_hostname="$node"}

This works fine for a single host but I would like to be able to have lines for several servers on one graph.这适用于单个主机,但我希望能够在一个图表上为多个服务器提供线。 I have 'Include All' and 'Multi-value' switched on for the variable.我为变量打开了“包含所有”和“多值”。 At the moment, when I choose a second or third server from my nodes variable the graph shows 'No data'.目前,当我从节点变量中选择第二个或第三个服务器时,图表显示“无数据”。 Do I need to amend my variable so that it parses with a pipe (OR) symbol at the end?我是否需要修改我的变量,以便它在末尾使用 pipe (OR) 符号进行解析? And if so how would I do that?如果是这样,我会怎么做?

I still haven't solved this but I managed the following workaround.我仍然没有解决这个问题,但我管理了以下解决方法。 I added the following to the grafana-agent.yaml file so that prometheus would add an environment and role label for each machine:我在grafana-agent.yaml文件中添加了以下内容,以便 prometheus 为每台机器添加环境和角色 label:

  prometheus_remote_write:
    url: {{ prometheus_url }}
    write_relabel_configs:
      - source_labels: [__address__]
        regex: '.*'
        target_label: instance
        replacement: {{ ansible_hostname }}
      - source_labels: [__address__]
        regex: '.*'
        target_label: environment
        replacement: {{ env | default('legacy') }}
      - source_labels: [__address__]
        regex: '.*'
        target_label: role
        replacement: {{ role | default('none') }}

Then in the dashboard variables I added:然后在仪表板变量中我添加了: 仪表板变量

Then in the query for each metric I added the role and environment, for example for load:然后在每个指标的查询中,我添加了角色和环境,例如负载:

node_load15{role="$role", environment="$environment" }

This allows me to show load for several machines on the one graph and also allows me to easily switch between environments and clusters using the variables drop-down at the top.这使我可以在一个图表上显示多台机器的负载,还允许我使用顶部的变量下拉菜单轻松地在环境和集群之间切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM