[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
					
				@ -84,10 +84,11 @@ type DHCP struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Memory struct
 | 
					// Memory struct
 | 
				
			||||||
type Memory struct {
 | 
					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
 | 
				
			||||||
 | 
				
			|||||||
@ -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)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,18 +33,19 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
 | 
				
			|||||||
	tags.SetString("nodeid", stats.NodeID)
 | 
						tags.SetString("nodeid", stats.NodeID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fields := models.Fields{
 | 
						fields := models.Fields{
 | 
				
			||||||
		"load":           stats.LoadAverage,
 | 
							"load":             stats.LoadAverage,
 | 
				
			||||||
		"time.up":        int64(stats.Uptime),
 | 
							"time.up":          int64(stats.Uptime),
 | 
				
			||||||
		"time.idle":      int64(stats.Idletime),
 | 
							"time.idle":        int64(stats.Idletime),
 | 
				
			||||||
		"proc.running":   stats.Processes.Running,
 | 
							"proc.running":     stats.Processes.Running,
 | 
				
			||||||
		"clients.wifi":   stats.Clients.Wifi,
 | 
							"clients.wifi":     stats.Clients.Wifi,
 | 
				
			||||||
		"clients.wifi24": stats.Clients.Wifi24,
 | 
							"clients.wifi24":   stats.Clients.Wifi24,
 | 
				
			||||||
		"clients.wifi5":  stats.Clients.Wifi5,
 | 
							"clients.wifi5":    stats.Clients.Wifi5,
 | 
				
			||||||
		"clients.total":  stats.Clients.Total,
 | 
							"clients.total":    stats.Clients.Total,
 | 
				
			||||||
		"memory.buffers": stats.Memory.Buffers,
 | 
							"memory.buffers":   stats.Memory.Buffers,
 | 
				
			||||||
		"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 {
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user