[BUGFIX] use available memory for usage estimation

Fix memory usage estimation following this commit:
https://github.com/freifunk-gluon/gluon/pull/1517
This commit is contained in:
skorpy 2018-08-25 01:17:52 +02:00 committed by Geno
parent 6815f3b1db
commit 4551923d46
5 changed files with 35 additions and 20 deletions

View File

@ -87,7 +87,8 @@ type Memory struct {
Cached int64 `json:"cached"` Cached int64 `json:"cached"`
Total int64 `json:"total"` Total int64 `json:"total"`
Buffers int64 `json:"buffers"` Buffers int64 `json:"buffers"`
Free int64 `json:"free"` Free int64 `json:"free,omitempty"`
Available int64 `json:"available,omitempty"`
} }
// SwitchPort struct // SwitchPort struct

View File

@ -104,6 +104,7 @@ func (c *Connection) InsertNode(node *runtime.Node) {
addField("memory.cached", stats.Memory.Cached) addField("memory.cached", stats.Memory.Cached)
addField("memory.free", stats.Memory.Free) addField("memory.free", stats.Memory.Free)
addField("memory.total", stats.Memory.Total) addField("memory.total", stats.Memory.Total)
addField("memory.available", stats.Memory.Available)
c.addPoint(fields) c.addPoint(fields)
} }

View File

@ -45,6 +45,7 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
"memory.cached": stats.Memory.Cached, "memory.cached": stats.Memory.Cached,
"memory.free": stats.Memory.Free, "memory.free": stats.Memory.Free,
"memory.total": stats.Memory.Total, "memory.total": stats.Memory.Total,
"memory.available": stats.Memory.Available,
} }
if nodeinfo := node.Nodeinfo; nodeinfo != nil { if nodeinfo := node.Nodeinfo; nodeinfo != nil {

View File

@ -126,10 +126,16 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
/* The Meshviewer could not handle absolute memory output /* The Meshviewer could not handle absolute memory output
* calc the used memory as a float which 100% equal 1.0 * calc the used memory as a float which 100% equal 1.0
* calc is coppied from node statuspage (look discussion: * calc is coppied from node statuspage (look discussion:
* https://github.com/FreifunkBremen/yanic/issues/35) * https://github.com/FreifunkBremen/yanic/issues/35 and
* https://github.com/freifunk-gluon/gluon/pull/1517)
*/ */
if statistic.Memory.Total > 0 { if statistic.Memory.Total > 0 {
usage := 1 - (float64(statistic.Memory.Free)+float64(statistic.Memory.Buffers)+float64(statistic.Memory.Cached))/float64(statistic.Memory.Total) usage := 0.0
if statistic.Memory.Available > 0 {
usage = 1 - float64(statistic.Memory.Available)/float64(statistic.Memory.Total)
} else {
usage = 1 - (float64(statistic.Memory.Free)+float64(statistic.Memory.Buffers)+float64(statistic.Memory.Cached))/float64(statistic.Memory.Total)
}
node.MemoryUsage = &usage node.MemoryUsage = &usage
} }

View File

@ -71,10 +71,16 @@ func NewStatistics(stats *data.Statistics, isOnline bool) *Statistics {
/* The Meshviewer could not handle absolute memory output /* The Meshviewer could not handle absolute memory output
* calc the used memory as a float which 100% equal 1.0 * calc the used memory as a float which 100% equal 1.0
* calc is coppied from node statuspage (look discussion: * calc is coppied from node statuspage (look discussion:
* https://github.com/FreifunkBremen/yanic/issues/35) * https://github.com/FreifunkBremen/yanic/issues/35 and
* https://github.com/freifunk-gluon/gluon/pull/1517)
*/ */
if stats.Memory.Total > 0 { if stats.Memory.Total > 0 {
usage := 1 - (float64(stats.Memory.Free)+float64(stats.Memory.Buffers)+float64(stats.Memory.Cached))/float64(stats.Memory.Total) usage := 0.0
if stats.Memory.Available > 0 {
usage = 1 - float64(stats.Memory.Available)/float64(stats.Memory.Total)
} else {
usage = 1 - (float64(stats.Memory.Free)+float64(stats.Memory.Buffers)+float64(stats.Memory.Cached))/float64(stats.Memory.Total)
}
output.MemoryUsage = &usage output.MemoryUsage = &usage
} }