+//
+//
+//
+func (m *Metrics) RegisterCounter(opts CounterOpts, subsytem string) Counter {
+ globalLock.Lock()
+ defer globalLock.Unlock()
+ opts.Namespace = m.Namespace
+ opts.Subsystem = subsytem
+ id := m.getFullName(prometheus.Opts(opts), []string{})
+ if _, ok := cache_allcountervects[id]; ok {
+ Logger.Warn("Register new counter with opts: %v, name conflicts existing counter vector", opts)
+ return nil
+ }
+ if _, ok := cache_allcounters[id]; !ok {
+ Logger.Debug("Register new counter with opts: %v", opts)
+ cache_allcounters[id] = promauto.NewCounter(prometheus.CounterOpts(opts))
+ }
+ return cache_allcounters[id]
+}
+
+//
+//
+//
+func (m *Metrics) RegisterCounterGroup(optsgroup []CounterOpts, subsytem string) map[string]Counter {
+ c := make(map[string]Counter)
+ for _, opts := range optsgroup {
+ c[opts.Name] = m.RegisterCounter(opts, subsytem)
+ }
+ return c
+}
+
+//
+//
+//
+func (m *Metrics) RegisterLabeledCounter(opts CounterOpts, labelNames []string, labelValues []string, subsytem string) Counter {
+ globalLock.Lock()
+ defer globalLock.Unlock()
+ opts.Namespace = m.Namespace
+ opts.Subsystem = subsytem
+ vecid := m.getFullName(prometheus.Opts(opts), []string{})
+ if _, ok := cache_allcounters[vecid]; ok {
+ Logger.Warn("Register new counter vector with opts: %v labelNames: %v, name conflicts existing counter", opts, labelNames)
+ return nil
+ }
+ if _, ok := cache_allcountervects[vecid]; !ok {
+ Logger.Debug("Register new counter vector with opts: %v labelNames: %v", opts, labelNames)
+ entry := CounterVec{}
+ entry.Opts = opts
+ entry.Labels = labelNames
+ entry.Vec = promauto.NewCounterVec(prometheus.CounterOpts(entry.Opts), entry.Labels)
+ cache_allcountervects[vecid] = entry
+ }
+ entry := cache_allcountervects[vecid]
+ if strSliceCompare(entry.Labels, labelNames) == false {
+ Logger.Warn("id:%s cached counter vec labels dont match %v != %v", vecid, entry.Labels, labelNames)
+ return nil
+ }
+ valid := m.getFullName(prometheus.Opts(entry.Opts), labelValues)
+ if _, ok := cache_allcounters[valid]; !ok {
+ Logger.Debug("Register new counter from vector with opts: %v labelValues: %v", entry.Opts, labelValues)
+ cache_allcounters[valid] = entry.Vec.WithLabelValues(labelValues...)
+ }
+ return cache_allcounters[valid]
+}
+
+//
+//
+//
+func (m *Metrics) RegisterLabeledCounterGroup(optsgroup []CounterOpts, labelNames []string, labelValues []string, subsytem string) map[string]Counter {
+ c := make(map[string]Counter)
+ for _, opts := range optsgroup {
+ c[opts.Name] = m.RegisterLabeledCounter(opts, labelNames, labelValues, subsytem)
+ }
+ return c
+}
+
+//
+//
+//
+func (m *Metrics) RegisterGauge(opts CounterOpts, subsytem string) Gauge {
+ globalLock.Lock()
+ defer globalLock.Unlock()
+ opts.Namespace = m.Namespace
+ opts.Subsystem = subsytem
+ id := m.getFullName(prometheus.Opts(opts), []string{})
+ if _, ok := cache_allgaugevects[id]; ok {
+ Logger.Warn("Register new gauge with opts: %v, name conflicts existing gauge vector", opts)
+ return nil
+ }
+ if _, ok := cache_allgauges[id]; !ok {
+ Logger.Debug("Register new gauge with opts: %v", opts)
+ cache_allgauges[id] = promauto.NewGauge(prometheus.GaugeOpts(opts))
+ }
+ return cache_allgauges[id]
+}
+
+//
+//
+//
+func (m *Metrics) RegisterGaugeGroup(optsgroup []CounterOpts, subsytem string) map[string]Gauge {
+ c := make(map[string]Gauge)
+ for _, opts := range optsgroup {
+ c[opts.Name] = m.RegisterGauge(opts, subsytem)
+ }
+ return c
+}
+
+//
+//
+//
+func (m *Metrics) RegisterLabeledGauge(opts CounterOpts, labelNames []string, labelValues []string, subsytem string) Gauge {
+ globalLock.Lock()
+ defer globalLock.Unlock()
+ opts.Namespace = m.Namespace
+ opts.Subsystem = subsytem
+ vecid := m.getFullName(prometheus.Opts(opts), []string{})
+ if _, ok := cache_allgauges[vecid]; ok {
+ Logger.Warn("Register new gauge vector with opts: %v labelNames: %v, name conflicts existing counter", opts, labelNames)
+ return nil
+ }
+ if _, ok := cache_allgaugevects[vecid]; !ok {
+ Logger.Debug("Register new gauge vector with opts: %v labelNames: %v", opts, labelNames)
+ entry := GaugeVec{}
+ entry.Opts = opts
+ entry.Labels = labelNames
+ entry.Vec = promauto.NewGaugeVec(prometheus.GaugeOpts(entry.Opts), entry.Labels)
+ cache_allgaugevects[vecid] = entry
+ }
+ entry := cache_allgaugevects[vecid]
+ if strSliceCompare(entry.Labels, labelNames) == false {
+ Logger.Warn("id:%s cached gauge vec labels dont match %v != %v", vecid, entry.Labels, labelNames)
+ return nil
+ }
+ valid := m.getFullName(prometheus.Opts(entry.Opts), labelValues)
+ if _, ok := cache_allgauges[valid]; !ok {
+ Logger.Debug("Register new gauge from vector with opts: %v labelValues: %v", entry.Opts, labelValues)
+ cache_allgauges[valid] = entry.Vec.WithLabelValues(labelValues...)
+ }
+ return cache_allgauges[valid]
+}
+
+//
+//
+//
+func (m *Metrics) RegisterLabeledGaugeGroup(optsgroup []CounterOpts, labelNames []string, labelValues []string, subsytem string) map[string]Gauge {
+ c := make(map[string]Gauge)
+ for _, opts := range optsgroup {
+ c[opts.Name] = m.RegisterLabeledGauge(opts, labelNames, labelValues, subsytem)