mirror of
https://github.com/Luzifer/mondash.git
synced 2024-12-23 04:21:18 +00:00
Fix: Welcome dashboard contains no metrics for 1m
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
21e57d0bd9
commit
f3932a4d57
1 changed files with 38 additions and 35 deletions
|
@ -17,43 +17,46 @@ func runWelcomePage(cfg *config.Config) {
|
||||||
welcomeAPIToken := cfg.APIToken
|
welcomeAPIToken := cfg.APIToken
|
||||||
generateTicker := time.NewTicker(time.Minute)
|
generateTicker := time.NewTicker(time.Minute)
|
||||||
|
|
||||||
for {
|
// Do one initial push on start
|
||||||
select {
|
postWelcomeMetric(baseURL, welcomeAPIToken)
|
||||||
case <-generateTicker.C:
|
|
||||||
beers := rand.Intn(24)
|
|
||||||
status := "OK"
|
|
||||||
switch {
|
|
||||||
case beers < 6:
|
|
||||||
status = "Critical"
|
|
||||||
case beers < 12:
|
|
||||||
status = "Warning"
|
|
||||||
}
|
|
||||||
|
|
||||||
beer := dashboardMetric{
|
for range generateTicker.C {
|
||||||
Title: "Amount of beer in the fridge",
|
postWelcomeMetric(baseURL, welcomeAPIToken)
|
||||||
Description: fmt.Sprintf("Currently there are %d bottles of beer in the fridge", beers),
|
}
|
||||||
IgnoreMAD: true,
|
}
|
||||||
Status: status,
|
|
||||||
Expires: 86400,
|
|
||||||
Freshness: 120,
|
|
||||||
Value: float64(beers),
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := json.Marshal(beer)
|
func postWelcomeMetric(baseURL, welcomeAPIToken string) {
|
||||||
if err != nil {
|
beers := rand.Intn(24)
|
||||||
log.Println(err)
|
status := "OK"
|
||||||
continue
|
switch {
|
||||||
}
|
case beers < 6:
|
||||||
url := fmt.Sprintf("%s/welcome/beer_available", baseURL)
|
status = "Critical"
|
||||||
req, _ := http.NewRequest("PUT", url, bytes.NewBuffer(body))
|
case beers < 12:
|
||||||
req.Header.Add("Authorization", welcomeAPIToken)
|
status = "Warning"
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("[WelcomeRunner] %s", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
resp.Body.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beer := dashboardMetric{
|
||||||
|
Title: "Amount of beer in the fridge",
|
||||||
|
Description: fmt.Sprintf("Currently there are %d bottles of beer in the fridge", beers),
|
||||||
|
IgnoreMAD: true,
|
||||||
|
Status: status,
|
||||||
|
Expires: 86400,
|
||||||
|
Freshness: 120,
|
||||||
|
Value: float64(beers),
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := json.Marshal(beer)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
url := fmt.Sprintf("%s/welcome/beer_available", baseURL)
|
||||||
|
req, _ := http.NewRequest("PUT", url, bytes.NewBuffer(body))
|
||||||
|
req.Header.Add("Authorization", welcomeAPIToken)
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[WelcomeRunner] %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue