+ c[opt.Name] = m.registerGauge(opt)
+ }
+
+ return
+}
+
+/*
+ * Handling counter vectors
+ *
+ * Example:
+
+ vec := Metric.RegisterCounterVecGroup(
+ []CounterOpts{
+ {Name: "counter1", Help: "counter1"},
+ {Name: "counter2", Help: "counter2"},
+ },
+ []string{"host"},
+ "SUBSYSTEM")
+
+ stat:=Metric.GetCounterGroupFromVects([]string{"localhost:8888"}, vec)
+
+*/
+type CounterVec struct {
+ Vec *prometheus.CounterVec
+ Opts CounterOpts
+}
+
+func (m *Metrics) registerCounterVec(opts CounterOpts, labelNames []string) *prometheus.CounterVec {
+ Logger.Info("Register new counter vector with opts: %v labelNames: %v", opts, labelNames)
+
+ return promauto.NewCounterVec(prometheus.CounterOpts(opts), labelNames)
+}
+
+func (m *Metrics) RegisterCounterVecGroup(opts []CounterOpts, labelNames []string, subsytem string) (c map[string]CounterVec) {
+ c = make(map[string]CounterVec)
+ for _, opt := range opts {
+ entry := CounterVec{}
+ entry.Opts = opt
+ entry.Opts.Namespace = m.Namespace
+ entry.Opts.Subsystem = subsytem
+ entry.Vec = m.registerCounterVec(entry.Opts, labelNames)
+ c[opt.Name] = entry
+ }
+ return
+}
+
+func (m *Metrics) GetCounterGroupFromVectsWithPrefix(prefix string, labels []string, vects ...map[string]CounterVec) (c map[string]Counter) {
+ c = make(map[string]Counter)
+ for _, vec := range vects {
+ for name, opt := range vec {
+ c[prefix+name] = opt.Vec.WithLabelValues(labels...)
+ Logger.Info("Register new counter for vector with opts: %v labels: %v", opt.Opts, labels)
+ }
+ }
+ return
+}
+
+func (m *Metrics) GetCounterGroupFromVects(labels []string, vects ...map[string]CounterVec) (c map[string]Counter) {
+ return m.GetCounterGroupFromVectsWithPrefix("", labels, vects...)
+}
+
+/*
+ * Handling gauge vectors
+ *
+ * Example:
+
+ vec := Metric.RegisterGaugeVecGroup(
+ []CounterOpts{
+ {Name: "gauge1", Help: "gauge1"},
+ {Name: "gauge2", Help: "gauge2"},
+ },
+ []string{"host"},
+ "SUBSYSTEM")
+
+ stat:=Metric.GetGaugeGroupFromVects([]string{"localhost:8888"},vec)
+
+*/
+type GaugeVec struct {
+ Vec *prometheus.GaugeVec
+ Opts CounterOpts
+}
+
+func (m *Metrics) registerGaugeVec(opts CounterOpts, labelNames []string) *prometheus.GaugeVec {
+ Logger.Info("Register new gauge vector with opts: %v labelNames: %v", opts, labelNames)
+
+ return promauto.NewGaugeVec(prometheus.GaugeOpts(opts), labelNames)
+}
+
+func (m *Metrics) RegisterGaugeVecGroup(opts []CounterOpts, labelNames []string, subsytem string) (c map[string]GaugeVec) {
+ c = make(map[string]GaugeVec)
+ for _, opt := range opts {
+ entry := GaugeVec{}
+ entry.Opts = opt
+ entry.Opts.Namespace = m.Namespace
+ entry.Opts.Subsystem = subsytem
+ entry.Vec = m.registerGaugeVec(entry.Opts, labelNames)
+ c[opt.Name] = entry
+