moncheck - make workers configurable

The default worker count was set to 25, which might be too much
depending on the amount of cores available. Now make the default 25 and
let people decide on how many they want to use.
This commit is contained in:
Gibheer 2019-01-07 15:50:55 +01:00
parent 9ea6b0f343
commit 3b222e06ed
2 changed files with 11 additions and 3 deletions

View File

@ -31,6 +31,7 @@ type (
Timeout string `json:"timeout"` Timeout string `json:"timeout"`
Wait string `json:"wait"` Wait string `json:"wait"`
Path []string `json:"path"` Path []string `json:"path"`
Workers int `json:"workers"`
} }
States []int States []int
@ -43,7 +44,7 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("could not read config: %s", err) log.Fatalf("could not read config: %s", err)
} }
config := Config{Timeout: "30s", Wait: "30s"} config := Config{Timeout: "30s", Wait: "30s", Workers: 25}
if err := json.Unmarshal(raw, &config); err != nil { if err := json.Unmarshal(raw, &config); err != nil {
log.Fatalf("could not parse config: %s", err) log.Fatalf("could not parse config: %s", err)
} }
@ -66,7 +67,7 @@ func main() {
log.Fatalf("could not open database connection: %s", err) log.Fatalf("could not open database connection: %s", err)
} }
for i := 0; i < 25; i++ { for i := 0; i < config.Workers; i++ {
go check(i, db, waitDuration, timeout) go check(i, db, waitDuration, timeout)
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}

View File

@ -1,5 +1,12 @@
{ {
"db": "user=moncheck dbname=monzero", "db": "user=moncheck dbname=monzero",
"timeout": "5s", "timeout": "5s",
"wait": "5s" "wait": "5s",
"path": [
"/bin",
"/sbin",
"/usr/bin",
"/usr/sbin"
],
"workers": 25
} }