forked from muravsky/unity2promgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
59 lines (50 loc) · 1.42 KB
/
utils.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
)
func readConfig(configPath string) (Exporter, []Unity) {
// Open our jsonFile
jsonFile, err := os.Open(configPath)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
log.Print("Successfully opened", configPath)
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
var config Config
json.Unmarshal([]byte(byteValue), &config)
return config.Exporter, config.UnityClients
}
func readMetrics(metricsPath string) []Metric {
// Open our jsonFile
jsonFile, err := os.Open(metricsPath)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
log.Print("Successfully opened", metricsPath)
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
var metrics Metrics
json.Unmarshal([]byte(byteValue), &metrics)
return metrics.Metrics
}
//Config is an array containing RestAPI client information for all monitored Unity Arrays
type Config struct {
Exporter Exporter `json:"exporter"`
UnityClients []Unity `json:"unitys"`
}
//Exporter represents a single Unity RestAPI client
type Exporter struct {
Port string `json:"port"`
Interval int `json:"interval"`
Metrics []string `json:"metrics"`
Pools bool `json:"pools"`
LUN bool `json:"LUN"`
StorageResources bool `json:"storage_resources"`
}