Added result logging functionality (#2)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All test commands now utilize the "-l" or "--log" flag to specify a file to log results to. Reviewed-on: #2
This commit is contained in:
parent
7a8503ed3e
commit
90f679c366
10
cmd/disk.go
10
cmd/disk.go
@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -30,7 +31,14 @@ var diskCmd = &cobra.Command{
|
|||||||
outfile := fmt.Sprintf("of=%s", tempfile)
|
outfile := fmt.Sprintf("of=%s", tempfile)
|
||||||
|
|
||||||
ddCmd := exec.Command("dd", "bs=1M", blocksCount, "if=/dev/zero", outfile)
|
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()
|
err = ddCmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("cmd.Run() failed with %s\n", err)
|
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/showwin/speedtest-go/speedtest"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"git.metaunix.net/bitgoblin/hardware-tests/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
var netCmd = &cobra.Command{
|
var netCmd = &cobra.Command{
|
||||||
@ -22,7 +24,14 @@ var netCmd = &cobra.Command{
|
|||||||
s.DownloadTest(false)
|
s.DownloadTest(false)
|
||||||
s.UploadTest(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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
15
cmd/ping.go
15
cmd/ping.go
@ -5,6 +5,8 @@ import (
|
|||||||
|
|
||||||
"github.com/go-ping/ping"
|
"github.com/go-ping/ping"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"git.metaunix.net/bitgoblin/hardware-tests/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -23,11 +25,18 @@ var pingCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
pinger.Count = count
|
pinger.Count = count
|
||||||
pinger.OnFinish = func(stats *ping.Statistics) {
|
pinger.OnFinish = func(stats *ping.Statistics) {
|
||||||
fmt.Printf("--- %s ping statistics ---\n", stats.Addr)
|
result := fmt.Sprintf("--- %s ping statistics ---\n", stats.Addr)
|
||||||
fmt.Printf("%d packets transmitted, %d packets received, %v%% packet loss\n",
|
result += fmt.Sprintf("%d packets transmitted, %d packets received, %v%% packet loss\n",
|
||||||
stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
|
stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
|
||||||
fmt.Printf("round-trip min/avg/max/stddev = %v/%v/%v/%v\n",
|
result += fmt.Sprintf("round-trip min/avg/max/stddev = %v/%v/%v/%v\n",
|
||||||
stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)
|
stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)
|
||||||
|
|
||||||
|
// log the result if it's configured, otherwise print it out
|
||||||
|
if Log != "false" {
|
||||||
|
lib.WriteToFile(Log, result)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%s", result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("PING %s (%s):\n", pinger.Addr(), pinger.IPAddr())
|
fmt.Printf("PING %s (%s):\n", pinger.Addr(), pinger.IPAddr())
|
||||||
err = pinger.Run() // Blocks until finished.
|
err = pinger.Run() // Blocks until finished.
|
||||||
|
@ -7,6 +7,10 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Log string
|
||||||
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "bgbench",
|
Use: "bgbench",
|
||||||
Short: "Bit Goblin hardware benching tool.",
|
Short: "Bit Goblin hardware benching tool.",
|
||||||
@ -20,3 +24,7 @@ func Execute() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&Log, "log", "l", "false", "File location to write results to.")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user