parent
1af83e7971
commit
6ea51afa66
2 changed files with 8 additions and 3 deletions
|
@ -25,8 +25,9 @@ class PrometheusPlugin(object):
|
|||
|
||||
def init_app(self, app):
|
||||
prom_url = app.config.get('PROMETHEUS_AGGREGATOR_URL')
|
||||
prom_namespace = app.config.get('PROMETHEUS_NAMESPACE')
|
||||
logger.debug('Initializing prometheus with aggregator url: %s', prom_url)
|
||||
prometheus = Prometheus(prom_url)
|
||||
prometheus = Prometheus(prom_url, prom_namespace)
|
||||
|
||||
# register extension with app
|
||||
app.extensions = getattr(app, 'extensions', {})
|
||||
|
@ -39,9 +40,10 @@ class PrometheusPlugin(object):
|
|||
|
||||
class Prometheus(object):
|
||||
""" Aggregator for collecting stats that are reported to Prometheus. """
|
||||
def __init__(self, url=None):
|
||||
def __init__(self, url=None, namespace=None):
|
||||
self._metric_collectors = []
|
||||
self._url = url
|
||||
self._namespace = namespace or ''
|
||||
|
||||
if url is not None:
|
||||
self._queue = Queue(QUEUE_MAX)
|
||||
|
@ -91,6 +93,7 @@ class Prometheus(object):
|
|||
return self._create_collector('Untyped', args, kwargs)
|
||||
|
||||
def _create_collector(self, collector_type, args, kwargs):
|
||||
kwargs['namespace'] = kwargs.get('namespace', self._namespace)
|
||||
return _Collector(self.enqueue, collector_type, *args, **kwargs)
|
||||
|
||||
|
||||
|
@ -138,7 +141,6 @@ class _Collector(object):
|
|||
def __init__(self, enqueue_method, collector_type, collector_name, collector_help,
|
||||
namespace='', subsystem='', **kwargs):
|
||||
self._enqueue_method = enqueue_method
|
||||
|
||||
self._base_args = {
|
||||
'Name': collector_name,
|
||||
'Namespace': namespace,
|
||||
|
|
Reference in a new issue