-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmetric_config.go
53 lines (45 loc) · 1.07 KB
/
metric_config.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
package prometheus_client
import (
"fmt"
"strings"
"github.com/prometheus/client_golang/prometheus"
)
type promMetricConfig struct {
namespace string
name string
subsystem string
help string
labels []string
}
func (m *promMetricConfig) hasLabels() bool {
return len(m.labels) > 0
}
func (m *promMetricConfig) getKey() string {
return fmt.Sprintf("%s_%s_%s", m.namespace, m.subsystem, m.name)
}
func (m *promMetricConfig) equal(m2 *promMetricConfig) bool {
if m.getKey() != m2.getKey() {
return false
}
if (len(m.labels) != 0) && (len(m2.labels) != 0) {
// because labels sorted
return strings.Join(m.labels, "") == strings.Join(m2.labels, "")
}
return false
}
func (m *promMetricConfig) getGaugeOpts() prometheus.GaugeOpts {
return prometheus.GaugeOpts{
Namespace: m.namespace,
Subsystem: m.subsystem,
Name: m.name,
Help: m.help,
}
}
func (m *promMetricConfig) getCounterOpts() prometheus.CounterOpts {
return prometheus.CounterOpts{
Namespace: m.namespace,
Subsystem: m.subsystem,
Name: m.name,
Help: m.help,
}
}