/
stream.go
46 lines (41 loc) · 1.32 KB
/
stream.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
package monitor
import (
"github.com/go-kit/kit/metrics"
"github.com/go-kit/kit/metrics/discard"
"github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
)
// StreamMetrics is the struct of metric in stream module
type StreamMetrics struct {
CacheSize metrics.Gauge
}
// DefaultStreamMetrics returns Metrics build using Prometheus client library if Prometheus is enabled
// Otherwise, it returns no-op Metrics
func DefaultStreamMetrics(config *prometheusConfig) *StreamMetrics {
if config.Prometheus {
return NewStreamMetrics()
}
return NopStreamMetrics()
}
// NewStreamMetrics returns a pointer of a new StreamMetrics object
func NewStreamMetrics(labelsAndValues ...string) *StreamMetrics {
var labels []string
for i := 0; i < len(labelsAndValues); i += 2 {
labels = append(labels, labelsAndValues[i])
}
return &StreamMetrics{
CacheSize: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: xNameSpace,
Subsystem: streamSubSystem,
Name: "cache_size",
Help: "the excuting cache queue size in stream module.",
}, labels).With(labelsAndValues...),
}
}
// NopStreamMetrics returns a pointer of no-op Metrics
func NopStreamMetrics() *StreamMetrics {
return &StreamMetrics{
//PulsarSendNum: discard.NewGauge(),
CacheSize: discard.NewGauge(),
}
}