@@ -105,6 +105,16 @@ def write_to_textfile(path, registry):
105105def push_to_gateway (gateway , job , registry , grouping_key = None , timeout = None ):
106106 '''Push metrics to the given pushgateway.
107107
108+ `gateway` the url for your push gateway. Either of the form
109+ 'http://pushgateway.local', or 'pushgateway.local'.
110+ Scheme defaults to 'http' if none is provided
111+ `job` is the job label to be attached to all pushed metrics
112+ `registry` is an instance of CollectorRegistry
113+ `grouping_key` please see the pushgateway documentation for details.
114+ Defaults to None
115+ `timeout` is how long push will attempt to connect before giving up.
116+ Defaults to None
117+
108118 This overwrites all metrics with the same job and grouping_key.
109119 This uses the PUT HTTP method.'''
110120 _use_gateway ('PUT' , gateway , job , registry , grouping_key , timeout )
@@ -113,6 +123,16 @@ def push_to_gateway(gateway, job, registry, grouping_key=None, timeout=None):
113123def pushadd_to_gateway (gateway , job , registry , grouping_key = None , timeout = None ):
114124 '''PushAdd metrics to the given pushgateway.
115125
126+ `gateway` the url for your push gateway. Either of the form
127+ 'http://pushgateway.local', or 'pushgateway.local'.
128+ Scheme defaults to 'http' if none is provided
129+ `job` is the job label to be attached to all pushed metrics
130+ `registry` is an instance of CollectorRegistry
131+ `grouping_key` please see the pushgateway documentation for details.
132+ Defaults to None
133+ `timeout` is how long push will attempt to connect before giving up.
134+ Defaults to None
135+
116136 This replaces metrics with the same name, job and grouping_key.
117137 This uses the POST HTTP method.'''
118138 _use_gateway ('POST' , gateway , job , registry , grouping_key , timeout )
@@ -121,13 +141,24 @@ def pushadd_to_gateway(gateway, job, registry, grouping_key=None, timeout=None):
121141def delete_from_gateway (gateway , job , grouping_key = None , timeout = None ):
122142 '''Delete metrics from the given pushgateway.
123143
144+ `gateway` the url for your push gateway. Either of the form
145+ 'http://pushgateway.local', or 'pushgateway.local'.
146+ Scheme defaults to 'http' if none is provided
147+ `job` is the job label to be attached to all pushed metrics
148+ `grouping_key` please see the pushgateway documentation for details.
149+ Defaults to None
150+ `timeout` is how long delete will attempt to connect before giving up.
151+ Defaults to None
152+
124153 This deletes metrics with the given job and grouping_key.
125154 This uses the DELETE HTTP method.'''
126155 _use_gateway ('DELETE' , gateway , job , None , grouping_key , timeout )
127156
128157
129158def _use_gateway (method , gateway , job , registry , grouping_key , timeout ):
130- url = 'http://{0}/metrics/job/{1}' .format (gateway , quote_plus (job ))
159+ if not (gateway .startswith ('http://' ) or gateway .startswith ('https://' )):
160+ gateway = 'http://{0}' .format (gateway )
161+ url = '{0}/metrics/job/{1}' .format (gateway , quote_plus (job ))
131162
132163 data = b''
133164 if method != 'DELETE' :
0 commit comments