简体   繁体   中英

How does rate function calculate the result?

I saw this question on rate Do I understand Prometheus's rate vs increase functions correctly?

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

I didn't understand the result of

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

and


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

Could you explain me please the logic ?

I think that OP in the question has simply calculated it incorrectly. The only answer to that question explains it very clearly and into detail, providing the exact formula to use. Also with an example (in comments):

if t1 is 1 and t5 is 5; and the value at t1 is 1 and the value at t5 is 10 (as above) then (v5 - v1) / (t5 - t1) is (10 - 1) / (5 - 1) , ie 2.25

Which clearly contradicts the rate(counter[5s]) from the original example at 5th second which says 2. Also note that in the answer says the ICH for sec 1 should be 0.

I will now try to calculate it by hand:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM