gpt4 book ai didi

Prometheus 如何处理服务器上的计数器

转载 作者:行者123 更新时间:2023-12-04 22:43:35 25 4
gpt4 key购买 nike

我有文章,对于每篇我想阅读的文章

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

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

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

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



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

这是redis重启后的计数器图像:
enter image description here

最佳答案

您通常不想以您在示例中的方式查看计数器的总数,因为一旦您实际尝试以分析方式使用它,它就没有太大意义。
这个想法是你想知道一段时间内的增长。例如,您想知道过去 7 天、本月至今、过去 30 天等的文章浏览总量吗?
This answerthis article很好地解释了所有这些,但这里有一些例子。出于演示目的,我使用了一个名为 walks_started_total 的计数器。 .
问题
查询:`walks_started_total`
enter image description here
解决方案1
查看上周的总数:`increase(walks_started_total[1w])`
enter image description here
解决方案2
超过 1 分钟:`increase(walks_started_total[1m])`
enter image description here

关于Prometheus 如何处理服务器上的计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37548412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com