Documentation ¶
Overview ¶
Package throughput provides an interface and implementations of that interface to read the throughput of network devices.
Synopsis ¶
A brief example of using the package to print throughput stats:
package main import ( "fmt" "github.com/robkingsbury/bndstat/throughput" "time" ) func main() { // Throwing away errors is bad practice but is done here for brevity. reporter, _ := throughput.NewReporter() table := throughput.NewTable() for { stats, _ := reporter.Report() // Directly accessing device stats for _, device := range stats.Devices() { in, out, _ := stats.Avg(device, throughput.Kbps) fmt.Printf("%s: in = %.2f, out = %.2f\n", device, in, out) } // Using the builtin, aligned table output table.Write(throughput.TableWriteOpts{ Stats: stats, Devices: stats.Devices(), Unit: throughput.Kbps, ShowUnit: false, }) time.Sleep(time.Second) } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Linux ¶
type Linux struct {
// contains filtered or unexported fields
}
Linux implements the Reporter interface for linux systems.
type NilReporter ¶
type NilReporter struct{}
NilReporter implements the Reporter interface in a most trivial fashion.
func (*NilReporter) Report ¶
func (*NilReporter) Report() (*Stats, error)
Report always returns an empty Stat slice and an error.
type Reporter ¶
type Reporter interface { // Report should return a pointer to a Stats struct containing data for all // discovered network devices. Report() (*Stats, error) }
Reporter is the interface implemented by types that report basic network device throughput stats.
func NewReporter ¶ added in v0.3.0
NewReporter returns an initialized Reporter that's compatible with the current OS. An error is returned if the OS is not supported.
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
Stats contains throughput data for each network device.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is used to print device Stats in a nicely formatted output.
func (*Table) Write ¶
func (t *Table) Write(opt TableWriteOpts) error
Write outputs the average throughput of each device in an aligned, absolutely gorgeous rendition of data, designed to instill feelings of joy at the beauty in the world. Each time Table is called, the average throughput since the last call to Table is printed to stdout.
type TableWriteOpts ¶ added in v0.4.0
type TableWriteOpts struct { // Stats should be a pointer to a Stats struct with network // device throughput data. Stats *Stats // Devices is a slice of devices from Stats to display. Devices []string // Unit specifies the unit to use when display the throughput. Unit Unit // ShowUnit will print the unit type in the table header when set // to true. ShowUnit bool }
TableWriteOpts is used to specify options by Table.Write().
type Unit ¶
type Unit int
A unit is used to format the value returned by Stat.Avg().
func ParseUnit ¶
ParseUnit returns the Unit associated with a unit name. Use the string form of the const name for the unit that you want. Parsing is not case sensitive. For example, an input of "Bps" or "bps", will return the unit Bps, "Mbps", "mbps", or "mBps" will return the Mbps unit, etc.
An error is returned if the input does not match any Unit const.