Skip to content

Commit

Permalink
[BUGFIX] use available memory for usage estimation
Browse files Browse the repository at this point in the history
Fix memory usage estimation following this commit:
freifunk-gluon/gluon#1517
  • Loading branch information
skorpy2009 committed Aug 25, 2018
1 parent 6815f3b commit 07f48ab
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion data/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ type Memory struct {
Cached int64 `json:"cached"`
Total int64 `json:"total"`
Buffers int64 `json:"buffers"`
Free int64 `json:"free"`
Free int64 `json:"free,omitempty"`
Available int64 `json:"available,omitempty"`
}

// SwitchPort struct
Expand Down
1 change: 1 addition & 0 deletions database/graphite/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (c *Connection) InsertNode(node *runtime.Node) {
addField("memory.cached", stats.Memory.Cached)
addField("memory.free", stats.Memory.Free)
addField("memory.total", stats.Memory.Total)
addField("memory.available", stats.Memory.Available)

c.addPoint(fields)
}
1 change: 1 addition & 0 deletions database/influxdb/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
"memory.cached": stats.Memory.Cached,
"memory.free": stats.Memory.Free,
"memory.total": stats.Memory.Total,
"memory.available": stats.Memory.Available,
}

if nodeinfo := node.Nodeinfo; nodeinfo != nil {
Expand Down
9 changes: 7 additions & 2 deletions output/meshviewer-ffrgb/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,15 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
/* The Meshviewer could not handle absolute memory output
* calc the used memory as a float which 100% equal 1.0
* 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 {
usage := 1 - (float64(statistic.Memory.Free)+float64(statistic.Memory.Buffers)+float64(statistic.Memory.Cached))/float64(statistic.Memory.Total)
if statistic.Memory.Available > 0 {
usage := 1 - float64(statistic.Memory.Available)/float64(statistic.Memory.Total)
} else {
usage := 1 - (float64(stats.Memory.Free)+float64(stats.Memory.Buffers)+float64(stats.Memory.Cached))/float64(stats.Memory.Total)
}
node.MemoryUsage = &usage
}

Expand Down
9 changes: 7 additions & 2 deletions output/meshviewer/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ func NewStatistics(stats *data.Statistics, isOnline bool) *Statistics {
/* The Meshviewer could not handle absolute memory output
* calc the used memory as a float which 100% equal 1.0
* 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 {
usage := 1 - (float64(stats.Memory.Free)+float64(stats.Memory.Buffers)+float64(stats.Memory.Cached))/float64(stats.Memory.Total)
if statistic.Memory.Available > 0 {
usage := 1 - float64(statistic.Memory.Available)/float64(statistic.Memory.Total)
} else {
usage := 1 - (float64(stats.Memory.Free)+float64(stats.Memory.Buffers)+float64(stats.Memory.Cached))/float64(stats.Memory.Total)
}
output.MemoryUsage = &usage
}

Expand Down

0 comments on commit 07f48ab

Please sign in to comment.