func main() { a := agent.New() h := newMovingAvgHandler(a) a.Handler = h log.Println("Starting agent") a.Start() err := a.Wait() if err != nil { log.Fatal(err) } }
func main() { a := agent.New(os.Stdin, os.Stdout) h := newOutlierHandler(a) a.Handler = h log.Println("Starting agent") a.Start() err := a.Wait() if err != nil { log.Fatal(err) } }
func main() { // Parse flags flag.Parse() // Setup logging log.SetOutput(wlog.NewWriter(os.Stderr)) if err := wlog.SetLevelFromName(*logLevel); err != nil { log.Fatal("E! ", err) } if *socket == "" { a := agent.New(os.Stdin, os.Stdout) h := newHandler(a) a.Handler = h log.Println("I! Starting agent using STDIN/STDOUT") a.Start() err := a.Wait() if err != nil { log.Fatal("E! ", err) } log.Println("I! Agent finished") } else { // Create unix socket addr, err := net.ResolveUnixAddr("unix", *socket) if err != nil { log.Fatal("E! ", err) } l, err := net.ListenUnix("unix", addr) if err != nil { log.Fatal("E! ", err) } // Create server that listens on the socket s := agent.NewServer(l, &accepter{}) // Setup signal handler to stop Server on various signals s.StopOnSignals(os.Interrupt, syscall.SIGTERM) log.Println("I! Socket server listening on", addr.String()) err = s.Serve() if err != nil { log.Fatal("E! ", err) } log.Println("I! Socket server stopped") } }
// Create a new agent/handler for each new connection. // Count and log each new connection and termination. func (acc *accpeter) Accept(conn net.Conn) { count := acc.count acc.count++ a := agent.New(conn, conn) h := newSkylineHandler(a) a.Handler = h log.Println("Starting agent for connection", count) a.Start() go func() { err := a.Wait() if err != nil { log.Fatal(err) } log.Printf("Agent for connection %d finished", count) }() }
// Create a new agent/handler for each new connection. // Count and log each new connection and termination. func (acc *accepter) Accept(conn net.Conn) { count := acc.count acc.count++ a := agent.New(conn, conn) h := newHandler(a) a.Handler = h log.Println("I! Starting agent for connection", count) a.Start() go func() { err := a.Wait() if err != nil { log.Printf("E! Agent for connection %d terminated with error: %s", count, err) } else { log.Printf("I! Agent for connection %d finished", count) } }() }