Reformat. Make Metrics a string array.

This commit is contained in:
Jan Eitzinger 2021-03-18 08:06:57 +01:00
parent 24c5a80585
commit 1815825206

View File

@ -4,15 +4,15 @@ import (
"fmt"
"os"
"os/exec"
// "context"
"encoding/json"
"path/filepath"
"sort"
"strings"
"time"
"sort"
"path/filepath"
"encoding/json"
)
type GlobalConfig struct {
Sink struct {
User string `json:"user"`
@ -34,7 +34,7 @@ type GlobalConfig struct {
Duration int `json:"duration"`
} `json:"node"`
} `json:"schedule"`
Metrics string `json:"metrics"`
Metrics []string `json:"metrics"`
CollectorPath string `json:"collector_path"`
}
@ -102,7 +102,7 @@ func CreatePoint(metricname string, tags map[string]string, fields map[string]in
taglist := SortStringStringMap(tags)
fieldlist := SortStringInterfaceMap(fields)
if (len(taglist) > 0) {
if len(taglist) > 0 {
fmt.Fprintf(&s, "%s,%s %s %d", metricname, strings.Join(taglist, ","), strings.Join(fieldlist, ","), timestamp)
} else {
fmt.Fprintf(&s, "%s %s %d", metricname, strings.Join(fieldlist, ","), timestamp)
@ -137,7 +137,7 @@ func GetSingleCollector(folders *[]string) filepath.WalkFunc {
if err != nil {
panic(err)
}
if (info.IsDir()) {
if info.IsDir() {
configfile := filepath.Join(path, "config.json")
if _, err := os.Stat(configfile); err == nil {
*folders = append(*folders, path)
@ -171,16 +171,15 @@ func main() {
// fmt.Println(CreatePoint("flops_any", tags, fields, time.Now().UnixNano()))
var config GlobalConfig
LoadGlobalConfiguration("config.json", &config)
// fmt.Println(config)
var folders []string
GetCollectorFolders(config.CollectorPath, &folders)
// fmt.Println(folders)
for _, path := range folders {
var col_config CollectorConfig
configfile := filepath.Join(path, "config.json")
LoadCollectorConfiguration(configfile, &col_config)
cmd := filepath.Join(path, col_config.Command)
stdout := run_cmd(cmd, col_config.Args)
LoadCollectorConfiguration(filepath.Join(path, "config.json"), &col_config)
stdout := run_cmd(filepath.Join(path, col_config.Command), col_config.Args)
metrics := strings.Split(stdout, "\n")
for _, m := range metrics {
if len(m) > 0 {
@ -193,7 +192,5 @@ func main() {
fmt.Println("SEND", m)
}
}
}
}