forked from go-mysql-org/go-mysql-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
54 lines (49 loc) · 1.28 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
package river
import (
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
esInsertNum = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "mysql2es_inserted_num",
Help: "The number of docs inserted to elasticsearch",
}, []string{"index"},
)
esUpdateNum = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "mysql2es_updated_num",
Help: "The number of docs updated to elasticsearch",
}, []string{"index"},
)
esDeleteNum = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "mysql2es_deleted_num",
Help: "The number of docs deleted from elasticsearch",
}, []string{"index"},
)
canalSyncState = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "mysql2es_canal_state",
Help: "The canal slave running state: 0=stopped, 1=ok",
},
)
canalDelay = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "mysql2es_canal_delay",
Help: "The canal slave lag",
},
)
)
func (r *River) collectMetrics() {
for range time.Tick(10 * time.Second) {
canalDelay.Set(float64(r.canal.GetDelay()))
}
}
func InitStatus(addr string, path string) {
http.Handle(path, promhttp.Handler())
http.ListenAndServe(addr, nil)
}