Change storage format

This commit is contained in:
Thomas Roehl
2021-10-04 15:23:43 +02:00
parent 8956ce7ad5
commit 558bbaba59
19 changed files with 874 additions and 283 deletions

View File

@@ -2,6 +2,7 @@ package collectors
import (
"fmt"
lp "github.com/influxdata/line-protocol"
"log"
"os/exec"
"strings"
@@ -12,15 +13,23 @@ const NUM_PROCS = 5
type TopProcsCollector struct {
MetricCollector
tags map[string]string
}
func (m *TopProcsCollector) Init() error {
m.name = "TopProcsCollector"
m.tags = map[string]string{"type": "node"}
m.setup()
command := exec.Command("ps", "-Ao", "comm", "--sort=-pcpu")
command.Wait()
_, err := command.Output()
if err == nil {
m.init = true
}
return nil
}
func (m *TopProcsCollector) Read(interval time.Duration) {
func (m *TopProcsCollector) Read(interval time.Duration, out *[]lp.MutableMetric) {
command := exec.Command("ps", "-Ao", "comm", "--sort=-pcpu")
command.Wait()
stdout, err := command.Output()
@@ -31,10 +40,15 @@ func (m *TopProcsCollector) Read(interval time.Duration) {
lines := strings.Split(string(stdout), "\n")
for i := 1; i < NUM_PROCS+1; i++ {
m.node[fmt.Sprintf("topproc%d", i)] = lines[i]
name := fmt.Sprintf("topproc%d", i)
y, err := lp.New(name, m.tags, map[string]interface{}{"value": string(lines[i])}, time.Now())
if err == nil {
*out = append(*out, y)
}
}
}
func (m *TopProcsCollector) Close() {
m.init = false
return
}