diff --git a/prometheus/push/push.go b/prometheus/push/push.go index 3721ff1..ccfca3a 100644 --- a/prometheus/push/push.go +++ b/prometheus/push/push.go @@ -64,6 +64,8 @@ type Pusher struct { client *http.Client useBasicAuth bool username, password string + + expfmt expfmt.Format } // New creates a new Pusher to push to the provided URL with the provided job @@ -96,6 +98,7 @@ func New(url, job string) *Pusher { gatherers: prometheus.Gatherers{reg}, registerer: reg, client: &http.Client{}, + expfmt: expfmt.FmtProtoDelim, } } @@ -182,6 +185,14 @@ func (p *Pusher) BasicAuth(username, password string) *Pusher { return p } +// Format configures the Pusher to use an encoding format given by the +// provided expfmt.Format. For convenience, this method returns a +// pointer to the Pusher itself. +func (p *Pusher) Format(format expfmt.Format) *Pusher { + p.expfmt = format + return p +} + func (p *Pusher) push(method string) error { if p.error != nil { return p.error @@ -197,7 +208,7 @@ func (p *Pusher) push(method string) error { return err } buf := &bytes.Buffer{} - enc := expfmt.NewEncoder(buf, expfmt.FmtProtoDelim) + enc := expfmt.NewEncoder(buf, p.expfmt) // Check for pre-existing grouping labels: for _, mf := range mfs { for _, m := range mf.GetMetric() {