diff --git a/pkg/perf/monitor.go b/pkg/perf/monitor.go index 9afe28f28..a4af8efb1 100644 --- a/pkg/perf/monitor.go +++ b/pkg/perf/monitor.go @@ -14,7 +14,7 @@ import ( // PerformanceMonitor holds the module data type PerformanceMonitor struct { scheduler *gocron.Scheduler - pool redis.Pool + pool *redis.Pool tasks []Task } @@ -29,7 +29,7 @@ func NewPerformanceMonitor(redisAddr string) (*PerformanceMonitor, error) { return &PerformanceMonitor{ scheduler: scheduler, - pool: *redisPool, + pool: redisPool, tasks: []Task{}, }, nil } diff --git a/pkg/perf/tcp_task.go b/pkg/perf/tcp_task.go index dad78b233..144314ff8 100644 --- a/pkg/perf/tcp_task.go +++ b/pkg/perf/tcp_task.go @@ -1,10 +1,12 @@ package perf import ( + "bytes" "context" "fmt" "os/exec" + "github.com/rs/zerolog/log" "github.com/threefoldtech/zos/pkg/network/iperf" ) @@ -28,10 +30,21 @@ func (t *TCPTask) Cron() string { // Run runs the tcp test and returns the result func (t *TCPTask) Run(ctx context.Context) (interface{}, error) { - output, err := exec.CommandContext(ctx, fmt.Sprintf("iperf3 -c %s -p %d -b %s", t.ClientIP, iperf.IperfPort, t.Bandwidth)).Output() + _, err := exec.LookPath("iperf") if err != nil { return nil, err } - return output, nil + cmd := exec.CommandContext(ctx, "iperf", fmt.Sprintf("-c %s -p %d -b %s", t.ClientIP, iperf.IperfPort, t.Bandwidth)) + var out bytes.Buffer + var stderr bytes.Buffer + cmd.Stderr = &stderr + cmd.Stdout = &out + + err = cmd.Run() + if err != nil { + log.Error().Err(err).Msgf("failed to run iperf tcp task: %s", stderr.String()) + } + + return out.String(), nil } diff --git a/pkg/perf/udp_task.go b/pkg/perf/udp_task.go index c20834e9c..acc4381b2 100644 --- a/pkg/perf/udp_task.go +++ b/pkg/perf/udp_task.go @@ -1,10 +1,12 @@ package perf import ( + "bytes" "context" "fmt" "os/exec" + "github.com/rs/zerolog/log" "github.com/threefoldtech/zos/pkg/network/iperf" ) @@ -28,10 +30,21 @@ func (t *UDPTask) Cron() string { // Run runs the udp test and returns the result func (t *UDPTask) Run(ctx context.Context) (interface{}, error) { - output, err := exec.CommandContext(ctx, fmt.Sprintf("iperf3 -c %s -p %d -b %s -u", t.ClientIP, iperf.IperfPort, t.Bandwidth)).Output() + _, err := exec.LookPath("iperf") if err != nil { return nil, err } - return output, nil + cmd := exec.CommandContext(ctx, "iperf", fmt.Sprintf("-c %s -p %d -b %s -u", t.ClientIP, iperf.IperfPort, t.Bandwidth)) + var out bytes.Buffer + var stderr bytes.Buffer + cmd.Stderr = &stderr + cmd.Stdout = &out + + err = cmd.Run() + if err != nil { + log.Error().Err(err).Msgf("failed to run iperf udp task: %s", stderr.String()) + } + + return out.String(), nil }