Lots of changes to the website
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"ridgwaysystems.org/website/internal/status"
|
||||
"ridgwaysystems.org/website/internal/uptime"
|
||||
)
|
||||
|
||||
// Start launches the background checker. It checks services every interval
|
||||
@@ -26,18 +27,19 @@ func run(dataDir string, interval time.Duration) {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
path := filepath.Join(dataDir, "status.json")
|
||||
statusPath := filepath.Join(dataDir, "status.json")
|
||||
uptimePath := filepath.Join(dataDir, "uptime.json")
|
||||
|
||||
for {
|
||||
check(client, path)
|
||||
check(client, statusPath, uptimePath)
|
||||
time.Sleep(interval)
|
||||
}
|
||||
}
|
||||
|
||||
func check(client *http.Client, path string) {
|
||||
page, err := status.Load(path)
|
||||
func check(client *http.Client, statusPath, uptimePath string) {
|
||||
page, err := status.Load(statusPath)
|
||||
if err != nil {
|
||||
log.Printf("checker: load %s: %v", path, err)
|
||||
log.Printf("checker: load %s: %v", statusPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -57,16 +59,24 @@ func check(client *http.Client, path string) {
|
||||
}
|
||||
|
||||
if changed {
|
||||
if err := status.Save(path, page); err != nil {
|
||||
log.Printf("checker: save %s: %v", path, err)
|
||||
if err := status.Save(statusPath, page); err != nil {
|
||||
log.Printf("checker: save %s: %v", statusPath, err)
|
||||
}
|
||||
} else {
|
||||
// Still update last_checked timestamp so the status page shows freshness
|
||||
page.LastChecked = time.Now().UTC()
|
||||
if err := status.Save(path, page); err != nil {
|
||||
log.Printf("checker: save %s: %v", path, err)
|
||||
if err := status.Save(statusPath, page); err != nil {
|
||||
log.Printf("checker: save %s: %v", statusPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Record hourly uptime snapshot.
|
||||
statuses := make(map[string]string, len(page.Services))
|
||||
for _, svc := range page.Services {
|
||||
statuses[svc.Name] = svc.Status
|
||||
}
|
||||
if err := uptime.Record(uptimePath, statuses); err != nil {
|
||||
log.Printf("checker: uptime record: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func probe(client *http.Client, url string) string {
|
||||
@@ -82,7 +92,6 @@ func probe(client *http.Client, url string) string {
|
||||
case resp.StatusCode >= 500:
|
||||
return "down"
|
||||
default:
|
||||
// 4xx could mean the service is up but the URL is wrong; treat as degraded
|
||||
return "degraded"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user