blob: cfbaec30908b5f3d7d266aa1a477860e2b294753 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
from __future__ import absolute_import
from kafka.metrics.stats.sampled_stat import AbstractSampledStat
class Avg(AbstractSampledStat):
"""
An AbstractSampledStat that maintains a simple average over its samples.
"""
def __init__(self):
super(Avg, self).__init__(0.0)
def update(self, sample, config, value, now):
sample.value += value
def combine(self, samples, config, now):
total_sum = 0
total_count = 0
for sample in samples:
total_sum += sample.value
total_count += sample.event_count
if not total_count:
return 0
return float(total_sum) / total_count
|