lemur/lemur/metrics.py

37 lines
1.1 KiB
Python
Raw Normal View History

2016-04-02 01:54:33 +02:00
"""
.. module: lemur.metrics
:copyright: (c) 2018 by Netflix Inc., see AUTHORS for more
2016-04-02 01:54:33 +02:00
:license: Apache, see LICENSE for more details.
"""
from flask import current_app
from lemur.plugins.base import plugins
class Metrics(object):
"""
:param app: The Flask application object. Defaults to None.
"""
2019-05-16 16:57:02 +02:00
2016-04-02 01:54:33 +02:00
_providers = []
def __init__(self, app=None):
if app is not None:
self.init_app(app)
def init_app(self, app):
"""Initializes the application with the extension.
:param app: The Flask application object.
"""
2019-05-16 16:57:02 +02:00
self._providers = app.config.get("METRIC_PROVIDERS", [])
2016-04-02 01:54:33 +02:00
def send(self, metric_name, metric_type, metric_value, *args, **kwargs):
for provider in self._providers:
current_app.logger.debug(
2019-05-16 16:57:02 +02:00
"Sending metric '{metric}' to the {provider} provider.".format(
metric=metric_name, provider=provider
)
)
2016-04-02 01:54:33 +02:00
p = plugins.get(provider)
p.submit(metric_name, metric_type, metric_value, *args, **kwargs)