Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions kafka/metrics/compound_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def stats(self):


class NamedMeasurable(object):
__slots__ = ('_name', '_stat')

def __init__(self, metric_name, measurable_stat):
self._name = metric_name
self._stat = measurable_stat
Expand Down
4 changes: 3 additions & 1 deletion kafka/metrics/kafka_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class KafkaMetric(object):
__slots__ = ('_metric_name', '_measurable', '_config')

# NOTE java constructor takes a lock instance
def __init__(self, metric_name, measurable, config):
if not metric_name:
Expand Down Expand Up @@ -33,4 +35,4 @@ def config(self, config):
def value(self, time_ms=None):
if time_ms is None:
time_ms = time.time() * 1000
return self.measurable.measure(self.config, time_ms)
return self._measurable.measure(self._config, time_ms)
2 changes: 2 additions & 0 deletions kafka/metrics/metric_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

class MetricConfig(object):
"""Configuration values for metrics"""
__slots__ = ('quota', '_samples', 'event_window', 'time_window_ms', 'tags')

def __init__(self, quota=None, samples=2, event_window=sys.maxsize,
time_window_ms=30 * 1000, tags=None):
"""
Expand Down
1 change: 1 addition & 0 deletions kafka/metrics/metric_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MetricName(object):
# as messages are sent we record the sizes
sensor.record(message_size)
"""
__slots__ = ('_name', '_group', '_description', '_tags', '_hash')

def __init__(self, name, group, description=None, tags=None):
"""
Expand Down
2 changes: 2 additions & 0 deletions kafka/metrics/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

class Quota(object):
"""An upper or lower bound for metrics"""
__slots__ = ('_bound', '_upper')

def __init__(self, bound, is_upper):
self._bound = bound
self._upper = is_upper
Expand Down
2 changes: 2 additions & 0 deletions kafka/metrics/stats/avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Avg(AbstractSampledStat):
"""
An AbstractSampledStat that maintains a simple average over its samples.
"""
__slots__ = ('_initial_value', '_samples', '_current')

def __init__(self):
super(Avg, self).__init__(0.0)

Expand Down
2 changes: 2 additions & 0 deletions kafka/metrics/stats/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Count(AbstractSampledStat):
"""
An AbstractSampledStat that maintains a simple count of what it has seen.
"""
__slots__ = ('_initial_value', '_samples', '_current')

def __init__(self):
super(Count, self).__init__(0.0)

Expand Down
6 changes: 6 additions & 0 deletions kafka/metrics/stats/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class Histogram(object):
__slots__ = ('_hist', '_count', '_bin_scheme')

def __init__(self, bin_scheme):
self._hist = [0.0] * bin_scheme.bins
self._count = 0.0
Expand Down Expand Up @@ -40,6 +42,8 @@ def __str__(self):
return '{%s}' % ','.join(values)

class ConstantBinScheme(object):
__slots__ = ('_min', '_max', '_bins', '_bucket_width')

def __init__(self, bins, min_val, max_val):
if bins < 2:
raise ValueError('Must have at least 2 bins.')
Expand Down Expand Up @@ -69,6 +73,8 @@ def to_bin(self, x):
return int(((x - self._min) / self._bucket_width) + 1)

class LinearBinScheme(object):
__slots__ = ('_bins', '_max', '_scale')

def __init__(self, num_bins, max_val):
self._bins = num_bins
self._max = max_val
Expand Down
2 changes: 2 additions & 0 deletions kafka/metrics/stats/max_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

class Max(AbstractSampledStat):
"""An AbstractSampledStat that gives the max over its samples."""
__slots__ = ('_initial_value', '_samples', '_current')

def __init__(self):
super(Max, self).__init__(float('-inf'))

Expand Down
2 changes: 2 additions & 0 deletions kafka/metrics/stats/min_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class Min(AbstractSampledStat):
"""An AbstractSampledStat that gives the min over its samples."""
__slots__ = ('_initial_value', '_samples', '_current')

def __init__(self):
super(Min, self).__init__(float(sys.maxsize))

Expand Down
2 changes: 2 additions & 0 deletions kafka/metrics/stats/percentile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


class Percentile(object):
__slots__ = ('_metric_name', '_percentile')

def __init__(self, metric_name, percentile):
self._metric_name = metric_name
self._percentile = float(percentile)
Expand Down
3 changes: 3 additions & 0 deletions kafka/metrics/stats/percentiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class BucketSizing(object):

class Percentiles(AbstractSampledStat, AbstractCompoundStat):
"""A compound stat that reports one or more percentiles"""
__slots__ = ('_initial_value', '_samples', '_current',
'_percentiles', '_buckets', '_bin_scheme')

def __init__(self, size_in_bytes, bucketing, max_val, min_val=0.0,
percentiles=None):
super(Percentiles, self).__init__(0.0)
Expand Down
3 changes: 3 additions & 0 deletions kafka/metrics/stats/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Rate(AbstractMeasurableStat):
occurrences (e.g. the count of values measured over the time interval)
or other such values.
"""
__slots__ = ('_stat', '_unit')

def __init__(self, time_unit=TimeUnit.SECONDS, sampled_stat=None):
self._stat = sampled_stat or SampledTotal()
self._unit = time_unit
Expand Down Expand Up @@ -105,6 +107,7 @@ def convert(self, time_ms):


class SampledTotal(AbstractSampledStat):
__slots__ = ('_initial_value', '_samples', '_current')
def __init__(self, initial_value=None):
if initial_value is not None:
raise ValueError('initial_value cannot be set on SampledTotal')
Expand Down
2 changes: 2 additions & 0 deletions kafka/metrics/stats/sampled_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class AbstractSampledStat(AbstractMeasurableStat):
Subclasses of this class define different statistics measured
using this basic pattern.
"""
__slots__ = ('_initial_value', '_samples', '_current')

def __init__(self, initial_value):
self._initial_value = initial_value
self._samples = []
Expand Down
4 changes: 4 additions & 0 deletions kafka/metrics/stats/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Sensor(object):
the `record(double)` api and would maintain a set
of metrics about request sizes such as the average or max.
"""
__slots__ = ('_lock', '_registry', '_name', '_parents', '_metrics',
'_stats', '_config', '_inactive_sensor_expiration_time_ms',
'_last_record_time')

def __init__(self, registry, name, parents, config,
inactive_sensor_expiration_time_seconds):
if not name:
Expand Down
2 changes: 2 additions & 0 deletions kafka/metrics/stats/total.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

class Total(AbstractMeasurableStat):
"""An un-windowed cumulative total maintained over all time."""
__slots__ = ('_total')

def __init__(self, value=0.0):
self._total = value

Expand Down
Loading