From 400993f22e5b02ecfded7fbada4a67191cabca7e Mon Sep 17 00:00:00 2001 From: xtaci Date: Wed, 1 Jun 2016 10:52:12 +0800 Subject: [PATCH] send -SIGUSR1 to dump KCP snmp --- client/main.go | 15 +++++++++++++++ server/main.go | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/client/main.go b/client/main.go index 683e1eb..f6f06de 100644 --- a/client/main.go +++ b/client/main.go @@ -6,6 +6,8 @@ import ( "math/rand" "net" "os" + "os/signal" + "syscall" "time" "github.com/hashicorp/yamux" @@ -50,6 +52,7 @@ func checkError(err error) { func main() { rand.Seed(int64(time.Now().Nanosecond())) + go sig_handler() myApp := cli.NewApp() myApp.Name = "kcptun" myApp.Usage = "kcptun client" @@ -178,3 +181,15 @@ func main() { } myApp.Run(os.Args) } + +func sig_handler() { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGUSR1) + + for { + switch <-ch { + case syscall.SIGUSR1: + log.Printf("KCP SNMP:%+v", kcp.DefaultSnmp.Copy()) + } + } +} diff --git a/server/main.go b/server/main.go index 0c8afdb..235c55b 100644 --- a/server/main.go +++ b/server/main.go @@ -6,6 +6,8 @@ import ( "math/rand" "net" "os" + "os/signal" + "syscall" "time" "github.com/hashicorp/yamux" @@ -78,6 +80,7 @@ func handleClient(p1, p2 net.Conn) { func main() { rand.Seed(int64(time.Now().Nanosecond())) + go sig_handler() myApp := cli.NewApp() myApp.Name = "kcptun" myApp.Usage = "kcptun server" @@ -175,3 +178,14 @@ func main() { } myApp.Run(os.Args) } +func sig_handler() { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGUSR1) + + for { + switch <-ch { + case syscall.SIGUSR1: + log.Printf("KCP SNMP:%+v", kcp.DefaultSnmp.Copy()) + } + } +}