Toggle navigation
首页
技术
骑行
羽毛球
资讯
联络我
登录
grafana 创建带联动效果的选单
2022-06-16
grafana
prometheus
> 本文主要介绍 grafana 连接 prometheus 创建监控看板,并可以通过建立有联动关系的下拉选单来过滤指标 # 查询变量 当 grafana 接入 prometheus 的时候,可以通过如下 function 来将查询结果转换为 grafana 看板的变量以供过滤: | Name | Description | Used API endpoints | | :-------------------------- | :-------------------------------------------------------------------- | :---------------------------- | | label_names() | Returns a list of label names. | /api/v1/labels | | label_values(label) | Returns a list of label values for the label in every metric. | /api/v1/label/label/values | | label_values(metric, label) | Returns a list of label values for the label in the specified metric. | /api/v1/series | | metrics(metric) | Returns a list of metrics matching the specified metric regex. | /api/v1/label/__name__/values | | query_result(query) | Returns a list of Prometheus query result for the query. | /api/v1/query | 假设现在 prometheus 有如下指标,希望 path 选单的值依赖于 instance 选单的值: | metrics | | :----------------------------------------------------------- | | traefik_seconds_bucket{instance="service-a", path="/path-x"} | | traefik_seconds_bucket{instance="service-a", path="/path-y"} | | traefik_seconds_bucket{instance="service-b", path="/path-x"} | | traefik_seconds_bucket{instance="service-b", path="/path-z"} | 则可以先建立 instance 变量: label_values(traefik_seconds_bucket,instance) 然后建立 path 变量,通过 reference variable,根据已经选择的 instance 的值来筛选 path 的值: label_values(traefik_seconds_bucket{instance="${instance}"}, path) 完成如上两个变量的设置之后,回到看板,就可以让 path 选单的值根据 instance 选单选择的不同值,呈现不同的选项。 # 参考 * [datasources-prometheus](https://grafana.com/docs/grafana/latest/datasources/prometheus/) * [Variable syntax](https://grafana.com/docs/grafana/latest/variables/syntax/)
×
本文为博主原创,如需转载,请注明出处:
http://www.supperxin.com
返回博客列表