Browse Source

dump metrics

Abhishek Kondur 2 years ago
parent
commit
6712824763
1 changed files with 14 additions and 0 deletions
  1. 14 0
      metrics/metrics.go

+ 14 - 0
metrics/metrics.go

@@ -1,12 +1,18 @@
 package metrics
 
 import (
+	"encoding/json"
+	"os"
 	"sync"
 	"time"
 
 	"github.com/gravitl/netmaker/models"
 )
 
+func Init() {
+	go dumpMetrics()
+}
+
 // lock for metrics map
 var metricsMapLock = &sync.RWMutex{}
 
@@ -81,3 +87,11 @@ func ResetMetricForNode(server, peerKey, peerID string) {
 
 // MetricCollectionInterval - collection interval for metrics
 const MetricCollectionInterval = time.Second * 25
+
+func dumpMetrics() {
+	for {
+		time.Sleep(time.Second * 35)
+		d, _ := json.MarshalIndent(metricsPeerMap, "", " ")
+		os.WriteFile("/tmp/metrics.json", d, 0755)
+	}
+}