Prometheus 如何处理服务器上的计数器 [英] Prometheus how to handle counters on server

查看:39
本文介绍了Prometheus 如何处理服务器上的计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文章,每篇文章我想阅读的数量

# TYPE news_read_counter2 计数器news_read_counter2{id="2000"} 168

现在服务器上的计数器保存在 redis\memcached 中,因此它们可以不时重置,因此一段时间后 redis 机器重新启动并且服务器没有最后的 news_read_counter 编号,如果我再次从零开始

# TYPE news_read_counter2 计数器news_read_counter2{id="2000"} 2

现在查看 news_read_counter2{id="2000"} 图表,我看到计数器下降到 2 而文档说:

<块引用>

计数器是表示单个数字的累积度量价值只会上升.

所以现在要跟踪 news_read_counter 我需要将数据保存到 db 中,然后我回到开始区,在那里我需要使用 mysql 来处理我的数据

这里是redis重启后的计数器图像:

解决方案

您通常不希望以您在示例中的方式查看计数器的总数,因为一旦您真正尝试这样做,它就没有太大意义分析性地使用它.

这个想法是你想知道一段时间内的增长.例如,您是否想知道过去 7 天、本月至今、过去 30 天等的文章浏览总量.

解决方案 1

查看上周的总数:`increase(walks_started_total[1w])`

解决方案 2

超过 1 分钟:`increase(walks_started_total[1m])`

I have articles and for each article I want to have read count

# TYPE news_read_counter2 Counter
news_read_counter2{id="2000"} 168

now the counters on the servers are saved in redis\memcached so they can get reset from time to time so after a while the redis machine is restart and the server dont have the last news_read_counter number and if I start from zero again

# TYPE news_read_counter2 Counter
news_read_counter2{id="2000"} 2

now looking at the news_read_counter2{id="2000"} graph I see that the counter is getting dropped to 2 while the docs says:

A counter is a cumulative metric that represents a single numerical value that only ever goes up.

so now to keep track of the news_read_counter I need to save the data into db and I back to the start zone where I need to use mysql to handle my data

here an Image of counter after redis got restart:

解决方案

You generally don't want to look at the total of a counter the way that you are in your example, because it's not very meaningful once you actually try to use it analytically.

The idea is that you want to know increases over a period of time. For example, do you want to know the total amount of article views for the last 7 days, for this month so far, for the last 30 days, etc.

This answer and this article do an excellent job of explaining all this, but here are some examples. For demonstration purposes I use a counter called walks_started_total.

The problem

Query: `walks_started_total`

Solution 1

Seeing the total for the last week: `increase(walks_started_total[1w])`

Solution 2

Over a 1 minute period: `increase(walks_started_total[1m])`

这篇关于Prometheus 如何处理服务器上的计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