Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Sampling with Prometheus and panel display with Grafana were basic operations at the system monitoring level, and the flexibility of variables was common in the panel configuration of Grafana to display data dials of different dimensions

Now there is such a scenario, an application has multiple machines, we set a variable instance to represent the specific instance IP, support to select the monitoring of different machines by IP, how to operate?

1. Configure variables

To implement the case above, the first step is to set a variable

Note the variable configuration above. Label_values (instance) takes all the instance IP addresses. However, in general, we need to differentiate between application dimensions. For now, I only want to see information about the prometheus-Example application

The test variable configuration can be as follows

label_values(http_server_requests_seconds_count{application="prometheus-example"}, instance)
Copy the code

Note that http_server_requestS_SECONds_count is a reported metric name. Select an actual metric name and configure the whole market

2. Include all Configuration

This completes a basic variable usage configuration, but there is a question: what if I want to check the monitoring of all the machines in this application?

To support the use of all, we need to change our metrics expressions to regular instead of exact matching

(rate(http_server_requests_seconds_count{instance=~"$ip"}[1m]))
Copy the code

3. Summary

The variable configuration of Grafana is used to realize the condition screening of the large market, where the key point of variable configuration is

Label_values (metric_name{tagName=tagValue}, variable name)Copy the code

Secondly, in the metric configuration of the market, the key point for include All support is the use of PROMQL

  • =: Selects a label identical to the supplied string.
  • ! =: Selects a label that is different from the supplied string.
  • = ~: Selects the label that the regular expression matches the supplied string (or substring).
  • ! ~: Selects labels that the regular expression does not match the supplied string (or substring).

II. The other

1. A gray Blog:liuyueyi.github.io/hexblog

A gray personal blog, recording all the study and work in the blog, welcome everyone to go to stroll

2. Statement

As far as the letter is not as good, the above content is purely one’s opinion, due to the limited personal ability, it is inevitable that there are omissions and mistakes, if you find bugs or have better suggestions, welcome criticism and correction, don’t hesitate to appreciate

  • Micro Blog address: Small Gray Blog
  • QQ: a gray /3302797840
  • Wechat official account: One Grey Blog