Prometheus在Grafana的仪表盘配置Json

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Prometheus在Grafana的仪表盘配置Json相关的知识,希望对你有一定的参考价值。

参考技术A
"annotations":
"list": [

"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"

]
,
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"hideControls": false,
"id": 2,
"links": [],
"refresh": false,
"rows": [

"collapse": false,
"height": 250,
"panels": [

"aliasColors": ,
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fill": 1,
"id": 5,
"legend":
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
,
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [

"expr": "instance:node_cpu:avg_rate5m",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": " instance ",
"refId": "A"

],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Node CPU % Utilization Avg 5m",
"tooltip":
"shared": true,
"sort": 0,
"value_type": "individual"
,
"type": "graph",
"xaxis":
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
,
"yaxes": [

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
,

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true

]
,

"aliasColors": ,
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fill": 1,
"id": 6,
"legend":
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
,
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [

"expr": "instance:node_cpu_saturation:load1",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": " instance ",
"refId": "A"

],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Node Load Avg Saturation",
"tooltip":
"shared": true,
"sort": 0,
"value_type": "individual"
,
"type": "graph",
"xaxis":
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
,
"yaxes": [

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
,

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true

]

],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Dashboard Row",
"titleSize": "h6"
,

"collapse": false,
"height": 250,
"panels": [

"aliasColors": ,
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fill": 1,
"id": 2,
"legend":
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
,
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [

"expr": "instance:node_memory_usage:percentage",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": " instance ",
"refId": "A"

],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Node Memory % usage",
"tooltip":
"shared": true,
"sort": 0,
"value_type": "individual"
,
"type": "graph",
"xaxis":
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
,
"yaxes": [

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
,

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true

]
,

"aliasColors": ,
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"fill": 1,
"id": 4,
"legend":
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
,
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [

"expr": "instance:node_memory_swap_io_bytes:sum_rate",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": " instance ",
"refId": "A"

],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Node Memory Saturation Swap IO",
"tooltip":
"shared": true,
"sort": 0,
"value_type": "individual"
,
"type": "graph",
"xaxis":
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
,
"yaxes": [

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
,

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true

]

],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Dashboard Row",
"titleSize": "h6"
,

"collapse": false,
"height": 250,
"panels": [

"aliasColors": ,
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fill": 1,
"id": 7,
"legend":
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
,
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [

"expr": "instance:root:node_filesystem_usage:percentage",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": " instance ",
"refId": "A"

],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Node % Disk Usage (root /)",
"tooltip":
"shared": true,
"sort": 0,
"value_type": "individual"
,
"type": "graph",
"xaxis":
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
,
"yaxes": [

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
,

"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true

]

],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Dashboard Row",
"titleSize": "h6"

],
"schemaVersion": 14,
"style": "dark",
"tags": [],
"templating":
"list": []
,
"time":
"from": "2018-02-04T01:31:28.369Z",
"to": "2018-02-04T02:40:02.655Z"
,
"timepicker":
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
,
"timezone": "",
"title": "Node Dashboard",
"version": 23

如何为多个 Prometheus 数据源配置 Grafana 仪表板?

【中文标题】如何为多个 Prometheus 数据源配置 Grafana 仪表板?【英文标题】:How to configure a Grafana dashboard for multiple Prometheus datasources? 【发布时间】:2020-11-30 14:22:09 【问题描述】:

我正在尝试为多个 Prometheus 数据源配置 Grafana 仪表板。这两个数据源存在于两个不同的服务器中。

Prometheus 从三个作业中抓取指标,prometheus 本身,用于主机指标的节点导出器,用于 docker 容器指标的顾问。

这是prometheus.yaml 的样子:

global:
 scrape_interval: 5s
scrape_configs:
 - job_name: 'prometheus'
   static_configs:
       - targets: ['localhost:9090']
 - job_name: 'node-exporter'
   static_configs:
     - targets: ['node-exporter:9100']
 - job_name: 'cadvisor'
   static_configs:
     - targets: ['cadvisor:8080']

两台服务器都使用相同的 yaml 配置。

我在 Grafana UI 中创建了两个数据源,它们各自的名称是 PrometheusPrometheus-Certify。第一个数据源是默认数据源。我正在使用 Grafana v7.1.0。

这是我的仪表板对于数据源Prometheus 的样子:

还有其他面板,但显示这些面板就足以解释问题。

如果我单击Host 下拉选项,则可以看到主机cadvisor:8080localhost:9090node-exporter:9100

要求

我想要实现的是为两个数据源配置此仪表板。我可以在datasource 下拉菜单defaultPrometheusPrometheus-Certify 中看到所有选项。当我选择特定数据源时,我希望仪表板向我显示来自特定源的数据。这就是我卡住的地方。

我对此进行了研究,发现我们可以在一个面板中同时显示来自两个不同来源的数据。我在 Grafana 文档中看到了 this 选项,还有这个 thread 实际上让我更接近我想要实现的目标。

所以我遵循这种方法并为面板配置了--Mixed-- 数据源。

它完美无缺地工作,在不同的面板上执行相同的操作,结果如下:

虽然它有效,但这不是我想要做的。这里的问题是:

    我必须对每个面板都执行此操作才能查看来自两个来源的数据。 它同时显示来自两个来源的数据。我只想查看来自所选数据源的数据,而不是两者。 如果我以后添加另一个数据源,我将不得不重新执行所有操作。

我看到很多地方都建议使用[模板和变量][6]。我试了一下,但它什么也没做。

如果更改变量是可行的方法,那么请仅提供针对此问题的建议,因为我已经浏览了该部分并且找不到任何具体的内容。

我希望我能够向你们解释我的问题。我只想查看来自所选数据源的数据而不创建新仪表板。您的帮助将不胜感激。谢谢。

【问题讨论】:

【参考方案1】:

我意识到我导入的仪表板创建了一个变量DS_PROMETHEUS,它的类型是Datasource

此变量保存所选数据源的值。我无法看到来自所选数据源的数据,因为面板查询中的数据源有点硬编码。

如上图所示,预选数据源为Prometheus。将此值更改为 $DS_PROMETHEUS 就可以了。

所以这一切都归结为如何使这个变量作为每个面板中每个查询的数据源?现在的问题是如何运行查询/命令来一次修改多个面板的设置。

在做了一些研究后,我发现了这个thread。它已被归类为功能请求。 Person/People 已经开发了一个tool 来处理这些场景。到目前为止,我还没有使用过这个工具,但我会在使用后更新我的答案。

简单而老式的方法是在仪表板的 JSON 中将 prometheus 替换为 $DS_PROMETHEUS。所以我做到了,瞧!成功了。

【讨论】:

以上是关于Prometheus在Grafana的仪表盘配置Json的主要内容,如果未能解决你的问题,请参考以下文章

关于如何在 Grafana 绘制 Apache Hudi Metrics 仪表盘的教程

如何将Prometheus仪表板添加到Grafana

如何在 grafana 仪表板中隐藏主机?

在 cAdvisor 的刮板中更改 Prometheus 作业标签会破坏 Grafana 仪表板

grafana仪表盘中针对prometheus设置全局变量

stable/prometheus-operator - 添加持久的 grafana 仪表板