-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmetrics.go
75 lines (60 loc) · 1.36 KB
/
metrics.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
const (
MetricHelpDefault = "Azure monitor insight metric"
)
type (
MetricList struct {
List map[string][]MetricRow
Help map[string]string
}
MetricRow struct {
Labels prometheus.Labels
Value float64
}
)
func NewMetricList() *MetricList {
list := MetricList{}
list.List = map[string][]MetricRow{}
list.Help = map[string]string{}
return &list
}
func (l *MetricList) Add(name string, metric ...MetricRow) {
if _, ok := l.List[name]; !ok {
l.List[name] = []MetricRow{}
}
l.List[name] = append(l.List[name], metric...)
}
func (l *MetricList) GetMetricNames() (list []string) {
for name := range l.List {
list = append(list, name)
}
return
}
func (l *MetricList) SetMetricHelp(name, help string) {
l.Help[name] = help
}
func (l *MetricList) GetMetricHelp(name string) string {
if val, ok := l.Help[name]; ok {
return val
}
return MetricHelpDefault
}
func (l *MetricList) GetMetricList(name string) []MetricRow {
return l.List[name]
}
func (l *MetricList) GetMetricLabelNames(name string) []string {
var list []string
uniqueLabelMap := map[string]string{}
for _, row := range l.List[name] {
for labelName := range row.Labels {
uniqueLabelMap[labelName] = labelName
}
}
for labelName := range uniqueLabelMap {
list = append(list, labelName)
}
return list
}