sflow

package module
v0.0.0-...-3c379a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

README

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)

Documentation

Index

Constants

View Source
const (
	TypeGenericInterfaceCountersRecord = 1
	TypeEthernetCountersRecord         = 2
	TypeTokenRingCountersRecord        = 3
	TypeVgCountersRecord               = 4
	TypeVlanCountersRecord             = 5

	TypeProcessorCountersRecord  = 1001
	TypeHostCPUCountersRecord    = 2003
	TypeHostMemoryCountersRecord = 2004
	TypeHostDiskCountersRecord   = 2005
	TypeHostNetCountersRecord    = 2006

	// Custom (Enterprise) types
	TypeApplicationCountersRecord = (1)<<12 + 1
)
View Source
const (
	// MaximumRecordLength defines the maximum length acceptable for decoded records.
	// This maximum prevents from excessive memory allocation.
	// The value is derived from MAX_PKT_SIZ 65536 in the reference sFlow implementation
	// https://github.com/sflow/sflowtool/blob/bd3df6e11bdf/src/sflowtool.c#L4313.
	MaximumRecordLength = 65536

	// MaximumHeaderLength defines the maximum length acceptable for decoded flow samples.
	// This maximum prevents from excessive memory allocation.
	// The value is set to maximum transmission unit (MTU), as the header of a network packet
	// may not exceed the MTU.
	MaximumHeaderLength = 1500
)
View Source
const (
	TypeFlowSample            = 1
	TypeCounterSample         = 2
	TypeExpandedFlowSample    = 3
	TypeExpandedCounterSample = 4
)

Variables

View Source
var (
	ErrInvalidSliceLength = errors.New("sflow: invalid slice length")
	ErrInvalidFieldType   = errors.New("sflow: field type")
)
View Source
var (
	ErrNoSamplesProvided = errors.New("sflow: no samples provided for encoding")
)
View Source
var (
	ErrUnknownSampleType = errors.New("sflow: Unknown sample type")
)
View Source
var ErrUnsupportedDatagramVersion = errors.New("sflow: unsupported datagram version")

Functions

This section is empty.

Types

type CounterSample

type CounterSample struct {
	SequenceNum      uint32
	SourceIdType     byte
	SourceIdIndexVal uint32 // NOTE: this is 3 bytes in the datagram

	Records []records.Record
	// contains filtered or unexported fields
}

func (*CounterSample) GetRecords

func (s *CounterSample) GetRecords() []records.Record

func (*CounterSample) SampleType

func (s *CounterSample) SampleType() int

SampleType returns the type of sFlow sample.

func (CounterSample) String

func (s CounterSample) String() string

type Datagram

type Datagram struct {
	Version        uint32   `json:"version"`
	IpVersion      uint32   `json:"ipVersion"`
	IpAddress      net.IP   `json:"ipAddress"`
	SubAgentId     uint32   `json:"subAgentId"`
	SequenceNumber uint32   `json:"sequenceNumber"`
	Uptime         uint32   `json:"uptime"`
	NumSamples     uint32   `json:"numSamples"`
	Samples        []Sample `json:"samples"`
}

func (Datagram) String

func (d Datagram) String() string

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r io.ReadSeeker) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode() (*Datagram, error)

func (*Decoder) Use

func (d *Decoder) Use(r io.ReadSeeker)

type Encoder

