@@ -105,6 +105,16 @@ def write_to_textfile(path, registry):
105
105
def push_to_gateway (gateway , job , registry , grouping_key = None , timeout = None ):
106
106
'''Push metrics to the given pushgateway.
107
107
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
+
108
118
This overwrites all metrics with the same job and grouping_key.
109
119
This uses the PUT HTTP method.'''
110
120
_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):
113
123
def pushadd_to_gateway (gateway , job , registry , grouping_key = None , timeout = None ):
114
124
'''PushAdd metrics to the given pushgateway.
115
125
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
+
116
136
This replaces metrics with the same name, job and grouping_key.
117
137
This uses the POST HTTP method.'''
118
138
_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):
121
141
def delete_from_gateway (gateway , job , grouping_key = None , timeout = None ):
122
142
'''Delete metrics from the given pushgateway.
123
143
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
+
124
153
This deletes metrics with the given job and grouping_key.
125
154
This uses the DELETE HTTP method.'''
126
155
_use_gateway ('DELETE' , gateway , job , None , grouping_key , timeout )
127
156
128
157
129
158
def _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 ))
131
162
132
163
data = b''
133
164
if method != 'DELETE' :
0 commit comments