Working with PromQL

PromQL has three data types: instant vectors, range vectors, and scalars. An instant vector is a time series of data samples; a range vector is a set of time series containing data within a certain time range; and a scalar is a numeric floating value. Metrics stored inside Prometheus are identified with a metric name and labels, and we can find the name of any collected metric with the drop-down list next to the Execute button in the expression browser. If we query Prometheus using a metric name, say http_requests_total, we'll get lots of results, as instant vectors often have the same name but with different labels. Likewise, we can also query a particular set of labels using the {} syntax. For example, the query {code="400",method="get"} means that we want any metric that has the labels code, method equal to 400, and get. Combining names and labels in a query is also valid, such as http_requests_total{code="400",method="get"}. PromQL grants us the ability to inspect our applications or systems based on lots of different parameters, so long as the related metrics are collected.

In addition to the basic queries just mentioned, PromQL has many other functionalities. For example, we can query labels with regex and logical operators, joining and aggregating metrics with functions, and even performing operations between different metrics. For instance, the following expression gives us the total memory consumed by a kube-dns pod in the kube-system namespace:

sum(container_memory_usage_bytes{namespace="kube-system", pod_name=~"kube-dns-([^-]+)-.*"} ) / 1048576

More detailed documentation can be found at the official Prometheus site (https://prometheus.io/docs/querying/basics/). This will help you to unleash the power of Prometheus.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset