Merge branch 'main' of github.com:ClusterCockpit/cc-metric-collector into main

This commit is contained in:
Thomas Roehl 2021-03-19 17:21:05 +01:00
commit 6fbaf21841
2 changed files with 155 additions and 155 deletions

View File

@ -4,14 +4,17 @@ import (
"fmt"
"os"
"os/exec"
//"bytes"
// "context"
"encoding/json"
"path/filepath"
//"sort"
"errors"
"strings"
"time"
"errors"
protocol "github.com/influxdata/line-protocol"
)
@ -81,7 +84,6 @@ func LoadCollectorConfiguration(file string, config *CollectorConfig) error {
return err
}
//////////////////////////////////////////////////////////////////////////////
// Load collector configurations
//////////////////////////////////////////////////////////////////////////////
@ -109,7 +111,6 @@ func GetCollectorFolders(root string, folders *[]string) error {
return err
}
//////////////////////////////////////////////////////////////////////////////
// Setup all collectors
//////////////////////////////////////////////////////////////////////////////
@ -132,7 +133,6 @@ func SetupCollectors(config GlobalConfig) ([]InternalCollectorConfig, error) {
return outconfig, nil
}
//////////////////////////////////////////////////////////////////////////////
// Run collector
//////////////////////////////////////////////////////////////////////////////
@ -143,7 +143,7 @@ func RunCollector(config InternalCollectorConfig) ([]string, error) {
if _, err = os.Stat(cmd); err != nil {
//fmt.Println(err.Error())
if ! strings.HasPrefix(cmd, "/") {
if !strings.HasPrefix(cmd, "/") {
cmd = filepath.Join(config.Location, config.Config.Command)
if _, err = os.Stat(cmd); err != nil {
//fmt.Println(err.Error())
@ -171,7 +171,9 @@ func RunCollector(config InternalCollectorConfig) ([]string, error) {
lines := strings.Split(string(stdout), "\n")
for _, l := range lines {
if strings.HasPrefix(l, "#") { continue }
if strings.HasPrefix(l, "#") {
continue
}
results = append(results, l)
}
return results, err
@ -188,16 +190,16 @@ func SetupSink(config GlobalConfig) chan string {
return c
}
func RunSink(config GlobalConfig, queue* chan string) (*time.Ticker, chan bool) {
var interval time.Duration
func RunSink(config GlobalConfig, queue *chan string) (*time.Ticker, chan bool) {
interval = time.Duration(config.Report.Interval) * time.Second
interval := time.Duration(config.Report.Interval) * time.Second
ticker := time.NewTicker(interval)
done := make(chan bool)
go func() {
for {
select {
case <- done:
case <-done:
return
case t := <-ticker.C:
fmt.Println("SinkTick at", t)
@ -205,7 +207,7 @@ func RunSink(config GlobalConfig, queue* chan string) (*time.Ticker, chan bool)
var batch []string
for empty == false {
select {
case metric := <- *queue:
case metric := <-*queue:
fmt.Println(metric)
batch = append(batch, metric)
default:
@ -229,19 +231,17 @@ func CloseSink(config GlobalConfig, queue *chan string, ticker *time.Ticker, don
close(*queue)
}
func MainLoop(config GlobalConfig, sink *chan string) (*time.Ticker, chan bool) {
var intConfig []InternalCollectorConfig
intConfig, err := SetupCollectors(config)
if err != nil {
panic(err)
}
var interval time.Duration
interval = time.Duration(config.Schedule.Node.Frequency) * time.Second
interval := time.Duration(config.Schedule.Node.Frequency) * time.Second
ticker := time.NewTicker(time.Second)
done := make(chan bool)
go func() {
for {
select {
@ -296,25 +296,25 @@ func main() {
collectDone <- true
CloseSink(config, &queue, sinkTicker, sinkDone)
// var folders []string
// GetCollectorFolders(config.CollectorPath, &folders)
// var folders []string
// GetCollectorFolders(config.CollectorPath, &folders)
// for _, path := range folders {
// var col_config CollectorConfig
// LoadCollectorConfiguration(filepath.Join(path, "config.json"), &col_config)
// stdout := run_cmd(filepath.Join(path, col_config.Command), col_config.Args)
// for _, path := range folders {
// var col_config CollectorConfig
// 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 {
// t := strings.Fields(m)
// if len(t) == 2 {
// var s strings.Builder
// fmt.Fprintf(&s, "%s %d", m, time.Now().UnixNano())
// m = s.String()
// }
// fmt.Println("SEND", m)
// }
// }
// }
// metrics := strings.Split(stdout, "\n")
// for _, m := range metrics {
// if len(m) > 0 {
// t := strings.Fields(m)
// if len(t) == 2 {
// var s strings.Builder
// fmt.Fprintf(&s, "%s %d", m, time.Now().UnixNano())
// m = s.String()
// }
// fmt.Println("SEND", m)
// }
// }
// }
}

0
collectors/memavg/read_memavg.go Executable file → Normal file
View File