send -SIGUSR1 to dump KCP snmp

This commit is contained in:
xtaci
2016-06-01 10:52:12 +08:00
parent 4d935d26a2
commit 400993f22e
2 changed files with 29 additions and 0 deletions
+15
View File
@@ -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())
}
}
}
+14
View File
@@ -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())
}
}
}