feat(agent) multi-driver db monitoring, hot-plug config, release pipeline

This commit is contained in:
2026-06-15 17:29:53 +01:00
parent db6ed003f1
commit 40811ed6e8
17 changed files with 949 additions and 34 deletions

View File

@@ -15,22 +15,36 @@ type Window struct {
diskCount uint64
uptime uint64
// DB metrics — populated only when a DB collector is registered.
hasDB bool
dbDriver uint8
dbConnPctSum float64
dbConnPctCount uint64
dbThreadsSum float64
dbThreadsCount uint64
dbSlowQueriesDelta uint64
dbSizeBytes uint64
}
type Snapshot struct {
Timestamp time.Time
CPUAvg float64
MemAvg float64
CPUAvg float64
MemAvg float64
DiskAvg float64
Uptime uint64
Uptime uint64
// nil when DB monitoring is not enabled.
DBDriver *uint8
DBConnPct *float64
DBThreadsRunning *float64
DBSlowQueries *uint64
DBSizeBytes *uint64
}
func NewWindow() *Window {
return &Window{
start: time.Now(),
}
return &Window{start: time.Now()}
}
func (w *Window) AddCPU(value float64) {
@@ -43,10 +57,41 @@ func (w *Window) AddMemory(value float64) {
w.memCount++
}
func (w *Window) AddDisk(value float64) {
w.diskSum += value
w.diskCount++
}
func (w *Window) SetUptime(value uint64) {
w.uptime = value
}
func (w *Window) AddDBConnPct(v float64) {
w.dbConnPctSum += v
w.dbConnPctCount++
w.hasDB = true
}
func (w *Window) AddDBThreadsRunning(v float64) {
w.dbThreadsSum += v
w.dbThreadsCount++
}
func (w *Window) AddDBSlowQueriesDelta(v uint64) {
w.dbSlowQueriesDelta += v
}
func (w *Window) SetDBSizeBytes(v uint64) {
w.dbSizeBytes = v
w.hasDB = true
}
// SetDBDriver records the numeric driver identifier (see dbmanager.Driver* constants).
// When multiple collectors are active this is called once per window by the manager.
func (w *Window) SetDBDriver(v uint8) {
w.dbDriver = v
}
func (w *Window) Ready(windowDuration time.Duration) bool {
return time.Since(w.start) >= windowDuration
}
@@ -67,16 +112,36 @@ func (w *Window) Snapshot() Snapshot {
diskAvg = w.diskSum / float64(w.diskCount)
}
return Snapshot{
snap := Snapshot{
Timestamp: time.Now(),
CPUAvg: cpuAvg,
MemAvg: memAvg,
DiskAvg: diskAvg,
Uptime: w.uptime,
}
}
func (w *Window) AddDisk(value float64) {
w.diskSum += value
w.diskCount++
}
if w.hasDB {
driver := w.dbDriver
var connPct float64
if w.dbConnPctCount > 0 {
connPct = w.dbConnPctSum / float64(w.dbConnPctCount)
}
var threads float64
if w.dbThreadsCount > 0 {
threads = w.dbThreadsSum / float64(w.dbThreadsCount)
}
slow := w.dbSlowQueriesDelta
sizeBytes := w.dbSizeBytes
snap.DBDriver = &driver
snap.DBConnPct = &connPct
snap.DBThreadsRunning = &threads
snap.DBSlowQueries = &slow
snap.DBSizeBytes = &sizeBytes
}
return snap
}