-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathprometheus.go
35 lines (32 loc) · 890 Bytes
/
prometheus.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
package main
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)
type Prometheus struct {
Requests prometheus.Counter
ForwarderStatus *prometheus.CounterVec
}
func NewPrometheus() (*Prometheus, error) {
p := Prometheus{
Requests: prometheus.NewCounter(prometheus.CounterOpts{
Name: `requests`,
Help: `Announce requests`,
}),
ForwarderStatus: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: `forwarder_status`,
Help: `Forwarder response status`,
}, []string{`name`, `status`}),
}
if err := prometheus.Register(p.Requests); err != nil {
ErrorLog.Println(err.Error())
return nil, err
}
if err := prometheus.Register(p.ForwarderStatus); err != nil {
ErrorLog.Println(err.Error())
return nil, err
}
http.Handle("/metrics", promhttp.Handler())
return &p, nil
}