feat: métriques serveur dans footer dashboard + notification offline WS

This commit is contained in:
Gilles Soulier
2026-05-22 17:46:55 +02:00
parent 6f79554cce
commit 8a8198a51a
5 changed files with 188 additions and 6 deletions
+26 -4
View File
@@ -234,13 +234,35 @@ func (d *DB) PruneOldMetrics(retentionDays int) error {
}
func (d *DB) MarkOffline(timeoutSec int64) error {
cutoff := time.Now().Unix() - timeoutSec
_, err := d.conn.Exec(
`UPDATE agents SET status='offline' WHERE last_seen < ? AND status != 'offline'`,
cutoff)
_, err := d.MarkOfflineAndGetIDs(timeoutSec)
return err
}
// MarkOfflineAndGetIDs marque les agents inactifs et retourne leurs IDs.
func (d *DB) MarkOfflineAndGetIDs(timeoutSec int64) ([]string, error) {
cutoff := time.Now().Unix() - timeoutSec
rows, err := d.conn.Query(
`SELECT id FROM agents WHERE last_seen < ? AND status != 'offline'`, cutoff)
if err != nil {
return nil, err
}
var ids []string
for rows.Next() {
var id string
_ = rows.Scan(&id)
ids = append(ids, id)
}
if err = rows.Err(); err != nil {
return nil, err
}
rows.Close()
if len(ids) > 0 {
_, err = d.conn.Exec(
`UPDATE agents SET status='offline' WHERE last_seen < ? AND status != 'offline'`, cutoff)
}
return ids, err
}
func init() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
}