Grafana 仪表板变量:如何在度量等于某个值时提取标签值

时间:2021-01-21 05:34:34

标签: prometheus grafana promql grafana-templating grafana-variable

我有一个指标来监控名为 nodejs_microservice_health_status 的微服务的健康状态。

我想创建一个变量 failedmicroservice,它在 service 等于 0 时提取指标的 nodejs_microservice_health_status 标签的值。

PromQL 查询 nodejs_microservice_health_status == bool 0 返回所有等于 0 的项目,但是当我尝试将变量的查询设置为 label_values({nodejs_microservice_health_status == bool 0}, service) 时, enter image description here

我收到以下错误:

enter image description here

有人知道怎么做吗?

1 个答案:

答案 0 :(得分:1)

使用以下值,

查询:

query_result(nodejs_microservice_health_status==0)

正则表达式:

/.*service=\"([^\"]+)\".*/