Browse Source

collect metrics by server

Abhishek Kondur 2 years ago
parent
commit
26f9c2525c
2 changed files with 9 additions and 6 deletions
  1. 2 2
      go.mod
  2. 7 4
      logic/metrics/metrics.go

+ 2 - 2
go.mod

@@ -29,7 +29,7 @@ require (
 require (
 require (
 	filippo.io/edwards25519 v1.0.0
 	filippo.io/edwards25519 v1.0.0
 	github.com/c-robinson/iplib v1.0.6
 	github.com/c-robinson/iplib v1.0.6
-	github.com/go-ping/ping v1.1.0
+	github.com/go-ping/ping v1.1.0 // indirect
 	github.com/posthog/posthog-go v0.0.0-20211028072449-93c17c49e2b0
 	github.com/posthog/posthog-go v0.0.0-20211028072449-93c17c49e2b0
 )
 )
 
 
@@ -43,7 +43,7 @@ require (
 )
 )
 
 
 require (
 require (
-	github.com/gravitl/netclient v0.0.0-20230111052236-026a8d6b2a76
+	github.com/gravitl/netclient v0.0.0-20230111161447-b0ba3981a25f
 	github.com/guumaster/tablewriter v0.0.10
 	github.com/guumaster/tablewriter v0.0.10
 	github.com/matryer/is v1.4.0
 	github.com/matryer/is v1.4.0
 	github.com/olekukonko/tablewriter v0.0.5
 	github.com/olekukonko/tablewriter v0.0.5

+ 7 - 4
logic/metrics/metrics.go

@@ -11,7 +11,7 @@ import (
 )
 )
 
 
 // Collect - collects metrics
 // Collect - collects metrics
-func Collect(iface, network string, proxy bool, peerMap models.PeerMap) (*models.Metrics, error) {
+func Collect(iface, server, network string, proxy bool, peerMap models.PeerMap) (*models.Metrics, error) {
 	var metrics models.Metrics
 	var metrics models.Metrics
 	metrics.Connectivity = make(map[string]models.Metric)
 	metrics.Connectivity = make(map[string]models.Metric)
 	var wgclient, err = wgctrl.New()
 	var wgclient, err = wgctrl.New()
@@ -28,13 +28,16 @@ func Collect(iface, network string, proxy bool, peerMap models.PeerMap) (*models
 	// TODO handle freebsd??
 	// TODO handle freebsd??
 	for i := range device.Peers {
 	for i := range device.Peers {
 		currPeer := device.Peers[i]
 		currPeer := device.Peers[i]
+		if _, ok := peerMap[currPeer.PublicKey.String()]; !ok {
+			continue
+		}
 		id := peerMap[currPeer.PublicKey.String()].ID
 		id := peerMap[currPeer.PublicKey.String()].ID
 		address := peerMap[currPeer.PublicKey.String()].Address
 		address := peerMap[currPeer.PublicKey.String()].Address
 		if id == "" || address == "" {
 		if id == "" || address == "" {
 			logger.Log(0, "attempted to parse metrics for invalid peer from server", id, address)
 			logger.Log(0, "attempted to parse metrics for invalid peer from server", id, address)
 			continue
 			continue
 		}
 		}
-		proxyMetrics := proxy_metrics.GetMetric(currPeer.PublicKey.String())
+		proxyMetrics := proxy_metrics.GetMetric(server, currPeer.PublicKey.String())
 		var newMetric = models.Metric{
 		var newMetric = models.Metric{
 			NodeName: peerMap[currPeer.PublicKey.String()].Name,
 			NodeName: peerMap[currPeer.PublicKey.String()].Name,
 			IsServer: peerMap[currPeer.PublicKey.String()].IsServer,
 			IsServer: peerMap[currPeer.PublicKey.String()].IsServer,
@@ -60,9 +63,9 @@ func Collect(iface, network string, proxy bool, peerMap models.PeerMap) (*models
 		newMetric.TotalTime = 1
 		newMetric.TotalTime = 1
 		metrics.Connectivity[id] = newMetric
 		metrics.Connectivity[id] = newMetric
 		if len(proxyMetrics.NodeConnectionStatus) == 1 {
 		if len(proxyMetrics.NodeConnectionStatus) == 1 {
-			proxy_metrics.ResetMetricsForPeer(currPeer.PublicKey.String())
+			proxy_metrics.ResetMetricsForPeer(server, currPeer.PublicKey.String())
 		} else {
 		} else {
-			proxy_metrics.ResetMetricForNode(currPeer.PublicKey.String(), id)
+			proxy_metrics.ResetMetricForNode(server, currPeer.PublicKey.String(), id)
 		}
 		}
 	}
 	}