Skip to content

Cistern/sflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ed105e3 · Jun 22, 2024

History

97 Commits
Jun 21, 2024
Jun 22, 2024
Dec 10, 2015
Oct 29, 2014
Feb 3, 2016
May 29, 2015
Oct 1, 2015
May 29, 2015
Jun 22, 2024
May 29, 2015
Oct 1, 2015
Dec 21, 2014
Jun 22, 2024
Dec 12, 2015
May 29, 2015
Jun 22, 2024
Jun 22, 2024
Jun 22, 2024
Jan 2, 2015
Jun 22, 2024
Jan 2, 2015
Dec 10, 2015
Jun 21, 2024
May 16, 2015
Jun 22, 2024

Repository files navigation

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)