max_stat.py 546 B

1234567891011121314151617
  1. from __future__ import absolute_import
  2. from kafka.metrics.stats.sampled_stat import AbstractSampledStat
  3. class Max(AbstractSampledStat):
  4. """An AbstractSampledStat that gives the max over its samples."""
  5. def __init__(self):
  6. super(Max, self).__init__(float('-inf'))
  7. def update(self, sample, config, value, now):
  8. sample.value = max(sample.value, value)
  9. def combine(self, samples, config, now):
  10. if not samples:
  11. return float('-inf')
  12. return float(max(sample.value for sample in samples))