Status serves the status page. The returned handler is already instrumented for Prometheus.
( ms storage.MetricStore, root http.FileSystem, flags map[string]string, pathPrefix string, logger *slog.Logger, )
| 54 | // |
| 55 | // The returned handler is already instrumented for Prometheus. |
| 56 | func Status( |
| 57 | ms storage.MetricStore, |
| 58 | root http.FileSystem, |
| 59 | flags map[string]string, |
| 60 | pathPrefix string, |
| 61 | logger *slog.Logger, |
| 62 | ) http.Handler { |
| 63 | birth := time.Now() |
| 64 | return InstrumentWithCounter( |
| 65 | "status", |
| 66 | http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 67 | t := template.New("status") |
| 68 | t.Funcs(template.FuncMap{ |
| 69 | "value": func(f float64) string { |
| 70 | return strconv.FormatFloat(f, 'f', -1, 64) |
| 71 | }, |
| 72 | "timeFormat": func(t time.Time) string { |
| 73 | return t.Format(time.RFC3339) |
| 74 | }, |
| 75 | "base64": func(s string) string { |
| 76 | return base64.RawURLEncoding.EncodeToString([]byte(s)) |
| 77 | }, |
| 78 | "formatHistogram": func(m *dto.Histogram) string { |
| 79 | h, fh := histogram.NewModelHistogram(m) |
| 80 | if h == nil { |
| 81 | return fh.String() |
| 82 | } |
| 83 | return h.String() |
| 84 | }, |
| 85 | "add": func(x, y int) int { |
| 86 | return x + y |
| 87 | }, |
| 88 | "formatLabelName": func(s string) string { |
| 89 | if !ValidationScheme.IsValidLabelName(s) { |
| 90 | return fmt.Sprintf("%q", s) |
| 91 | } |
| 92 | return s |
| 93 | }, |
| 94 | }) |
| 95 | |
| 96 | f, err := root.Open("template.html") |
| 97 | if err != nil { |
| 98 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 99 | logger.Error("error loading template.html", "err", err.Error()) |
| 100 | return |
| 101 | } |
| 102 | defer f.Close() |
| 103 | tpl, err := io.ReadAll(f) |
| 104 | if err != nil { |
| 105 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 106 | logger.Error("error reading template.html", "err", err.Error()) |
| 107 | return |
| 108 | } |
| 109 | _, err = t.Parse(string(tpl)) |
| 110 | if err != nil { |
| 111 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 112 | logger.Error("error parsing template", "err", err.Error()) |
| 113 | return |
searching dependent graphs…