From 31bd3c35abe53e7e36f940085a0377cce7fb5391 Mon Sep 17 00:00:00 2001 From: Joel Male Date: Wed, 25 Feb 2026 14:48:12 +1000 Subject: [PATCH] feat: include next_update_check timestamp in every pulse payload --- main.go | 22 +++++++++++++++++++--- payload.json | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 5c6e9cc..2d16d0d 100644 --- a/main.go +++ b/main.go @@ -60,8 +60,9 @@ type Metrics struct { Timestamp time.Time `json:"timestamp"` Token string `json:"token"` Hostname string `json:"hostname"` - CollectorVersion string `json:"collector_version"` - Uptime uint64 `json:"uptime"` + CollectorVersion string `json:"collector_version"` + NextUpdateCheck *time.Time `json:"next_update_check,omitempty"` + Uptime uint64 `json:"uptime"` System SystemInfo `json:"system"` LoadAvg LoadMetrics `json:"load_avg"` CPU CPUMetrics `json:"cpu"` @@ -154,6 +155,10 @@ type ProcessInfo struct { var prevNet *networkSnapshot +// nextUpdateCheck is set by the auto-updater goroutine so it can be included +// in every pulse. Nil when auto-update is disabled. +var nextUpdateCheck *time.Time + func main() { if len(os.Args) > 1 { switch os.Args[1] { @@ -457,7 +462,9 @@ type latestRelease struct { } func runAutoUpdater(config *Config) { - // Wait before first check so the initial collection can complete. + t := time.Now().Add(30 * time.Second) + nextUpdateCheck = &t + time.Sleep(30 * time.Second) checkAndUpdate(config) @@ -468,12 +475,18 @@ func runAutoUpdater(config *Config) { } } +func scheduleNextUpdateCheck() { + t := time.Now().Add(updateCheckInterval) + nextUpdateCheck = &t +} + func checkAndUpdate(config *Config) { latest, err := fetchLatestVersion() if err != nil { if config.Debug { log.Printf("[DEBUG] Update check failed: %v", err) } + scheduleNextUpdateCheck() return } @@ -481,6 +494,7 @@ func checkAndUpdate(config *Config) { if config.Debug { log.Printf("[DEBUG] Already on latest version %s", version) } + scheduleNextUpdateCheck() return } @@ -488,6 +502,7 @@ func checkAndUpdate(config *Config) { if err := downloadAndReplace(); err != nil { log.Printf("Auto-update failed: %v", err) + scheduleNextUpdateCheck() return } @@ -699,6 +714,7 @@ func collectMetrics(config *Config) (*Metrics, error) { Token: config.Token, Hostname: config.Hostname, CollectorVersion: version, + NextUpdateCheck: nextUpdateCheck, } // Uptime diff --git a/payload.json b/payload.json index 8016e9a..a10cead 100644 --- a/payload.json +++ b/payload.json @@ -3,6 +3,7 @@ "token": "pw_tok_example_abc123", "hostname": "web-1", "collector_version": "0.2.0", + "next_update_check": "2026-02-25T16:30:00+10:00", "uptime": 92582, "system": { "os": "linux",