forked from zbindenren/negroni-prometheus
/
main.go
38 lines (31 loc) · 959 Bytes
/
main.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
package main
import (
"fmt"
"math/rand"
"net/http"
"time"
"github.com/urfave/negroni"
"github.com/prometheus/client_golang/prometheus"
"github.com/zbindenren/negroni-prometheus"
)
func main() {
n := negroni.New()
m := negroniprometheus.NewMiddlewareWithoutPath("serviceName")
// if you want to use other buckets than the default (300, 1200, 5000) you can run:
// m := negroniprometheus.NewMiddlewareWithoutPath("serviceName", 400, 1600, 700)
n.Use(m)
r := http.NewServeMux()
r.Handle("/metrics", prometheus.Handler())
r.HandleFunc(`/ok`, func(w http.ResponseWriter, r *http.Request) {
sleep := rand.Intn(4999) + 1
time.Sleep(time.Duration(sleep) * time.Millisecond)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "slept %d milliseconds\n", sleep)
})
r.HandleFunc(`/notfound`, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintln(w, "not found")
})
n.UseHandler(r)
n.Run(":3000")
}