type Encoder struct {
	Uptime uint32
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(source net.IP, subAgentId uint32, initialSequenceNumber uint32) *Encoder

NewEncoder returns a new sFlow encoder.

func (*Encoder) Encode

func (e *Encoder) Encode(w io.Writer, samples []Sample) error

Encode encodes an sFlow v5 datagram with the given samples and writes the packet to w.

type EthernetCounters

type EthernetCounters struct {
	AlignmentErrors           uint32
	FCSErrors                 uint32
	SingleCollisionFrames     uint32
	MultipleCollisionFrames   uint32
	SQETestErrors             uint32
	DeferredTransmissions     uint32
	LateCollisions            uint32
	ExcessiveCollisions       uint32
	InternalMACTransmitErrors uint32
	CarrierSenseErrors        uint32
	FrameTooLongs             uint32
	InternalMACReceiveErrors  uint32
	SymbolErrors              uint32
}

EthernetCounters is an Ethernet interface counters record.

func (EthernetCounters) Encode

func (c EthernetCounters) Encode(w io.Writer) error

func (EthernetCounters) RecordName

func (c EthernetCounters) RecordName() string

RecordName returns the Name of this counter record

func (EthernetCounters) RecordType

func (c EthernetCounters) RecordType() int

RecordType returns the type of counter record.

func (EthernetCounters) String

func (c EthernetCounters) String() string

type FlowSample

type FlowSample struct {
	SequenceNum      uint32
	SourceIdType     byte
	SourceIdIndexVal uint32 // NOTE: this is 3 bytes in the datagram
	SamplingRate     uint32
	SamplePool       uint32
	Drops            uint32
	Input            uint32
	Output           uint32

	Records []records.Record
	// contains filtered or unexported fields
}

func (*FlowSample) GetRecords

func (s *FlowSample) GetRecords() []records.Record

func (*FlowSample) SampleType

func (s *FlowSample) SampleType() int

SampleType returns the type of sFlow sample.

func (FlowSample) String

func (s FlowSample) String() string

type GenericInterfaceCounters

type GenericInterfaceCounters struct {
	Index               uint32
	Type                uint32
	Speed               uint64
	Direction           uint32
	Status              uint32
	InOctets            uint64
	InUnicastPackets    uint32
	InMulticastPackets  uint32
	InBroadcastPackets  uint32
	InDiscards          uint32
	InErrors            uint32
	InUnknownProtocols  uint32
	OutOctets           uint64
	OutUnicastPackets   uint32
	OutMulticastPackets uint32
	OutBroadcastPackets uint32
	OutDiscards         uint32
	OutErrors           uint32
	PromiscuousMode     uint32
}

GenericInterfaceCounters is a generic switch counters record.

func (GenericInterfaceCounters) Encode

func (GenericInterfaceCounters) RecordName

func (c GenericInterfaceCounters) RecordName() string

RecordName returns the Name of this counter record

func (GenericInterfaceCounters) RecordType

func (c GenericInterfaceCounters) RecordType() int

RecordType returns the type of counter record.

func (GenericInterfaceCounters) String

func (c GenericInterfaceCounters) String() string

type HostCPUCounters

type HostCPUCounters struct {
	Load1m           float32
	Load5m           float32
	Load15m          float32
	ProcessesRunning uint32
	ProcessesTotal   uint32
	NumCPU           uint32
	SpeedCPU         uint32
	Uptime           uint32

	CPUUser         uint32
	CPUNice         uint32
	CPUSys          uint32
	CPUIdle         uint32
	CPUWio          uint32
	CPUIntr         uint32
	CPUSoftIntr     uint32
	Interrupts      uint32
	ContextSwitches uint32

	CPUSteal     uint32
	CPUGuest     uint32
	CPUGuestNice uint32
}

HostCPUCounters is a host CPU counters record.

func (HostCPUCounters) Encode

func (c HostCPUCounters) Encode(w io.Writer) error

func (HostCPUCounters) RecordName

func (c HostCPUCounters) RecordName() string

RecordName returns the Name of this counter record

func (HostCPUCounters) RecordType

func (c HostCPUCounters) RecordType() int

RecordType returns the type of counter record.

func (HostCPUCounters) String

func (c HostCPUCounters) String() string

type HostDiskCounters

type HostDiskCounters struct {
	Total          uint64
	Free           uint64
	MaxUsedPercent float32
	Reads          uint32
	BytesRead      uint64
	ReadTime       uint32
	Writes         uint32
	BytesWritten   uint64
	WriteTime      uint32
}

HostDiskCounters is a host disk counters record.

func (HostDiskCounters) Encode

func (c HostDiskCounters) Encode(w io.Writer) error

func (HostDiskCounters) RecordName

func (c HostDiskCounters) RecordName() string

RecordName returns the Name of this counter record

func (HostDiskCounters) RecordType

func (c HostDiskCounters) RecordType() int

RecordType returns the type of counter record.

func (HostDiskCounters) String

func (c HostDiskCounters) String() string

type HostMemoryCounters

type HostMemoryCounters struct {
	Total     uint64
	Free      uint64
	Shared    uint64
	Buffers   uint64
	Cached    uint64
	SwapTotal uint64
	SwapFree  uint64

	PageIn  uint32
	PageOut uint32
	SwapIn  uint32
	SwapOut uint32
}

HostMemoryCounters is a host memory counters record.

func (HostMemoryCounters) Encode

func (c HostMemoryCounters) Encode(w io.Writer) error

func (HostMemoryCounters) RecordName

func (c HostMemoryCounters) RecordName() string

RecordName returns the Name of this counter record

func (HostMemoryCounters) RecordType

func (c HostMemoryCounters) RecordType() int

RecordType returns the type of counter record.

func (HostMemoryCounters) String

func (c HostMemoryCounters) String() string

type HostNetCounters

type HostNetCounters struct {
	BytesIn   uint64
	PacketsIn uint32
	ErrorsIn  uint32
	DropsIn   uint32

	BytesOut   uint64
	PacketsOut uint32
	ErrorsOut  uint32
	DropsOut   uint32
}

HostNetCounters is a host network counters record.

func (HostNetCounters) Encode

func (c HostNetCounters) Encode(w io.Writer) error

func (HostNetCounters) RecordName

func (c HostNetCounters) RecordName() string

RecordName returns the Name of this counter record

func (HostNetCounters) RecordType

func (c HostNetCounters) RecordType() int

RecordType returns the type of counter record.

func (HostNetCounters) String

func (c HostNetCounters) String() string

type ProcessorCounters

type ProcessorCounters struct {
	CPU5s       uint32
	CPU1m       uint32
	CPU5m       uint32
	TotalMemory uint64
	FreeMemory  uint64
}

ProcessorCounters is a switch processor counters record.

func (ProcessorCounters) Encode

func (c ProcessorCounters) Encode(w io.Writer) error

func (ProcessorCounters) RecordName

func (c ProcessorCounters) RecordName() string

RecordName returns the Name of this counter record

func (ProcessorCounters) RecordType

func (c ProcessorCounters) RecordType() int

RecordType returns the type of counter record.

func (ProcessorCounters) String

func (c ProcessorCounters) String() string

type Sample

type Sample interface {
	SampleType() int
	GetRecords() []records.Record
	// contains filtered or unexported methods
}

type TokenRingCounters

type TokenRingCounters struct {
	LineErrors         uint32
	BurstErrors        uint32
	ACErrors           uint32
	AbortTransErrors   uint32
	InternalErrors     uint32
	LostFrameErrors    uint32
	ReceiveCongestions uint32
	FrameCopiedErrors  uint32
	TokenErrors        uint32
	SoftErrors         uint32
	HardErrors         uint32
	SignalLoss         uint32
	TransmitBeacons    uint32
	Recoverys          uint32
	LobeWires          uint32
	Removes            uint32
	Singles            uint32
	FreqErrors         uint32
}

TokenRingCounters is a token ring interface counters record.

func (TokenRingCounters) Encode

func (c TokenRingCounters) Encode(w io.Writer) error

func (TokenRingCounters) RecordName

func (c TokenRingCounters) RecordName() string

RecordName returns the Name of this counter record

func (TokenRingCounters) RecordType

func (c TokenRingCounters) RecordType() int

RecordType returns the type of counter record.

func (TokenRingCounters) String

func (c TokenRingCounters) String() string

type VgCounters

type VgCounters struct {
	InHighPriorityFrames    uint32
	InHighPriorityOctets    uint64
	InNormPriorityFrames    uint32
	InNormPriorityOctets    uint64
	InIPMErrors             uint32
	InOversizeFrameErrors   uint32
	InDataErrors            uint32
	InNullAddressedFrames   uint32
	OutHighPriorityFrames   uint32
	OutHighPriorityOctets   uint64
	TransitionIntoTrainings uint32
	HCInHighPriorityOctets  uint64
	HCInNormPriorityOctets  uint64
	HCOutHighPriorityOctets uint64
}

VgCounters is a BaseVG interface counters record.

func (VgCounters) Encode

func (c VgCounters) Encode(w io.Writer) error

func (VgCounters) RecordName

func (c VgCounters) RecordName() string

RecordName returns the Name of this counter record

func (VgCounters) RecordType

func (c VgCounters) RecordType() int

RecordType returns the type of counter record.

func (VgCounters) String

func (c VgCounters) String() string

type VlanCounters

type VlanCounters struct {
	ID               uint32
	Octets           uint64
	UnicastPackets   uint32
	MulticastPackets uint32
	BroadcastPackets uint32
	Discards         uint32
}

VlanCounters is a VLAN counters record.

func (VlanCounters) Encode

func (c VlanCounters) Encode(w io.Writer) error

func (VlanCounters) RecordName

func (c VlanCounters) RecordName() string

RecordName returns the Name of this counter record

func (VlanCounters) RecordType

func (c VlanCounters) RecordType() int

RecordType returns the type of counter record.

func (VlanCounters) String

func (c VlanCounters) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL