@@ -121,7 +121,7 @@ def write_to_textfile(path, registry):
121121 os .rename (tmppath , path )
122122
123123
124- def push_to_gateway (gateway , job , registry , grouping_key = None , timeout = None , handler = None ):
124+ def push_to_gateway (gateway , job , registry , grouping_key = None , timeout = None , handler = None , handler_args = None ):
125125 '''Push metrics to the given pushgateway.
126126
127127 `gateway` the url for your push gateway. Either of the form
@@ -157,13 +157,14 @@ def push_to_gateway(gateway, job, registry, grouping_key=None, timeout=None, han
157157 failure.
158158 'content' is the data which should be used to form the HTTP
159159 Message Body.
160+ `handler_args` is an optional dict of extra arguments to provide
160161
161162 This overwrites all metrics with the same job and grouping_key.
162163 This uses the PUT HTTP method.'''
163- _use_gateway ('PUT' , gateway , job , registry , grouping_key , timeout , handler )
164+ _use_gateway ('PUT' , gateway , job , registry , grouping_key , timeout , handler , handler_args )
164165
165166
166- def pushadd_to_gateway (gateway , job , registry , grouping_key = None , timeout = None , handler = None ):
167+ def pushadd_to_gateway (gateway , job , registry , grouping_key = None , timeout = None , handler = None , handler_args = None ):
167168 '''PushAdd metrics to the given pushgateway.
168169
169170 `gateway` the url for your push gateway. Either of the form
@@ -184,10 +185,10 @@ def pushadd_to_gateway(gateway, job, registry, grouping_key=None, timeout=None,
184185
185186 This replaces metrics with the same name, job and grouping_key.
186187 This uses the POST HTTP method.'''
187- _use_gateway ('POST' , gateway , job , registry , grouping_key , timeout , handler )
188+ _use_gateway ('POST' , gateway , job , registry , grouping_key , timeout , handler , handler_args )
188189
189190
190- def delete_from_gateway (gateway , job , grouping_key = None , timeout = None , handler = None ):
191+ def delete_from_gateway (gateway , job , grouping_key = None , timeout = None , handler = None , handler_args = None ):
191192 '''Delete metrics from the given pushgateway.
192193
193194 `gateway` the url for your push gateway. Either of the form
@@ -207,10 +208,10 @@ def delete_from_gateway(gateway, job, grouping_key=None, timeout=None, handler=N
207208
208209 This deletes metrics with the given job and grouping_key.
209210 This uses the DELETE HTTP method.'''
210- _use_gateway ('DELETE' , gateway , job , None , grouping_key , timeout , handler )
211+ _use_gateway ('DELETE' , gateway , job , None , grouping_key , timeout , handler , handler_args )
211212
212213
213- def _use_gateway (method , gateway , job , registry , grouping_key , timeout , handler ):
214+ def _use_gateway (method , gateway , job , registry , grouping_key , timeout , handler , handler_args ):
214215 gateway_url = urlparse (gateway )
215216 if not gateway_url .scheme :
216217 gateway = 'http://{0}' .format (gateway )
@@ -228,8 +229,10 @@ def _use_gateway(method, gateway, job, registry, grouping_key, timeout, handler)
228229 headers = [('Content-Type' , CONTENT_TYPE_LATEST )]
229230 if handler is None :
230231 handler = default_handler
232+ if handler_args is None :
233+ handler_args = dict ()
231234 handler (url = url , method = method , timeout = timeout ,
232- headers = headers , data = data )
235+ headers = headers , data = data , ** handler_args )
233236
234237def instance_ip_grouping_key ():
235238 '''Grouping key with instance set to the IP Address of this host.'''
0 commit comments