initial working version
This commit is contained in:
@@ -2,10 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/BGrewell/go-conversions"
|
||||
"github.com/BGrewell/go-iperf"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -22,8 +20,17 @@ func main() {
|
||||
c.SetOmitSec(omitSec)
|
||||
c.SetProto((iperf.Protocol)(proto))
|
||||
c.SetLength(length)
|
||||
c.SetJSON(false)
|
||||
c.SetIncludeServer(false)
|
||||
c.SetTimeSec(20)
|
||||
c.SetStreams(2)
|
||||
reports := c.SetModeLive()
|
||||
|
||||
fmt.Printf("blockcount: %s\n", c.BlockCount())
|
||||
go func() {
|
||||
for report := range reports {
|
||||
fmt.Println(report.String())
|
||||
}
|
||||
}()
|
||||
|
||||
err := c.Start()
|
||||
if err != nil {
|
||||
@@ -31,20 +38,24 @@ func main() {
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
for c.Running {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
// Method 1: Wait for the test to finish by pulling from the 'Done' channel which will block until something is put in or it's closed
|
||||
<- c.Done
|
||||
|
||||
if c.Report().Error != "" {
|
||||
fmt.Println(c.Report().Error)
|
||||
} else {
|
||||
for _, entry := range c.Report().End.Streams {
|
||||
fmt.Println(entry.String())
|
||||
}
|
||||
for _, entry := range c.Report().ServerOutputJson.End.Streams {
|
||||
fmt.Println(entry.String())
|
||||
}
|
||||
fmt.Printf("DL Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumReceived.BitsPerSecond)))
|
||||
fmt.Printf("UL Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumSent.BitsPerSecond)))
|
||||
}
|
||||
// Method 2: Poll the c.Running state and wait for it to be 'false'
|
||||
//for c.Running {
|
||||
// time.Sleep(100 * time.Millisecond)
|
||||
//}
|
||||
|
||||
//if c.Report().Error != "" {
|
||||
// fmt.Println(c.Report().Error)
|
||||
//} else {
|
||||
// for _, entry := range c.Report().End.Streams {
|
||||
// fmt.Println(entry.String())
|
||||
// }
|
||||
// for _, entry := range c.Report().ServerOutputJson.End.Streams {
|
||||
// fmt.Println(entry.String())
|
||||
// }
|
||||
// fmt.Printf("DL Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumReceived.BitsPerSecond)))
|
||||
// fmt.Printf("UL Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumSent.BitsPerSecond)))
|
||||
//}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user