Skip to content

Instantly share code, notes, and snippets.

@chetth
Last active October 6, 2016 08:36
Show Gist options
  • Save chetth/87b75e7bd547ca286f6a348f8b88f821 to your computer and use it in GitHub Desktop.
Save chetth/87b75e7bd547ca286f6a348f8b88f821 to your computer and use it in GitHub Desktop.
Print syslog request per sec.
package main
import (
"fmt"
"gopkg.in/mcuadros/go-syslog.v2"
"time"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
channel := make(syslog.LogPartsChannel)
handler := syslog.NewChannelHandler(channel)
server := syslog.NewServer()
server.SetFormat(syslog.RFC5424)
server.SetHandler(handler)
server.ListenUDP("0.0.0.0:514")
server.ListenTCP("0.0.0.0:514")
server.Boot()
go func(channel syslog.LogPartsChannel) {
i := 0
for logParts := range channel {
fmt.Println(logParts)
timer2 := time.NewTimer(time.Second)
go func() {
<-timer2.C
fmt.Println("Req/sec = ", i)
i = 0
}()
i = i + 1
}
}(channel)
server.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment