Example #1
0
// initOnlineNodesGauge counts all nodes with status Online and initializes the
// OnlineNode Gauge with it. It also register a callback with the database to be notified
// of nodes going offline.
func initOnlineNodesGauge(store data.Nodeinfostore) {
	OnlineNodes.Set(0.0)
	for _, status := range store.GetNodeStatusInfos() {
		if status.Online {
			OnlineNodes.Inc()
		}
	}
	store.NotifyNodeOffline(decrementOnlineNodes)
}
Example #2
0
// initTotalClientsGauge iterates over all statistics
// and sums up the clients if all online nodes.
func initTotalClientsGauge(store data.Nodeinfostore) {
	TotalClientCounter.Set(0.0)
	var totalClients int = 0
	for _, stats := range store.GetAllStatistics() {
		status, err := store.GetNodeStatusInfo(stats.NodeId)
		if err != nil {
			log.WithFields(log.Fields{
				"error":  err,
				"nodeId": stats.NodeId,
			}).Warn("Didn't found node status in store")
		}
		if status.Online {
			totalClients = totalClients + stats.Clients.Total
			TotalClientCounter.Add(float64(stats.Clients.Total))
		} else {
			log.Debugf("Node %s was offline", status.NodeId)
		}
	}
}
Example #3
0
// initTrafficCounter initialises the traffic counters with the accumulated traffic
// in all node statistics stored in the database at startup
func initTrafficCounter(store data.Nodeinfostore) {
	TotalNodeTrafficRx.Set(0.0)
	TotalNodeTrafficTx.Set(0.0)
	TotalNodeMgmtTrafficRx.Set(0.0)
	TotalNodeMgmtTrafficTx.Set(0.0)

	for _, stats := range store.GetAllStatistics() {
		if stats.Traffic != nil {
			if b := stats.Traffic.Rx; b != nil {
				TotalNodeTrafficRx.Add(float64(b.Bytes))
			}
			if b := stats.Traffic.Tx; b != nil {
				TotalNodeTrafficTx.Add(float64(b.Bytes))
			}
			if b := stats.Traffic.MgmtRx; b != nil {
				TotalNodeMgmtTrafficRx.Add(float64(b.Bytes))
			}
			if b := stats.Traffic.MgmtTx; b != nil {
				TotalNodeMgmtTrafficTx.Add(float64(b.Bytes))
			}
		}
	}
}
Example #4
0
// ProcessStoredValues needs to be called at startup as soon as the data store is
// ready. This methods takes care if initializing all Metrics with values based on
// the last saved values.
func ProcessStoredValues(store data.Nodeinfostore) {
	TotalNodes.Set(float64(len(store.GetNodeStatusInfos())))
	initTotalClientsGauge(store)
	initTrafficCounter(store)
	initOnlineNodesGauge(store)
}