8000 Add optional scheme support for push gateway urls by thekuffs · Pull Request #103 · prometheus/client_python · GitHub
[go: up one dir, main page]

Skip to content

Add optional scheme support for push gateway urls #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 1, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ def write_to_textfile(path, registry):
def push_to_gateway(gateway, job, registry, grouping_key=None, timeout=None):
'''Push metrics to the given pushgateway.

`gateway` the url for your push gateway. Either of the form
'http://pushgateway.local', or 'pushgateway.local'.
Scheme defaults to 'http' if none is provided
`job` is the job label to be attached to all pushed metrics
`registry` is an instance of CollectorRegistry
`grouping_key` please see the pushgateway documentation for details.
Defaults to None
`timeout` is how long push will attempt to connect before giving up.
Defaults to None

This overwrites all metrics with the same job and grouping_key.
This uses the PUT HTTP method.'''
_use_gateway('PUT', gateway, job, registry, grouping_key, timeout)
Expand All @@ -113,6 +123,16 @@ def push_to_gateway(gateway, job, registry, grouping_key=None, timeout=None):
def pushadd_to_gateway(gateway, job, registry, grouping_key=None, timeout=None):
'''PushAdd metrics to the given pushgateway.

`gateway` the url for your push gateway. Either of the form
'http://pushgateway.local', or 'pushgateway.local'.
Scheme defaults to 'http' if none is provided
`job` is the job label to be attached to all pushed metrics
`registry` is an instance of CollectorRegistry
`grouping_key` please see the pushgateway documentation for details.
Defaults to None
`timeout` is how long push will attempt to connect before giving up.
Defaults to None

This replaces metrics with the same name, job and grouping_key.
This uses the POST HTTP method.'''
_use_gateway('POST', gateway, job, registry, grouping_key, timeout)
Expand All @@ -121,13 +141,24 @@ def pushadd_to_gateway(gateway, job, registry, grouping_key=None, timeout=None):
def delete_from_gateway(gateway, job, grouping_key=None, timeout=None):
'''Delete metrics from the given pushgateway.

`gateway` the url for your push gateway. Either of the form
'http://pushgateway.local', or 'pushgateway.local'.
Scheme defaults to 'http' if none is provided
`job` is the job label to be attached to all pushed metrics
`grouping_key` please see the pushgateway documentation for details.
Defaults to None
`timeout` is how long delete will attempt to connect before giving up.
Defaults to None

This deletes metrics with the given job and grouping_key.
This uses the DELETE HTTP method.'''
_use_gateway('DELETE', gateway, job, None, grouping_key, timeout)


def _use_gateway(method, gateway, job, registry, grouping_key, timeout):
url = 'http://{0}/metrics/job/{1}'.format(gateway, quote_plus(job))
if not (gateway.startswith('http://') or gateway.startswith('https://')):
gateway = 'http://{0}'.format(gateway)
url = '{0}/metrics/job/{1}'.format(gateway, quote_plus(job))

data = b''
if method != 'DELETE':
Expand Down
0