package main import ( "fmt" "github.com/gliderlabs/ssh" "net/http" "log" ) var( metrics_num_passwords int ) func main() { log.Println("Starting SSH listener") go func() { listenErr := ssh.ListenAndServe(":2222", nil, ssh.PasswordAuth(handlePass)) if listenErr != nil { log.Fatalln(listenErr.Error()) } }() log.Println("Starting HTTP metrics listener") http.HandleFunc("/metrics", metricsHandler) listenErr := http.ListenAndServe(":8080", nil) if listenErr != nil { log.Fatalln(listenErr.Error()) } } // Handling incoming SSH connections func handlePass(ctx ssh.Context, pass string) bool { metrics_num_passwords++ log.Printf("%s@%s: '%s'", ctx.User(), ctx.RemoteAddr().String(), pass) return false } // Handle HTTP /metrics requests func metricsHandler(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "num_passwords %d\n", metrics_num_passwords) }