The recent graph already gives us a hint on how to get this number: get the current value of the counter and subtract the value it had 5 minutes ago. Orders created within the last 5 minutesĪ number that seems to be more interesting in our example is the number of orders created within a certain period of time (e.g. What matters is, how it increases over time. Lesson learned: The current value of a Counter doesn’t matter. That’s probably not what we want to know in our day to day business. Our counter will increase and increase, and will always contain the total number of orders that were created since the point in time when we first created it. Imagine our shop runs for several days, weeks, months, or even longer. Figure 3 – our counter graph after a few more minutes 5 minutes ago where the graph starts) when we move the mouse pointer over the graph. We can also see which value it had at which point in time (e.g. If we go for a fresh cup of coffee and refresh this query after coming back a few minutes later, we will see that the value has further increased. Figure 2 – graph displaying the instant vector of our counter We can adjust the range that the graph should show (called the graph range) to the last 5 minutes, using the controls above the diagram. The graph shows how our counter increased so far. If we switch to the graph tab, we can see that the result isn’t the single value we saw so far, but a vector of values over time (called instant vector). Refreshing the Prometheus query, we can see that the value increases as expected. Let’s create a new Counter orders.created and register it within our sample ( fixedDelay = 5000 ) public void increaseCounter () It’s a cumulative metric, so it always contains the overall value. ![]() It’s monotonically increasing, so it can only increase, usually one-by-one. the number of orders created in a shop system. What is a Counter?Īccording to the Prometheus documentation, a Counter is a single, monotonically increasing, cumulative metric.Ī single metric means, that a Counter represents a single value, e.g. Having everything in place, we can start our journey and create our own Counter. Using the graph section (at we should also be able to query some default metrics created by spring, e.g. We can verify this by looking at the targets status page (at It should display two targets, Prometheus itself and our spring-boot app, both with state UP. If we use Maven, we have to add the following lines to our pom.xml file. To use the Micrometer Prometheus plugin we just need to add the appropriate dependency to our project. You will find lots of resources on the internet describing how to set up a spring-boot app. As an easy option we can create a simple spring-boot application and use the Micrometer Prometheus plugin to write our counter. To better understand the results of our upcoming queries, it’s a good idea to have a little playground where we can create and increase a counter in a simple and controlled way. In this article, I want you to join me on my way to understand how Counters in Prometheus work and how to query them to get the right information. It took me quite some time to understand what I have to do to get the numbers and graphs that I wanted. It turned out that I had underestimated the complexity of Prometheus Counters. ![]() I assumed that those are the simplest metrics available and it should be easy to extract some meaningful numbers and graphs out of them. I focussed on a couple of already existing counter metrics. I recently had to setup a few monitoring dashboards in Grafana based on a Prometheus data source.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |