/
unit.go
51 lines (41 loc) · 1.12 KB
/
unit.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
package grafana
import (
"log"
"os"
"gopkg.in/yaml.v3"
)
type Metric struct {
Metric string `yaml:"metric"`
OntapUnit string `yaml:"ontapUnit"`
GrafanaJSON string `yaml:"grafanaJson"`
GrafanaDisplay string `yaml:"grafanaDisplay"`
Comment string `yaml:"comment"`
skipValidate bool
}
func parseUnits() map[string]Metric {
excludeValidationMap := map[string]struct{}{
"svm_nfs_read_throughput": {},
"svm_nfs_throughput": {},
"svm_nfs_write_throughput": {},
}
filePath := "units.yaml"
// Read the YAML file
yamlData, err := os.ReadFile(filePath)
if err != nil {
log.Fatalf("Failed to read YAML file: %v", err)
}
var metrics []Metric
// Unmarshal the YAML data into the metrics slice
err = yaml.Unmarshal(yamlData, &metrics)
if err != nil {
log.Fatalf("Failed to unmarshal YAML: %v", err)
}
// Create a map to store the metrics
metricsMap := make(map[string]Metric)
// Populate the map using the metric name as the key
for _, metric := range metrics {
_, metric.skipValidate = excludeValidationMap[metric.Metric]
metricsMap[metric.Metric] = metric
}
return metricsMap
}