Use GBytes as unit for large memory numbers

This commit is contained in:
Thomas Roehl 2022-03-09 11:05:26 +01:00
parent c0e600269a
commit e7f7e68095

View File

@ -37,6 +37,7 @@ type MemstatCollector struct {
matches map[string]string
config MemstatCollectorConfig
nodefiles map[int]MemstatCollectorNode
sendMemUsed bool
}
func getStats(filename string) map[string]float64 {
@ -77,7 +78,7 @@ func (m *MemstatCollector) Init(config json.RawMessage) error {
return err
}
}
m.meta = map[string]string{"source": m.name, "group": "Memory", "unit": "kByte"}
m.meta = map[string]string{"source": m.name, "group": "Memory", "unit": "GByte"}
m.stats = make(map[string]int64)
m.matches = make(map[string]string)
m.tags = map[string]string{"type": "node"}
@ -99,6 +100,10 @@ func (m *MemstatCollector) Init(config json.RawMessage) error {
m.matches[k] = v
}
}
m.sendMemUsed = false
if _, skip := stringArrayContains(m.config.ExcludeMetrics, "mem_used"); !skip {
m.sendMemUsed = true
}
if len(m.matches) == 0 {
return errors.New("no metrics to collect")
}
@ -152,25 +157,28 @@ func (m *MemstatCollector) Read(interval time.Duration, output chan lp.CCMetric)
if v, ok := stats[match]; ok {
value = v
}
y, err := lp.New(name, tags, m.meta, map[string]interface{}{"value": value}, time.Now())
y, err := lp.New(name, tags, m.meta, map[string]interface{}{"value": value * 1e-6}, time.Now())
if err == nil {
output <- y
}
}
if _, skip := stringArrayContains(m.config.ExcludeMetrics, "mem_used"); !skip {
if m.sendMemUsed {
memUsed := 0.0
if totalVal, total := stats["MemTotal"]; total {
if freeVal, free := stats["MemFree"]; free {
if bufVal, buffers := stats["Buffers"]; buffers {
if cacheVal, cached := stats["Cached"]; cached {
memUsed := stats["MemTotal"] - (freeVal + bufVal + cacheVal)
y, err := lp.New("mem_used", tags, m.meta, map[string]interface{}{"value": memUsed}, time.Now())
memUsed = totalVal - (freeVal + bufVal + cacheVal)
}
}
}
}
y, err := lp.New("mem_used", tags, m.meta, map[string]interface{}{"value": memUsed * 1e-6}, time.Now())
if err == nil {
output <- y
}
}
}
}
}
}
if m.config.NodeStats {
nodestats := getStats(MEMSTATFILE)