Push pushes Prometheus metrics to the configured Graphite server.
()
| 164 | |
| 165 | // Push pushes Prometheus metrics to the configured Graphite server. |
| 166 | func (b *Bridge) Push() error { |
| 167 | mfs, err := b.g.Gather() |
| 168 | if err != nil || len(mfs) == 0 { |
| 169 | switch b.errorHandling { |
| 170 | case AbortOnError: |
| 171 | return err |
| 172 | case ContinueOnError: |
| 173 | if b.logger != nil { |
| 174 | b.logger.Println("continue on error:", err) |
| 175 | } |
| 176 | default: |
| 177 | panic("unrecognized error handling value") |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | conn, err := net.DialTimeout("tcp", b.url, b.timeout) |
| 182 | if err != nil { |
| 183 | return err |
| 184 | } |
| 185 | defer conn.Close() |
| 186 | |
| 187 | return writeMetrics(conn, mfs, b.useTags, b.prefix, model.Now()) |
| 188 | } |
| 189 | |
| 190 | func writeMetrics(w io.Writer, mfs []*dto.MetricFamily, useTags bool, prefix string, now model.Time) error { |
| 191 | vec, err := expfmt.ExtractSamples(&expfmt.DecodeOptions{ |