Fix: #222. Support custom registry for MetricsHandler. by ioggstream · Pull Request #223 · prometheus/client_python · GitHub
Skip to content

Fix: #222. Support custom registry for MetricsHandler.#223

Merged
brian-brazil merged 1 commit into
prometheus:masterfrom
ioggstream:222-pass-registry-to-handler
Dec 13, 2017
Merged

Fix: #222. Support custom registry for MetricsHandler.#223
brian-brazil merged 1 commit into
prometheus:masterfrom
ioggstream:222-pass-registry-to-handler

Conversation

@ioggstream

Copy link
Copy Markdown
Contributor

What does this PR do?

Add registry parameter to start_http_server, so you can serve data
from a custom registry.

How it's implemented

Added:

  • the optional named parameter registry to start_http_server
  • create a MetricHandler tied to the passed registry via MetricHandler.factory

How do you use it

Create a new or a multiprocess registry
Pass registry=myregistry to start_http_server.

from prometheus_client import multiprocess, start_http_server
from prometheus_client import Counter
...
# Serve myregistry metrics.
myregistry = CollectorRegistry()
start_http_server(8000, registry=myregistry)

# Server core.REGISTRY metrics
start_http_server(8001) 
...

  Pass a registry to start_http_server via a MetricsHandler
    factory implemented as a staticmethod of the existing class.
@brian-brazil

Copy link
Copy Markdown
Contributor

@ioggstream

Copy link
Copy Markdown
Contributor Author

I split the patch in two. This is just the custom registry part. No multiprocess.

@brian-brazil brian-brazil merged commit 24d4d95 into prometheus:master Dec 13, 2017
@brian-brazil

Copy link
Copy Markdown
Contributor

Thanks!

@ioggstream

Copy link
Copy Markdown
Contributor Author

@ioggstream ioggstream deleted the 222-pass-registry-to-handler branch December 14, 2017 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants