-
Notifications
You must be signed in to change notification settings - Fork 10
/
stress.go
73 lines (64 loc) · 1.67 KB
/
stress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"os"
"time"
"github.com/dhoomakethu/stress/utils"
"github.com/urfave/cli"
)
func getCommands() []cli.Command {
// global level flags
var cpuload float64
var duration float64
var cpucore int
sampleInterval := 100 * time.Millisecond
cpuLoadFlags := []cli.Flag{
cli.Float64Flag{
Name: "cpuload",
Usage: "Target CPU load 0<cpuload<1",
Value: 0.1,
Destination: &cpuload,
},
cli.Float64Flag{
Name: "duration",
Usage: "Duration to run the stress app in Seconds",
Value: 10,
Destination: &duration,
},
cli.IntFlag{
Name: "cpucore",
Usage: "Cpu core to stress ",
Value: 0,
Destination: &cpucore,
},
}
commands := []cli.Command{
{
Name: "cpu",
Action: func(c *cli.Context) {
runCpuLoader(sampleInterval, cpuload, duration, cpucore)
},
Usage: "load cpu , use --help for more options",
Flags: cpuLoadFlags,
Before: func(_ *cli.Context) error { return nil },
},
}
return commands
}
func runCpuLoader(sampleInterval time.Duration, cpuload float64, duration float64, cpu int) {
controller := utils.NewCpuLoadController(sampleInterval, cpuload)
monitor := utils.NewCpuLoadMonitor(float64(cpu), sampleInterval)
actuator := utils.NewCpuLoadGenerator(controller, monitor, time.Duration(duration))
utils.StartCpuLoadController(controller)
utils.StartCpuMonitor(monitor)
utils.RunCpuLoader(actuator)
utils.StopCpuLoadController(controller)
utils.StopCpuMonitor(monitor)
}
func main() {
app := cli.NewApp()
app.Name = "Stress"
app.Usage = "tool to stress test host !!"
app.Commands = getCommands()
app.Version = "0.0.1"
app.Run(os.Args)
}