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

@@ -7,30 +7,44 @@ import (
"net/http"
"time"
"bugs.watch/agent/internal/config"
"bugs.watch/agent/internal/aggregate"
)
type HTTPSender struct {
client *http.Client
endpoint string
token string
hostID string
env string
}
func NewHTTPSender(endpoint string) *HTTPSender {
func NewHTTPSender(cfg config.Config) *HTTPSender {
return &HTTPSender{
client: &http.Client{
Timeout: 5 * time.Second,
},
endpoint: endpoint,
endpoint: cfg.Endpoint + "/api/v1/agents/" + cfg.AgentID,
token: cfg.APIToken,
hostID: cfg.HostID,
env: cfg.Env,
}
}
func (s *HTTPSender) Send(ctx context.Context, snap aggregate.Snapshot) error {
payload := SnapshotPayload{
Timestamp: snap.Timestamp,
CPUAvg: snap.CPUAvg,
MemAvg: snap.MemAvg,
DiskAvg: snap.DiskAvg,
Uptime: snap.Uptime,
Timestamp: snap.Timestamp,
CPUAvg: snap.CPUAvg,
MemAvg: snap.MemAvg,
DiskAvg: snap.DiskAvg,
Uptime: snap.Uptime,
HostID: s.hostID,
Environment: s.env,
DBDriver: snap.DBDriver,
DBConnPct: snap.DBConnPct,
DBThreadsRunning: snap.DBThreadsRunning,
DBSlowQueries: snap.DBSlowQueries,
DBSizeBytes: snap.DBSizeBytes,
}
body, err := json.Marshal(payload)
@@ -40,7 +54,7 @@ func (s *HTTPSender) Send(ctx context.Context, snap aggregate.Snapshot) error {
req, err := http.NewRequestWithContext(
ctx,
http.MethodPost,
http.MethodPut,
s.endpoint,
bytes.NewReader(body),
)
@@ -49,6 +63,7 @@ func (s *HTTPSender) Send(ctx context.Context, snap aggregate.Snapshot) error {
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer " + s.token)
resp, err := s.client.Do(req)
if err != nil {

View File

@@ -9,6 +9,16 @@ type SnapshotPayload struct {
CPUAvg float64 `json:"cpu_avg"`
MemAvg float64 `json:"mem_avg"`
DiskAvg float64 `json:"disk_avg"`
Uptime uint64 `json:"uptime"`
Uptime uint64 `json:"uptime"`
HostID string `json:"host_id,omitempty"`
Environment string `json:"environment,omitempty"`
// Optional — only present when DB monitoring is enabled.
// DBDriver is a numeric identifier: 1=mysql/mariadb 2=postgres 3=redis 4=mongodb 5=sqlite
DBDriver *uint8 `json:"db_driver,omitempty"`
DBConnPct *float64 `json:"db_conn_pct,omitempty"`
DBThreadsRunning *float64 `json:"db_threads_running,omitempty"`
DBSlowQueries *uint64 `json:"db_slow_queries,omitempty"`
DBSizeBytes *uint64 `json:"db_size_bytes,omitempty"`
}