/
statuspage.go
33 lines (28 loc) · 1017 Bytes
/
statuspage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package echostatuspage
import (
"bytes"
"net/http"
"github.com/labstack/echo"
"github.com/sirupsen/logrus"
"github.com/trafficstars/statuspage"
)
// StatusJSON is a handler for framework "echo" to display all the metrics in JSON format
func StatusJSON(ctx echo.Context) error {
buf := new(bytes.Buffer)
err := statuspage.WriteMetricsJSON(buf)
if err != nil {
logrus.Errorf(`cannot print the status page (JSON): %v`, err)
}
ctx.Response().Header().Set("Content-Type", `application/json`)
return ctx.String(http.StatusOK, string(buf.Bytes()))
}
// StatusPrometheus is a handler for framework "echo" to display all the metrics in Prometheus format
func StatusPrometheus(ctx echo.Context) error {
buf := new(bytes.Buffer)
err := statuspage.WriteMetricsPrometheus(buf)
if err != nil {
logrus.Errorf(`cannot print the status page (for Prometheus): %v`, err)
}
ctx.Response().Header().Set("Content-Type", string(statuspage.PrometheusFormat))
return ctx.String(http.StatusOK, string(buf.Bytes()))
}