-
Notifications
You must be signed in to change notification settings - Fork 3
/
headached.go
81 lines (67 loc) · 1.83 KB
/
headached.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
74
75
76
77
78
79
80
81
package main
import (
"encoding/json"
"github.com/oniichaNj/headached/lib/corrupt"
"github.com/oniichaNj/headached/lib/entropyexhaustion"
"github.com/oniichaNj/headached/lib/load"
"log"
"os"
"sync"
)
type Config struct {
/* Should we corrupt files? */
EnableCorruption bool
/* The directory to remove files from: */
CorruptDirs []string
/* The interval of seconds to wait between file corruption: */
MinCorruptSeconds int
MaxCorruptSeconds int
/* The amount of bytes to corrupt. */
CorruptNbytes int
/* Should we increase load average? */
EnableCPUSpike bool
/* The interval of seconds to wait between CPU usage */
MinCPUSpikeSeconds int
MaxCPUSpikeSeconds int
/* The duration of a CPU spike, in seconds */
CPUSpikeDuration int
/* Should we exhaust system entropy? */
EnableEntropyExhaustion bool
}
func main() {
/*
* Logging to STDERR is neater because we can then let something else deal with rotation
* and choose what file to put things in.
*/
errLog := log.New(os.Stderr, "", log.Ldate|log.Ltime)
/* Open and set up the configuration file. */
cfgf, err := os.Open("/etc/headached.json")
if err != nil {
errLog.Fatal(err)
}
defer cfgf.Close()
decoder := json.NewDecoder(cfgf)
config := Config{}
err = decoder.Decode(&config)
if err != nil {
errLog.Fatal(err)
}
var wg sync.WaitGroup
/*
* Load the components from lib/ that we want to use.
* If you wrote your own components, add them here.
*/
if config.EnableCorruption {
wg.Add(1)
go corrupt.Init(config.MinCorruptSeconds, config.MaxCorruptSeconds, config.CorruptDirs, config.CorruptNbytes, errLog)
}
if config.EnableCPUSpike {
wg.Add(1)
go load.Init(config.MinCPUSpikeSeconds, config.MaxCPUSpikeSeconds, config.CPUSpikeDuration, errLog)
}
if config.EnableEntropyExhaustion {
wg.Add(1)
go entropyexhaustion.Init(errLog)
}
wg.Wait()
}