mirror of
https://github.com/wearepixel/pulsewise-collector.git
synced 2026-11-14 22:12:01 +00:00
feat: include next_update_check timestamp in every pulse payload
This commit is contained in:
@@ -60,8 +60,9 @@ type Metrics struct {
|
|||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
CollectorVersion string `json:"collector_version"`
|
CollectorVersion string `json:"collector_version"`
|
||||||
Uptime uint64 `json:"uptime"`
|
NextUpdateCheck *time.Time `json:"next_update_check,omitempty"`
|
||||||
|
Uptime uint64 `json:"uptime"`
|
||||||
System SystemInfo `json:"system"`
|
System SystemInfo `json:"system"`
|
||||||
LoadAvg LoadMetrics `json:"load_avg"`
|
LoadAvg LoadMetrics `json:"load_avg"`
|
||||||
CPU CPUMetrics `json:"cpu"`
|
CPU CPUMetrics `json:"cpu"`
|
||||||
@@ -154,6 +155,10 @@ type ProcessInfo struct {
|
|||||||
|
|
||||||
var prevNet *networkSnapshot
|
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() {
|
func main() {
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
@@ -457,7 +462,9 @@ type latestRelease struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runAutoUpdater(config *Config) {
|
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)
|
time.Sleep(30 * time.Second)
|
||||||
checkAndUpdate(config)
|
checkAndUpdate(config)
|
||||||
|
|
||||||
@@ -468,12 +475,18 @@ func runAutoUpdater(config *Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func scheduleNextUpdateCheck() {
|
||||||
|
t := time.Now().Add(updateCheckInterval)
|
||||||
|
nextUpdateCheck = &t
|
||||||
|
}
|
||||||
|
|
||||||
func checkAndUpdate(config *Config) {
|
func checkAndUpdate(config *Config) {
|
||||||
latest, err := fetchLatestVersion()
|
latest, err := fetchLatestVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if config.Debug {
|
if config.Debug {
|
||||||
log.Printf("[DEBUG] Update check failed: %v", err)
|
log.Printf("[DEBUG] Update check failed: %v", err)
|
||||||
}
|
}
|
||||||
|
scheduleNextUpdateCheck()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,6 +494,7 @@ func checkAndUpdate(config *Config) {
|
|||||||
if config.Debug {
|
if config.Debug {
|
||||||
log.Printf("[DEBUG] Already on latest version %s", version)
|
log.Printf("[DEBUG] Already on latest version %s", version)
|
||||||
}
|
}
|
||||||
|
scheduleNextUpdateCheck()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,6 +502,7 @@ func checkAndUpdate(config *Config) {
|
|||||||
|
|
||||||
if err := downloadAndReplace(); err != nil {
|
if err := downloadAndReplace(); err != nil {
|
||||||
log.Printf("Auto-update failed: %v", err)
|
log.Printf("Auto-update failed: %v", err)
|
||||||
|
scheduleNextUpdateCheck()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -699,6 +714,7 @@ func collectMetrics(config *Config) (*Metrics, error) {
|
|||||||
Token: config.Token,
|
Token: config.Token,
|
||||||
Hostname: config.Hostname,
|
Hostname: config.Hostname,
|
||||||
CollectorVersion: version,
|
CollectorVersion: version,
|
||||||
|
NextUpdateCheck: nextUpdateCheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uptime
|
// Uptime
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"token": "pw_tok_example_abc123",
|
"token": "pw_tok_example_abc123",
|
||||||
"hostname": "web-1",
|
"hostname": "web-1",
|
||||||
"collector_version": "0.2.0",
|
"collector_version": "0.2.0",
|
||||||
|
"next_update_check": "2026-02-25T16:30:00+10:00",
|
||||||
"uptime": 92582,
|
"uptime": 92582,
|
||||||
"system": {
|
"system": {
|
||||||
"os": "linux",
|
"os": "linux",
|
||||||
|
|||||||
Reference in New Issue
Block a user