Python prometheus_client.multiprocess.MultiProcessCollector() Examples
The following are 6
code examples of prometheus_client.multiprocess.MultiProcessCollector().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
prometheus_client.multiprocess
, or try the search function
.
Example #1
Source File: views.py From kqueen with MIT License | 6 votes |
def root(): # check access ip_whitelist = ip_network(current_app.config.get('PROMETHEUS_WHITELIST')) if ip_address(request.remote_addr) not in ip_whitelist: _jwt_required(current_app.config['JWT_DEFAULT_REALM']) MU = MetricUpdater() registry = CollectorRegistry() multiprocess.MultiProcessCollector(registry) data = generate_latest(registry) response = make_response(data) response.headers['Content-Type'] = CONTENT_TYPE_LATEST response.headers['Content-Length'] = str(len(data)) logger.info('Kqueen metrics updating') MU.update_metrics() return response
Example #2
Source File: utils.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def generate_latest(self): """Generate a bytestring with metric values.""" if self.registry is None: return registry = self.registry if registry is prom_cli.REGISTRY: # when using the global registry, setup up multiprocess # support. In this case, a separate registry needs to be used # for generating the samples. registry = prom_cli.CollectorRegistry() from prometheus_client import multiprocess multiprocess.MultiProcessCollector(registry) for handler in self._update_handlers: handler(self) return prom_cli.generate_latest(registry)
Example #3
Source File: yourapp.py From prometheus-multiprocessing-example with ISC License | 5 votes |
def metrics(): registry = CollectorRegistry() multiprocess.MultiProcessCollector(registry) data = generate_latest(registry) return Response(data, mimetype=CONTENT_TYPE_LATEST)
Example #4
Source File: exports.py From django-prometheus with Apache License 2.0 | 5 votes |
def ExportToDjangoView(request): """Exports /metrics as a Django view. You can use django_prometheus.urls to map /metrics to this view. """ if "prometheus_multiproc_dir" in os.environ: registry = prometheus_client.CollectorRegistry() multiprocess.MultiProcessCollector(registry) else: registry = prometheus_client.REGISTRY metrics_page = prometheus_client.generate_latest(registry) return HttpResponse( metrics_page, content_type=prometheus_client.CONTENT_TYPE_LATEST )
Example #5
Source File: __init__.py From prometheus_flask_exporter with MIT License | 5 votes |
def register_endpoint(self, path, app=None): """ Register the metrics endpoint on the Flask application. :param path: the path of the endpoint :param app: the Flask application to register the endpoint on (by default it is the application registered with this class) """ if is_running_from_reloader() and not os.environ.get('DEBUG_METRICS'): return if app is None: app = self.app or current_app @app.route(path) @self.do_not_track() def prometheus_metrics(): # import these here so they don't clash with our own multiprocess module from prometheus_client import multiprocess, CollectorRegistry if 'prometheus_multiproc_dir' in os.environ: registry = CollectorRegistry() else: registry = self.registry if 'name[]' in request.args: registry = registry.restricted_registry(request.args.getlist('name[]')) if 'prometheus_multiproc_dir' in os.environ: multiprocess.MultiProcessCollector(registry) headers = {'Content-Type': CONTENT_TYPE_LATEST} return generate_latest(registry), 200, headers
Example #6
Source File: 4-4-app.py From examples with Apache License 2.0 | 5 votes |
def app(environ, start_fn): REQUESTS.inc() if environ['PATH_INFO'] == '/metrics': registry = CollectorRegistry() multiprocess.MultiProcessCollector(registry) metrics_app = make_wsgi_app(registry) return metrics_app(environ, start_fn) start_fn('200 OK', []) return [b'Hello World']