Add some more memory metrics to memstat collector

This commit is contained in:
Thomas Roehl 2021-05-12 18:09:15 +02:00
parent fd6f19ea07
commit 9b59429a93

View File

@ -45,8 +45,22 @@ func (m *MemstatCollector) Read(interval time.Duration) {
return return
} }
m.node["mem_total"] = float64(memstats[`MemTotal`]) * 1.0e-3
m.node["swap_total"] = float64(memstats[`SwapTotal`]) * 1.0e-3
m.node["mem_sreclaimable"] = float64(memstats[`SReclaimable`]) * 1.0e-3
m.node["mem_slab"] = float64(memstats[`Slab`]) * 1.0e-3
m.node["mem_free"] = float64(memstats[`MemFree`]) * 1.0e-3
m.node["mem_buffers"] = float64(memstats[`Buffers`]) * 1.0e-3
m.node["mem_cached"] = float64(memstats[`Cached`]) * 1.0e-3
m.node["mem_available"] = float64(memstats[`MemAvailable`]) * 1.0e-3
m.node["swap_free"] = float64(memstats[`SwapFree`]) * 1.0e-3
memUsed := memstats[`MemTotal`] - (memstats[`MemFree`] + memstats[`Buffers`] + memstats[`Cached`]) memUsed := memstats[`MemTotal`] - (memstats[`MemFree`] + memstats[`Buffers`] + memstats[`Cached`])
m.node["mem_used"] = float64(memUsed) * 1.0e-3 m.node["mem_used"] = float64(memUsed) * 1.0e-3
// In linux-2.5.52 when Memshared was removed
if _, found := memstats[`MemShared`]; found {
m.node["mem_shared"] = float64(memstats[`MemShared`]) * 1.0e-3
}
} }
func (m *MemstatCollector) Close() { func (m *MemstatCollector) Close() {