RegistryDump returns the http page for a given registry's metrics. Very useful for visual debugging.
(reg *prometheus.Registry)
| 19 | // RegistryDump returns the http page for a given registry's metrics. |
| 20 | // Very useful for visual debugging. |
| 21 | func RegistryDump(reg *prometheus.Registry) string { |
| 22 | h := promhttp.HandlerFor(reg, promhttp.HandlerOpts{}) |
| 23 | rec := httptest.NewRecorder() |
| 24 | req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/", nil) |
| 25 | h.ServeHTTP(rec, req) |
| 26 | resp := rec.Result() |
| 27 | data, _ := io.ReadAll(resp.Body) |
| 28 | _ = resp.Body.Close() |
| 29 | return string(data) |
| 30 | } |
| 31 | |
| 32 | // Compare can be used to compare a registry to some prometheus formatted |
| 33 | // text. If any values differ, an error is returned. |