-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (31 loc) · 794 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
package main
import (
"fmt"
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// define you own custom metrics to be exported
var (
myCounter = promauto.NewCounter(prometheus.CounterOpts{
Name: "access_counter",
Help: "The total number of times /count was accessed",
})
)
func main() {
http.Handle("/metrics", promhttp.Handler())
http.HandleFunc("/count", func(w http.ResponseWriter, r *http.Request) {
myCounter.Inc()
_, err := w.Write([]byte("incrementing..."))
if err != nil {
log.Fatal(err)
}
})
fmt.Println("Listening on http://localhost:1234")
err := http.ListenAndServe(":1234", nil)
if err != nil {
panic(err)
}
}