diff --git a/client/main.go b/client/main.go index c03989a91..fcc160e70 100644 --- a/client/main.go +++ b/client/main.go @@ -1,13 +1,35 @@ package main import ( + "net/http" + _ "net/http/pprof" "os" + "path/filepath" + + log "github.com/sirupsen/logrus" "github.com/netbirdio/netbird/client/cmd" ) func main() { + if err := os.Setenv("NB_LOG_MAX_SIZE_MB", "100"); err != nil { + log.Errorf("Failed setting log-size: %v", err) + } + if err := os.Setenv("NB_WINDOWS_PANIC_LOG", filepath.Join(os.Getenv("ProgramData"), "netbird", "netbird.err")); err != nil { + log.Errorf("Failed setting panic log path: %v", err) + } + + go startPprofServer() + if err := cmd.Execute(); err != nil { os.Exit(1) } } + +func startPprofServer() { + pprofAddr := "localhost:6969" + log.Infof("Starting pprof debugging server on %s", pprofAddr) + if err := http.ListenAndServe(pprofAddr, nil); err != nil { + log.Infof("pprof server failed: %v", err) + } +} diff --git a/client/server/server.go b/client/server/server.go index 106bdf32b..54fe9eda1 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -120,6 +120,35 @@ func (s *Server) Start() error { ctx, cancel := context.WithCancel(s.rootCtx) s.actCancel = cancel + go func() { + ticker := time.NewTicker(30 * time.Second) + defer ticker.Stop() + + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + if statusResp, err := s.Status(ctx, &proto.StatusRequest{GetFullPeerStatus: true}); err != nil { + log.Infof("Error getting status: %v", err) + } else if statusResp.FullStatus != nil { + log.Infof("Status --------") + for _, peer := range statusResp.FullStatus.Peers { + log.Infof("[Peer Connection] Name: %s, IP: %s, Key: %s, Connection Status: %s, Relayed: %v, RelayedAddress: %v, Last WireGuard Handshake: %v", + peer.Fqdn, + peer.IP, + peer.PubKey, + peer.ConnStatus, + peer.Relayed, + peer.RelayAddress, + peer.LastWireguardHandshake.AsTime().Format("15:04:05"), + ) + } + } + } + } + }() + // if configuration exists, we just start connections. if is new config we skip and set status NeedsLogin // on failure we return error to retry config, err := internal.UpdateConfig(s.latestConfigInput)