-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmain.go
36 lines (29 loc) · 882 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
package main
import (
"fmt"
"math/rand"
"net/http"
"time"
"github.com/go-chi/chi"
"github.com/766b/chi-prometheus"
"github.com/prometheus/client_golang/prometheus"
)
func main() {
n := chi.NewRouter()
m := chiprometheus.NewMiddleware("serviceName")
// if you want to use other buckets than the default (300, 1200, 5000) you can run:
// m := negroniprometheus.NewMiddleware("serviceName", 400, 1600, 700)
n.Use(m)
n.Handle("/metrics", prometheus.Handler())
n.Get("/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)
})
n.Get("/notfound", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintln(w, "not found")
})
http.ListenAndServe(":3000", n)
}