Collector-specific configuration. LIKWID collector derives metrics itself, Run once CLI option

This commit is contained in:
Thomas Roehl
2021-11-25 14:04:03 +01:00
parent 57948e8cff
commit 51b8c62d4d
14 changed files with 981 additions and 381 deletions

View File

@@ -6,20 +6,32 @@ import (
"strconv"
"strings"
"time"
"encoding/json"
)
const LOADAVGFILE = `/proc/loadavg`
type LoadavgCollectorConfig struct {
ExcludeMetrics []string `json:"exclude_metrics, omitempty"`
}
type LoadavgCollector struct {
MetricCollector
tags map[string]string
load_matches []string
proc_matches []string
config LoadavgCollectorConfig
}
func (m *LoadavgCollector) Init() error {
func (m *LoadavgCollector) Init(config []byte) error {
m.name = "LoadavgCollector"
m.setup()
if len(config) > 0 {
err := json.Unmarshal(config, &m.config)
if err != nil {
return err
}
}
m.tags = map[string]string{"type": "node"}
m.load_matches = []string{"load_one", "load_five", "load_fifteen"}
m.proc_matches = []string{"proc_run", "proc_total"}
@@ -28,7 +40,10 @@ func (m *LoadavgCollector) Init() error {
}
func (m *LoadavgCollector) Read(interval time.Duration, out *[]lp.MutableMetric) {
var skip bool
if !m.init {
return
}
buffer, err := ioutil.ReadFile(string(LOADAVGFILE))
if err != nil {
@@ -39,8 +54,9 @@ func (m *LoadavgCollector) Read(interval time.Duration, out *[]lp.MutableMetric)
for i, name := range m.load_matches {
x, err := strconv.ParseFloat(ls[i], 64)
if err == nil {
_, skip = stringArrayContains(m.config.ExcludeMetrics, name)
y, err := lp.New(name, m.tags, map[string]interface{}{"value": float64(x)}, time.Now())
if err == nil {
if err == nil && !skip {
*out = append(*out, y)
}
}
@@ -49,8 +65,9 @@ func (m *LoadavgCollector) Read(interval time.Duration, out *[]lp.MutableMetric)
for i, name := range m.proc_matches {
x, err := strconv.ParseFloat(lv[i], 64)
if err == nil {
_, skip = stringArrayContains(m.config.ExcludeMetrics, name)
y, err := lp.New(name, m.tags, map[string]interface{}{"value": float64(x)}, time.Now())
if err == nil {
if err == nil && !skip {
*out = append(*out, y)
}
}