Пример #1
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)
		}
	}
}
Пример #2
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))
			}
		}
	}
}