diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index 2e3ac21ede..2ba51229a4 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -116,6 +116,7 @@ func start(_ *cobra.Command, _ []string) error { } }() + telemetryServer.SetIPAddress(cfg.PublicIP) tss, err := GenerateTss(masterLogger, cfg, zetaBridge, peers, priKey, telemetryServer) if err != nil { return err diff --git a/zetaclient/telemetry.go b/zetaclient/telemetry.go index 867c943a8b..baa51e4a50 100644 --- a/zetaclient/telemetry.go +++ b/zetaclient/telemetry.go @@ -27,6 +27,7 @@ type TelemetryServer struct { mu sync.Mutex lastStartTimestamp time.Time status types.Status + ipAddress string } // NewTelemetryServer should only listen to the loopback @@ -65,6 +66,19 @@ func (t *TelemetryServer) GetP2PID() string { return t.p2pid } +// setter/getter for p2pid +func (t *TelemetryServer) SetIPAddress(ip string) { + t.mu.Lock() + t.ipAddress = ip + t.mu.Unlock() +} + +func (t *TelemetryServer) GetIPAddress() string { + t.mu.Lock() + defer t.mu.Unlock() + return t.ipAddress +} + // setter for lastScanned block number func (t *TelemetryServer) SetLastScannedBlockNumber(chainID int64, blockNumber int64) { t.mu.Lock() @@ -106,6 +120,7 @@ func (t *TelemetryServer) Handlers() http.Handler { router.Handle("/laststarttimestamp", http.HandlerFunc(t.lastStartTimestampHandler)).Methods(http.MethodGet) router.Handle("/lastcoreblock", http.HandlerFunc(t.lastCoreBlockHandler)).Methods(http.MethodGet) router.Handle("/status", http.HandlerFunc(t.statusHandler)).Methods(http.MethodGet) + router.Handle("/ip", http.HandlerFunc(t.ipHandler)).Methods(http.MethodGet) // router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine")) // router.Handle("/debug/pprof/heap", pprof.Handler("heap")) // router.HandleFunc("/debug/pprof/", pprof.Index) @@ -164,6 +179,13 @@ func (t *TelemetryServer) p2pHandler(w http.ResponseWriter, _ *http.Request) { fmt.Fprintf(w, "%s", t.p2pid) } +func (t *TelemetryServer) ipHandler(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + t.mu.Lock() + defer t.mu.Unlock() + fmt.Fprintf(w, "%s", t.ipAddress) +} + func (t *TelemetryServer) lastScannedBlockHandler(w http.ResponseWriter, _ *http.Request) { //w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json")