-
Notifications
You must be signed in to change notification settings - Fork 0
/
exporter.go
65 lines (58 loc) · 1.64 KB
/
exporter.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
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"sync"
"github.com/prometheus/client_golang/prometheus"
)
const (
namespace = "http2pulsar" // For Prometheus metrics.
)
// Exporter is prometheus exporter
type Exporter struct {
mutex sync.Mutex
receivedSns prometheus.Counter
sendSns prometheus.Counter
failedSns prometheus.Counter
sentDuration prometheus.Gauge
}
// NewExporter create a Exporter
func NewExporter() *Exporter {
return &Exporter{
receivedSns: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "received_sns_total",
Help: "Total number of received sns.",
}),
sendSns: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "sent_sns_total",
Help: "Total number of processed sns sent to pulsar broker.",
}),
failedSns: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "failed_sns_total",
Help: "Total number of processed sns which failed on send to pulsar broker.",
}),
sentDuration: prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "sent_sns_duration_seconds",
Help: "Duration of sns send calls to the pulsar broker.",
},
),
}
}
// Describe describe metrics
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
e.receivedSns.Describe(ch)
e.sendSns.Describe(ch)
e.failedSns.Describe(ch)
e.sentDuration.Describe(ch)
}
// Collect collect metrics
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
e.mutex.Lock() // To protect metrics from concurrent collects.
defer e.mutex.Unlock()
e.receivedSns.Collect(ch)
e.sendSns.Collect(ch)
e.failedSns.Collect(ch)
e.sentDuration.Collect(ch)
}