/
http.go
49 lines (38 loc) · 1010 Bytes
/
http.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"net/http"
"strings"
"time"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
func initHTTP() {
httpLis, err := listen(cfg.ListenHTTP)
if err != nil {
log.Fatalf("Unable to listen to HTTP: %s", err)
}
http.HandleFunc("/stats", httpStats)
http.Handle("/metrics", promhttp.Handler())
if err = http.Serve(httpLis, nil); err != http.ErrServerClosed {
log.Fatalf("HTTP listening error: %s", err)
}
}
func httpStats(w http.ResponseWriter, r *http.Request) {
out := fmt.Sprintf("riemann-relay v%s up for %s\n", version, time.Since(startTime))
for _, n := range inputNames {
i := inputs[n]
out += fmt.Sprintf("Input %s:\n", n)
for _, r := range strings.Split(i.getStats(), "\n") {
out += fmt.Sprintf(" %s\n", r)
}
}
for _, n := range outputNames {
o := outputs[n]
out += fmt.Sprintf("Output %s:\n", n)
for _, r := range o.getStats() {
out += fmt.Sprintf(" %s\n", r)
}
}
fmt.Fprint(w, out)
}