New creates a new Pusher to push to the provided URL with the provided job name (which must not be empty). You can use just host:port or ip:port as url, in which case “http://” is added automatically. Alternatively, include the schema in the URL. However, do not include the “/metrics/jobs/…” part.
(url, job string)
| 89 | // in which case “http://” is added automatically. Alternatively, include the |
| 90 | // schema in the URL. However, do not include the “/metrics/jobs/…” part. |
| 91 | func New(url, job string) *Pusher { |
| 92 | var ( |
| 93 | reg = prometheus.NewRegistry() |
| 94 | err error |
| 95 | ) |
| 96 | if job == "" { |
| 97 | err = errJobEmpty |
| 98 | } |
| 99 | if !strings.Contains(url, "://") { |
| 100 | url = "http://" + url |
| 101 | } |
| 102 | url = strings.TrimSuffix(url, "/") |
| 103 | |
| 104 | return &Pusher{ |
| 105 | error: err, |
| 106 | url: url, |
| 107 | job: job, |
| 108 | grouping: map[string]string{}, |
| 109 | gatherers: prometheus.Gatherers{reg}, |
| 110 | registerer: reg, |
| 111 | client: &http.Client{}, |
| 112 | expfmt: expfmt.NewFormat(expfmt.TypeProtoDelim), |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Push collects/gathers all metrics from all Collectors and Gatherers added to |
| 117 | // this Pusher. Then, it pushes them to the Pushgateway configured while |