Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the Multidimensional data Model of Prometheus

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to understand the multidimensional data model of Prometheus. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

We discuss the core of Prometheus, the multidimensional data model. Let's first look at an example.

For example, to monitor the memory usage of the container webapp1, the most traditional and typical method is to define a metric container_memory_usage_bytes_webapp1 to record the memory usage data of the webapp1. If you take a sample every 1 minute, there will be a record similar to the following in the database.

Well, now that the requirements have changed a bit, we need to know the memory usage of all webapp containers. If we still use the previous method, we will have to add new indicators such as container_memory_usage_bytes_webapp2, container_memory_usage_bytes_webapp3.

More advanced monitoring solutions such as Graphite use a more elegant hierarchical data model. To meet the above requirements, Graphite defines indicators container.memory_usage_bytes.webapp1, container.memory_usage_bytes.webapp2, container.memory_usage_bytes.webapp3...

Then you can use container.memory_usage_bytes.webapp* to get all the memory usage data of webapp.

In addition, Graphite also supports functions such as sum () to calculate and process metrics. For example, sum (container.memory_usage_bytes.webapp*) can get the total amount of memory occupied by all webapp containers.

So far the problem has been handled very well. However, customers always put forward more requirements: now it is necessary to count memory usage not only by container name, but also by image, or to compare the memory usage of a certain group of containers in production and test environments.

Of course, you can say: as long as you define more indicators, you can meet these needs. Such as container.memory_usage_bytes.image1.webapp1, container.memory_usage_bytes.webapp1.prod and so on.

But the problem is that we can't predict in advance what kind of questions customers are going to answer with these data, so we can't define all the indicators in advance.

Let's take a look at Prometheus's solution.

Prometheus only needs to define a global metric container_memory_usage_bytes, and then add different dimensional data to meet different business needs.

For example, for the three pieces of sampled data in the previous webapp1, the conversion to Prometheus multidimensional data will be:

The next three columns container_name, image, and env are the three dimensions of the data. Imagine that if the containers of different env (prod, test, dev) and different image (mycom/webapp:1.2, mycom/webapp:1.3) have these three dimensional information marked in their memory usage data, they will be able to meet many business needs, such as:

Calculate the average memory usage of webapp2: avg (container_memory_usage_bytes {container_name= "webapp2"})

Calculate the total memory usage of all containers running mycom/webapp:1.3 images: sum (container_memory_usage_bytes {image= "mycom/webapp:1.3"})

Statistics on the total memory usage of webapp containers in different running environments: sum (container_memory_usage_bytes {container_name=~ "webapp"}) by (env)

Here are only a few examples, but they already illustrate the advantages of the Prometheus data model:

Explain the data through the dimension, add more business information, and then meet the needs of different businesses. At the same time, dimensions can be added dynamically, such as adding a user dimension to the data to count the container memory usage by user.

Prometheus's rich query language can flexibly and fully mine the value of data. Avg, sum, and by in the previous example are only a small part of the query language, which has shown us the powerful ability of Prometheus to fragment and aggregate multidimensional data.

This is the end of the multidimensional data model on how to understand Prometheus. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report