def add(self, metric_name, stat, config=None): """ Register a metric with this sensor Arguments: metric_name (MetricName): The name of the metric stat (AbstractMeasurableStat): The statistic to keep config (MetricConfig): A special configuration for this metric. If None use the sensor default configuration. """ with self._lock: metric = KafkaMetric(metric_name, stat, config or self._config) self._registry.register_metric(metric) self._metrics.append(metric) self._stats.append(stat)
def add_metric(self, metric_name, measurable, config=None): """ Add a metric to monitor an object that implements measurable. This metric won't be associated with any sensor. This is a way to expose existing values as metrics. Arguments: metricName (MetricName): The name of the metric measurable (AbstractMeasurable): The measurable that will be measured by this metric config (MetricConfig, optional): The configuration to use when measuring this measurable """ # NOTE there was a lock here, but i don't think it's needed metric = KafkaMetric(metric_name, measurable, config or self.config) self.register_metric(metric)
def add_compound(self, compound_stat, config=None): """ Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram) Arguments: stat (AbstractCompoundStat): The stat to register config (MetricConfig): The configuration for this stat. If None then the stat will use the default configuration for this sensor. """ if not compound_stat: raise ValueError('compound stat must be non-empty') self._stats.append(compound_stat) for named_measurable in compound_stat.stats(): metric = KafkaMetric(named_measurable.name, named_measurable.stat, config or self._config) self._registry.register_metric(metric) self._metrics.append(metric)