forked from MichelDiz/dgraph-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
42 lines (36 loc) · 875 Bytes
/
metrics.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
package tasks
import (
"fmt"
"net/http"
prom "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
counters = prom.NewCounterVec(
prom.CounterOpts{
Namespace: "dgraph",
Subsystem: "people",
Name: "query_count",
Help: "Total number of queries.",
}, []string{"query", "status"})
durations = prom.NewHistogramVec(
prom.HistogramOpts{
Namespace: "dgraph",
Subsystem: "people",
Name: "query_duration",
Help: "Histogram of query duration.",
Buckets: prom.DefBuckets,
},
[]string{"query", "status"},
)
)
func init() {
prom.Register(counters)
prom.Register(durations)
}
func StartPrometheusServer(port int) {
http.Handle("/metrics", promhttp.Handler())
if err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil); err != nil {
panic(err)
}
}