thomnico / sflow

sFlow v5 encoding and decoding in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sflow Circle CI GoDoc BSD License

An sFlow v5 encoding and decoding package for Go.

Usage

// 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 guarantees

API stability is not guaranteed. Vendoring or using a dependency manager is suggested.

Reporting issues

Bug reports are greatly appreciated. Please provide raw datagram dumps when possible.

License

BSD (see LICENSE)

About

sFlow v5 encoding and decoding in Go

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Go 100.0%