Completed logging functionality
This commit is contained in:
parent
56f1982837
commit
65c23c480d
10
cmd/disk.go
10
cmd/disk.go
@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -30,7 +31,14 @@ var diskCmd = &cobra.Command{
|
||||
outfile := fmt.Sprintf("of=%s", tempfile)
|
||||
|
||||
ddCmd := exec.Command("dd", "bs=1M", blocksCount, "if=/dev/zero", outfile)
|
||||
ddCmd.Stderr = os.Stdout
|
||||
|
||||
if Log != "false" {
|
||||
f, _ := os.Create(Log)
|
||||
ddCmd.Stderr = io.MultiWriter(os.Stderr, f)
|
||||
} else {
|
||||
ddCmd.Stderr = os.Stdout
|
||||
}
|
||||
|
||||
err = ddCmd.Run()
|
||||
if err != nil {
|
||||
log.Fatalf("cmd.Run() failed with %s\n", err)
|
||||
|
11
cmd/net.go
11
cmd/net.go
@ -5,6 +5,8 @@ import (
|
||||
|
||||
"github.com/showwin/speedtest-go/speedtest"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"git.metaunix.net/bitgoblin/hardware-tests/lib"
|
||||
)
|
||||
|
||||
var netCmd = &cobra.Command{
|
||||
@ -22,7 +24,14 @@ var netCmd = &cobra.Command{
|
||||
s.DownloadTest(false)
|
||||
s.UploadTest(false)
|
||||
|
||||
fmt.Printf("Latency: %s, Download: %f, Upload: %f\n", s.Latency, s.DLSpeed, s.ULSpeed)
|
||||
// put together the result
|
||||
result := fmt.Sprintf("Latency: %s, Download: %f, Upload: %f\n", s.Latency, s.DLSpeed, s.ULSpeed)
|
||||
// log the result if it's configured, otherwise print it out
|
||||
if Log != "false" {
|
||||
lib.WriteToFile(Log, result)
|
||||
} else {
|
||||
fmt.Printf("%s", result)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ var pingCmd = &cobra.Command{
|
||||
result += fmt.Sprintf("round-trip min/avg/max/stddev = %v/%v/%v/%v\n",
|
||||
stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)
|
||||
|
||||
if Log != nil {
|
||||
// log the result if it's configured, otherwise print it out
|
||||
if Log != "false" {
|
||||
lib.WriteToFile(Log, result)
|
||||
} else {
|
||||
fmt.Printf("%s", result)
|
||||
|
Loading…
Reference in New Issue
Block a user