首页 > 解决方案 > rate函数如何计算结果?

问题描述

我在 rate 上看到了这个问题 我是否正确理解 Prometheus 的 rate vs increase 函数?

second   counter_value    increase calculated by hand(call it ICH from now)
1             1                    1
2             3                    2
3             6                    3
4             7                    1
5            10                    3
6            14                    4
7            17                    3
8            21                    4
9            25                    4
10           30                    5

我不明白的结果

rate(counter[2s]): will get the average from the increment in 2 sec and distribute it among the seconds
So in the first 2 second we got an increment of total 3 which means the average is 1.5/sec. final result:

second result
1       1,5
2       1,5
3        2
4        2
5       3,5
6       3,5
7       3,5
8       3,5
9       4,5
10      4,5


rate(counter[5s]): will get the average from the increment in 5 sec and distribute it among the seconds
The same as for [2s] but we calculate the average from total increment of 5sec. final result:

second result
1        2
2        2
3        2
4        2
5        2
6        4
7        4
8        4
9        4

你能解释一下逻辑吗?

标签: prometheus

解决方案


我认为问题中的 OP 只是计算错误。该问题的唯一答案非常清楚和详细地解释了它,并提供了要使用的确切公式。还有一个例子(在评论中):

如果t1是 1 并且t5是 5;处的值为t11,处的值为t510(如上),(v5 - v1) / (t5 - t1)则为(10 - 1) / (5 - 1),即2.25

这显然与rate(counter[5s])第 5 秒的原始示例相矛盾,即 2。另请注意,答案中说第 1 秒的 ICH 应为 0。

我现在将尝试手动计算:

rate(counter[5s]): (v_y - v_x) / (t_y - t_x)

second result     calculation
1       N/A     (1 - 1) / (1 - 1)
2        2      (3 - 1) / (2 - 1)
3       2.5     (6 - 1) / (3 - 1)
4        2      (7 - 1) / (4 - 1)
5       2.25    (10 - 1) / (5 - 1)
6       2.75    (14 - 3) / (6 - 2)
7       2.75    (17 - 6) / (7 - 3)
8       3.5     (21 - 7) / (8 - 4)
9       3.75    (25 - 10) / (9 - 5)
10      4       (30 - 14) / (10 - 6)

推荐阅读