github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/common/monitor/stream.go (about) 1 package monitor 2 3 import ( 4 "github.com/go-kit/kit/metrics" 5 "github.com/go-kit/kit/metrics/discard" 6 "github.com/go-kit/kit/metrics/prometheus" 7 stdprometheus "github.com/prometheus/client_golang/prometheus" 8 ) 9 10 // StreamMetrics is the struct of metric in stream module 11 type StreamMetrics struct { 12 CacheSize metrics.Gauge 13 } 14 15 // DefaultStreamMetrics returns Metrics build using Prometheus client library if Prometheus is enabled 16 // Otherwise, it returns no-op Metrics 17 func DefaultStreamMetrics(config *prometheusConfig) *StreamMetrics { 18 if config.Prometheus { 19 return NewStreamMetrics() 20 } 21 return NopStreamMetrics() 22 } 23 24 // NewStreamMetrics returns a pointer of a new StreamMetrics object 25 func NewStreamMetrics(labelsAndValues ...string) *StreamMetrics { 26 var labels []string 27 for i := 0; i < len(labelsAndValues); i += 2 { 28 labels = append(labels, labelsAndValues[i]) 29 } 30 return &StreamMetrics{ 31 CacheSize: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 32 Namespace: xNameSpace, 33 Subsystem: streamSubSystem, 34 Name: "cache_size", 35 Help: "the excuting cache queue size in stream module.", 36 }, labels).With(labelsAndValues...), 37 } 38 } 39 40 // NopStreamMetrics returns a pointer of no-op Metrics 41 func NopStreamMetrics() *StreamMetrics { 42 return &StreamMetrics{ 43 //PulsarSendNum: discard.NewGauge(), 44 CacheSize: discard.NewGauge(), 45 } 46 }