mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 04:27:25 +01:00
Use GBytes as unit for large memory numbers
This commit is contained in:
parent
c0e600269a
commit
e7f7e68095
@ -32,11 +32,12 @@ type MemstatCollectorNode struct {
|
|||||||
|
|
||||||
type MemstatCollector struct {
|
type MemstatCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
stats map[string]int64
|
stats map[string]int64
|
||||||
tags map[string]string
|
tags map[string]string
|
||||||
matches map[string]string
|
matches map[string]string
|
||||||
config MemstatCollectorConfig
|
config MemstatCollectorConfig
|
||||||
nodefiles map[int]MemstatCollectorNode
|
nodefiles map[int]MemstatCollectorNode
|
||||||
|
sendMemUsed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStats(filename string) map[string]float64 {
|
func getStats(filename string) map[string]float64 {
|
||||||
@ -77,7 +78,7 @@ func (m *MemstatCollector) Init(config json.RawMessage) error {
|
|||||||
return err
|
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.stats = make(map[string]int64)
|
||||||
m.matches = make(map[string]string)
|
m.matches = make(map[string]string)
|
||||||
m.tags = map[string]string{"type": "node"}
|
m.tags = map[string]string{"type": "node"}
|
||||||
@ -99,6 +100,10 @@ func (m *MemstatCollector) Init(config json.RawMessage) error {
|
|||||||
m.matches[k] = v
|
m.matches[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.sendMemUsed = false
|
||||||
|
if _, skip := stringArrayContains(m.config.ExcludeMetrics, "mem_used"); !skip {
|
||||||
|
m.sendMemUsed = true
|
||||||
|
}
|
||||||
if len(m.matches) == 0 {
|
if len(m.matches) == 0 {
|
||||||
return errors.New("no metrics to collect")
|
return errors.New("no metrics to collect")
|
||||||
}
|
}
|
||||||
@ -152,23 +157,26 @@ func (m *MemstatCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
if v, ok := stats[match]; ok {
|
if v, ok := stats[match]; ok {
|
||||||
value = v
|
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 {
|
if err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, skip := stringArrayContains(m.config.ExcludeMetrics, "mem_used"); !skip {
|
if m.sendMemUsed {
|
||||||
if freeVal, free := stats["MemFree"]; free {
|
memUsed := 0.0
|
||||||
if bufVal, buffers := stats["Buffers"]; buffers {
|
if totalVal, total := stats["MemTotal"]; total {
|
||||||
if cacheVal, cached := stats["Cached"]; cached {
|
if freeVal, free := stats["MemFree"]; free {
|
||||||
memUsed := stats["MemTotal"] - (freeVal + bufVal + cacheVal)
|
if bufVal, buffers := stats["Buffers"]; buffers {
|
||||||
y, err := lp.New("mem_used", tags, m.meta, map[string]interface{}{"value": memUsed}, time.Now())
|
if cacheVal, cached := stats["Cached"]; cached {
|
||||||
if err == nil {
|
memUsed = totalVal - (freeVal + bufVal + cacheVal)
|
||||||
output <- y
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
y, err := lp.New("mem_used", tags, m.meta, map[string]interface{}{"value": memUsed * 1e-6}, time.Now())
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user