metrics.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import absolute_import
  2. import logging
  3. log = logging.getLogger(__name__)
  4. # TODO: Rename this to AbstractMetrics
  5. class Metrics(object):
  6. """ Base class for metrics
  7. Args:
  8. counter (:class:`hystrix.rolling_number.RollingNumber`): Used to
  9. increment or set values over time.
  10. """
  11. def __init__(self, counter):
  12. self.counter = counter
  13. def cumulative_count(self, event):
  14. """ Cumulative count
  15. Get the **cumulative** count since the start of the application for the
  16. given :class:`RollingNumberEvent`.
  17. Args:
  18. event (:class:`RollingNumberEvent`): The Event to retrieve a
  19. **sum** for.
  20. Returns:
  21. long: Returns the long cumulative count.
  22. """
  23. return self.counter.cumulative_sum(event)
  24. def rolling_count(self, event):
  25. """ **Rolling** count
  26. Get the rolling count for the given:class:`RollingNumberEvent`.
  27. Args:
  28. event (:class:`RollingNumberEvent`): The Event to retrieve a
  29. **sum** for.
  30. Returns:
  31. long: Returns the long cumulative count.
  32. """
  33. return self.counter.rolling_sum(event)