liuxiulin 1 month ago
parent
commit
77c350c835
1 changed files with 25 additions and 24 deletions
  1. 25 24
      services/mqttaccess/main.go

+ 25 - 24
services/mqttaccess/main.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"github.com/prometheus/client_golang/prometheus"
+	"net/http"
 	_ "net/http/pprof"
 	"sparrow/pkg/rpcs"
 	"sparrow/pkg/server"
@@ -12,13 +13,13 @@ var deviceMessageCount *prometheus.CounterVec
 
 func main() {
 
-	//go func() {
-	//	pprofPort := "6060"
-	//	server.Log.Infof("pprof server started at :%s/debug/pprof", pprofPort)
-	//	if err := http.ListenAndServe(":"+pprofPort, nil); err != nil {
-	//		server.Log.Errorf("pprof server failed: %v", err)
-	//	}
-	//}()
+	go func() {
+		pprofPort := "6060"
+		server.Log.Infof("pprof server started at :%s/debug/pprof", pprofPort)
+		if err := http.ListenAndServe(":"+pprofPort, nil); err != nil {
+			server.Log.Errorf("pprof server failed: %v", err)
+		}
+	}()
 
 	// init server
 	err := server.Init(rpcs.MQTTAccessName)
@@ -47,23 +48,23 @@ func main() {
 		return
 	}
 
-	//deviceOnlineMetric := &server.Metric{
-	//	ID:          "device_online_count",
-	//	Name:        "device_online_count",
-	//	Description: "MQTT Device Online Count",
-	//	Type:        "gauge",
-	//}
-	//recvMessageCount := &server.Metric{
-	//	ID:          "device_message_total",
-	//	Name:        "device_message_total",
-	//	Description: "device report message total count",
-	//	Type:        "counter_vec",
-	//	Args:        []string{"device_code"},
-	//}
-	//
-	//server.RegisterMetric(deviceOnlineMetric, recvMessageCount)
-	//deviceOnlineCount = deviceOnlineMetric.MetricCollector.(prometheus.Gauge)
-	//deviceMessageCount = recvMessageCount.MetricCollector.(*prometheus.CounterVec)
+	deviceOnlineMetric := &server.Metric{
+		ID:          "device_online_count",
+		Name:        "device_online_count",
+		Description: "MQTT Device Online Count",
+		Type:        "gauge",
+	}
+	recvMessageCount := &server.Metric{
+		ID:          "device_message_total",
+		Name:        "device_message_total",
+		Description: "device report message total count",
+		Type:        "counter_vec",
+		Args:        []string{"device_code"},
+	}
+
+	server.RegisterMetric(deviceOnlineMetric, recvMessageCount)
+	deviceOnlineCount = deviceOnlineMetric.MetricCollector.(prometheus.Gauge)
+	deviceMessageCount = recvMessageCount.MetricCollector.(*prometheus.CounterVec)
 	// start to run
 	err = server.Run()
 	if err != nil {