def setup_prometheus_sensors( app: AppT, pattern: str = "/metrics", registry: CollectorRegistry = REGISTRY, name_prefix: Optional[str] = None, ) -> None: """ A utility function which sets up prometheus and attaches the config to the app. @param app: the faust app instance @param pattern: the url pattern for prometheus @param registry: the prometheus registry @param name_prefix: the name prefix. Defaults to the app name @return: None """ if prometheus_client is None: raise ImproperlyConfigured( "prometheus_client requires `pip install prometheus_client`." ) if name_prefix is None: name_prefix = app.conf.name name_prefix = name_prefix.replace("-", "_").replace(".", "_") faust_metrics = FaustMetrics.create(registry, name_prefix) app.monitor = PrometheusMonitor(metrics=faust_metrics) @app.page(pattern) async def metrics_handler(self: _web.View, request: _web.Request) -> _web.Response: headers = {"Content-Type": CONTENT_TYPE_LATEST} return cast( _web.Response, Response(body=generate_latest(REGISTRY), headers=headers, status=200), )
def setup_prometheus_sensors( app: AppT, pattern: str = "/metrics", registry: CollectorRegistry = REGISTRY, name_prefix: str = None, ) -> None: """ A utility function which sets up prometheus and attaches the config to the app. @param app: the faust app instance @param pattern: the url pattern for prometheus @param registry: the prometheus registry @param name_prefix: the name prefix. Defaults to the app name @return: None """ if prometheus_client is None: raise ImproperlyConfigured( "prometheus_client requires `pip install prometheus_client`." ) if name_prefix is None: app_conf_name = app.conf.name app.logger.info( "Name prefix is not supplied. Using the name %s from App config.", app_conf_name, ) if "-" in app_conf_name: name_prefix = app_conf_name.replace("-", "_") app.logger.warning( "App config name %s does not conform to" " Prometheus naming conventions." " Using %s as a name_prefix.", app_conf_name, name_prefix, ) faust_metrics = FaustMetrics.create(registry, name_prefix) app.monitor = PrometheusMonitor(metrics=faust_metrics) @app.page(pattern) async def metrics_handler(self: _web.View, request: _web.Request) -> _web.Response: headers = {"Content-Type": CONTENT_TYPE_LATEST} return cast( _web.Response, Response(body=generate_latest(REGISTRY), headers=headers, status=200), )
def setup_prometheus_sensors(app: AppT, pattern: str = "/metrics", registry: CollectorRegistry = REGISTRY) -> None: if prometheus_client is None: raise ImproperlyConfigured( "prometheus_client requires `pip install prometheus_client`.") faust_metrics = FaustMetrics.create(registry) app.monitor = PrometheusMonitor(metrics=faust_metrics) @app.page(pattern) async def metrics_handler(self: _web.View, request: _web.Request) -> _web.Response: headers = {"Content-Type": CONTENT_TYPE_LATEST} return cast( _web.Response, Response(body=generate_latest(REGISTRY), headers=headers, status=200), )