An sFlow v5 encoding and decoding package for Go.
// Create a new decoder that reads from an io.Reader.
d := sflow.NewDecoder(r)
// Attempt to decode an sFlow datagram.
dgram, err := d.Decode()
if err != nil {
log.Println(err)
return
}
for _, sample := range dgram.Samples {
// Sample is an interface type
if sample.SampleType() == sflow.TypeCounterSample {
counterSample := sample.(sflow.CounterSample)
for _, record := range counterSample.Records {
// While there is a record.RecordType() method,
// you can always check types directly.
switch record.(type) {
case sflow.HostDiskCounters:
fmt.Printf("Max used percent of disk space is %d.\n",
record.MaxUsedPercent)
}
}
}
}
API stability is not guaranteed. Vendoring or using a dependency manager is suggested.
Bug reports are greatly appreciated. Please provide raw datagram dumps when possible.
BSD (see LICENSE)