Skip to content

Commit

Permalink
add ip telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinssgh committed Aug 15, 2023
1 parent fe41206 commit c7a9bff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions zetaclient/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c7a9bff

Please sign in to comment.