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