@@ -158,7 +158,7 @@ func Unregister(c Collector) bool {
158
158
// SetMetricFamilyInjectionHook sets a function that is called whenever metrics
159
159
// are collected. The hook function must be set before metrics collection begins
160
160
// (i.e. call SetMetricFamilyInjectionHook before setting the HTTP handler.) The
161
- // MetricFamily protobufs returned by the hook function are added to the
161
+ // MetricFamily protobufs returned by the hook function areadded to the
162
162
// delivered metrics. Each returned MetricFamily must have a unique name (also
163
163
// taking into account the MetricFamilies created in the regular way).
164
164
//
@@ -187,26 +187,6 @@ func EnableCollectChecks(b bool) {
187
187
defRegistry .collectChecksEnabled = b
188
188
}
189
189
190
- // Push triggers a metric collection and pushes all collected metrics to the
191
- // Pushgateway specified by addr. See the Pushgateway documentation for detailed
192
- // implications of the job and instance parameter. instance can be left
193
- // empty. The Pushgateway will then use the client's IP number instead. Use just
194
- // host:port or ip:port ass addr. (Don't add 'http://' or any path.)
195
- //
196
- // Note that all previously pushed metrics with the same job and instance will
197
- // be replaced with the metrics pushed by this call. (It uses HTTP method 'PUT'
198
- // to push to the Pushgateway.)
199
- func Push (job , instance , addr string ) error {
200
- return defRegistry .Push (job , instance , addr , "PUT" )
201
- }
202
-
203
- // PushAdd works like Push, but only previously pushed metrics with the same
204
- // name (and the same job and instance) will be replaced. (It uses HTTP method
205
- // 'POST' to push to the Pushgateway.)
206
- func PushAdd (job , instance , addr string ) error {
207
- return defRegistry .Push (job , instance , addr , "POST" )
208
- }
209
-
210
190
// encoder is a function that writes a dto.MetricFamily to an io.Writer in a
211
191
// certain encoding. It returns the number of bytes written and any error
212
192
// encountered. Note that ext.WriteDelimited and text.MetricFamilyToText are
@@ -346,10 +326,13 @@ func (r *registry) Unregister(c Collector) bool {
346
326
return true
347
327
}
348
328
349
- func (r * registry ) Push (job , instance , addr , method string ) error {
350
- u := fmt .Sprintf ("http://%s/metrics/jobs/%s" , addr , url .QueryEscape (job ))
329
+ func (r * registry ) Push (job , instance , pushURL , method string ) error {
330
+ if ! strings .Contains (pushURL , "://" ) {
331
+ pushURL = "http://" + pushURL
332
+ }
333
+ pushURL = fmt .Sprintf ("%s/metrics/jobs/%s" , pushURL , url .QueryEscape (job ))
351
334
if instance != "" {
352
- u += "/instances/" + url .QueryEscape (instance )
335
+ pushURL += "/instances/" + url .QueryEscape (instance )
353
336
}
354
337
buf := r .getBuf ()
355
338
defer r .giveBuf (buf )
@@ -359,7 +342,7 @@ func (r *registry) Push(job, instance, addr, method string) error {
359
342
}
360
343
return err
361
344
}
362
- req , err := http .NewRequest (method , u , buf )
345
+ req , err := http .NewRequest (method , pushURL , buf )
363
346
if err != nil {
364
347
return err
365
348
}
@@ -370,7 +353,7 @@ func (r *registry) Push(job, instance, addr, method string) error {
370
353
}
371
354
defer resp .Body .Close ()
372
355
if resp .StatusCode != 202 {
373
- return fmt .Errorf ("unexpected status code %d while pushing to %s" , resp .StatusCode , u )
356
+ return fmt .Errorf ("unexpected status code %d while pushing to %s" , resp .StatusCode , pushURL )
374
357
}
375
358
return nil
376
359
}
0 commit comments