[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:
		
							parent
							
								
									6815f3b1db
								
							
						
					
					
						commit
						4551923d46
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -126,10 +126,16 @@ 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)
 | 
			
		||||
			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
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -71,10 +71,16 @@ 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)
 | 
			
		||||
		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
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user