Add statistics printed out every minute
This commit is contained in:
parent
764203ea99
commit
dbcb695de4
21
knockr.go
21
knockr.go
@ -21,6 +21,8 @@ var (
|
|||||||
whitelist = make(map[string]int64)
|
whitelist = make(map[string]int64)
|
||||||
blacklist []string
|
blacklist []string
|
||||||
arguments *knockArguments
|
arguments *knockArguments
|
||||||
|
traffic_in int64
|
||||||
|
traffic_out int64
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -33,7 +35,15 @@ func main() {
|
|||||||
// Launch listeners
|
// Launch listeners
|
||||||
go listener(arguments.WhitelistPort, whitelist_handler)
|
go listener(arguments.WhitelistPort, whitelist_handler)
|
||||||
go listener(arguments.BlacklistPort, blacklist_handler)
|
go listener(arguments.BlacklistPort, blacklist_handler)
|
||||||
listener(arguments.GatewayPort, gateway_handler)
|
go listener(arguments.GatewayPort, gateway_handler)
|
||||||
|
stats()
|
||||||
|
}
|
||||||
|
|
||||||
|
func stats() {
|
||||||
|
for {
|
||||||
|
time.Sleep(60*time.Second)
|
||||||
|
fmt.Println("[STS] In ", traffic_in/1024, "KB, Out ", traffic_out/1024, "KB");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func listener(port int, listen_func func(c net.Conn)) {
|
func listener(port int, listen_func func(c net.Conn)) {
|
||||||
@ -163,7 +173,12 @@ func proxy(c net.Conn) {
|
|||||||
fmt.Println("[ERR] Proxy connection to server failed")
|
fmt.Println("[ERR] Proxy connection to server failed")
|
||||||
fmt.Println(" Error is ", err)
|
fmt.Println(" Error is ", err)
|
||||||
} else {
|
} else {
|
||||||
go io.Copy(c, ln)
|
// A bit of cluttery code for statistics purposes, sorry.
|
||||||
io.Copy(ln, c)
|
go func() {
|
||||||
|
delta_traffic_in, _ := io.Copy(c, ln)
|
||||||
|
traffic_in += delta_traffic_in
|
||||||
|
}()
|
||||||
|
delta_traffic_out, _ := io.Copy(ln, c)
|
||||||
|
traffic_out += delta_traffic_out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user