netusage

package
v0.0.0-...-2d83fc9 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2017 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package netusage gets the usage of the network devices. Usage is calculated by taking the difference between two network device snapshots, /proc/net/dev. The time elapsed between the two snapshots is stored in the TimeDelta field.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get() (u *structs.DevUsage, err error)

Get returns the current network device usage using the package's global Profiler. The profiler is lazily instantiated. If the profiler doesn't already exist, the first usage information will not be useful due to minimal time elapsing between the initial and second snapshots used for usage calculations; the results of the first call should be discarded.

func NewTicker

func NewTicker(d time.Duration) (joe.Tocker, error)

NewTicker returns a new Ticker containing a Data channel that delivers the data at intervals and an error channel that delivers any errors encountered. Stop the ticker to signal the ticker to stop running. Stopping the ticker does not close the Data channel; call Close to close both the ticker and the data channel.

Types

type Profiler

type Profiler struct {
	*netdev.Profiler
	// contains filtered or unexported fields
}

Profiler is used to process the network device usage.

func NewProfiler

func NewProfiler() (prof *Profiler, err error)

Returns an initialized Profiler; ready to use. Upon creation, a /proc/net/dev snapshot is taken so that any Get() will return valid information.

func (*Profiler) CalculateUsage

func (prof *Profiler) CalculateUsage(cur *structs.DevInfo) *structs.DevUsage

CalculateUsage returns the difference between the current /proc/net/dev snapshot and the prior one.

func (*Profiler) Get

func (prof *Profiler) Get() (u *structs.DevUsage, err error)

Get returns the current network device usage. Calculating usage requires two snapshots. This func gets the current snapshot of /proc/net/dev and calculates the difference between that and the prior snapshot. The current snapshot is stored for use as the prior snapshot on the next Get call. If ongoing usage information is desired, the Ticker should be used; it's better suited for ongoing usage information.

type Ticker

type Ticker struct {
	*joe.Ticker
	Data chan *structs.DevUsage
	*Profiler
}

Ticker delivers the system's network device usage at intervals.

func (*Ticker) Close

func (t *Ticker) Close()

Close closes the ticker resources.

func (*Ticker) Run

func (t *Ticker) Run()

Run runs the ticker.

Directories

Path Synopsis
Package netusage gets the usage of the network devices.
Package netusage gets the usage of the network devices.
Package netusage gets the usage of the network devices.
Package netusage gets the usage of the network devices.

Jump to

Keyboard shortcuts

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