Пример #1
0
func main() {
	listenAddr := flag.String("listen", ":6343", "Listening address for sFlow datagrams")
	flag.DurationVar(&window, "window", window, "How long to aggregate counters before resetting")

	flag.Parse()

	datagrams, err := udpchan.Listen(*listenAddr, nil)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Listening on", *listenAddr)

	go func() {
		for _ = range time.Tick(window) {
			printTopTalkers()
			resetTopTalkers()
		}
	}()

	for datagram := range datagrams {
		decodedDgram := sflow.Decode(datagram)
		for _, sample := range decodedDgram.Samples {
			if sample.SampleType() == sflow.TypeFlowSample {
				analyzeFlowSample(sample.(sflow.FlowSample))
			}
		}
	}
}
Пример #2
0
func main() {
	c, err := udpchan.Listen(":6343", nil)
	if err != nil {
		fmt.Println(err)
		return
	}

	for buf := range c {
		printDatagram(buf)
	}
}