bandwidth -> bps, and behavior change
- bps.BPS only keeps track of rates of a single rate - bps.BPS implements io.Writer - removed chan semantics, interact via .Add or .Write - fleshed out docs
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
bandwidth
|
||||
=========
|
||||
# bps
|
||||
|
||||
`bandwidth` is a little package to be used in collecting and reporting on bandwidth numbers.
|
||||
`bps` is used to keep track of rates
|
||||
|
||||
It is intended to be used as such:
|
||||
|
||||
|
||||
```go
|
||||
// report on 1, 10, 60 second intervals, update every 100 milliseconds
|
||||
bw, _ := NewBandwidth([]int{1, 10, 60}, 100*time.Millisecond)
|
||||
go bw.Run()
|
||||
bw.AddRx <- 10
|
||||
bw.AddTx <- 10
|
||||
// report on 1, 10, 60 second intervals, update every second
|
||||
bw, _ := NewBandwidth([]int{1, 10, 60}, time.Second)
|
||||
bw.Add(10)
|
||||
b := &bytes.Buffer{}
|
||||
b.Write([]byte("helloooooooooooooooooooooooooooooooooooooooooooooo"))
|
||||
io.Copy(bw, b)
|
||||
time.Sleep(1 * time.Second)
|
||||
log.Printf("%+v", <-bw.Rx)
|
||||
log.Printf("%+v", <-bw.Tx)
|
||||
```
|
||||
log.Printf("%+v", bw.Cur())
|
||||
|
||||
Reference in New Issue
Block a user