summaryrefslogtreecommitdiff
path: root/internal/daemon/daemon.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-16 08:47:11 +0300
committerPaul Buetow <paul@buetow.org>2026-04-16 08:47:11 +0300
commit442236f8515e761c1bd97f2cf3fd6b102bdecb64 (patch)
treedbeb4f48688f7d5bec72f858b2c4fafc1b2fa96d /internal/daemon/daemon.go
parentedeffd05dc62c4c3d747cc41067bf4e1814f300a (diff)
Add /metrics Prometheus endpoint to daemon mode
Exposes a gauge per host tracking the Unix timestamp of the last records file update. Excluded hosts (from the excluded_host table) are labeled excluded="true" so alerting rules can filter them out. Uses manual Prometheus text format to avoid adding a new dependency. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/daemon/daemon.go')
-rw-r--r--internal/daemon/daemon.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go
index e4f07f6..326224e 100644
--- a/internal/daemon/daemon.go
+++ b/internal/daemon/daemon.go
@@ -31,6 +31,7 @@ type Config struct {
StatsDir string
Addr string
AuthDB string
+ DB string
LogOutput io.Writer
}
@@ -41,16 +42,17 @@ func NewHandler(statsDir string) (http.Handler, error) {
if err != nil {
return nil, fmt.Errorf("auth db: %w", err)
}
- return routes(statsDir, "", store), nil
+ return routes(statsDir, "", "", store), nil
}
-func routes(statsDir, authDB string, store *authkeys.Store) http.Handler {
+func routes(statsDir, authDB, db string, store *authkeys.Store) http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/", root(statsDir))
mux.HandleFunc("/health", health)
mux.HandleFunc("/livez", health)
mux.HandleFunc("/readyz", readiness(statsDir, authDB))
mux.HandleFunc("/report", report(statsDir))
+ mux.HandleFunc("/metrics", metricsHandler(statsDir, db))
mux.Handle("/upload/", uploadHandler(statsDir, store))
return mux
}
@@ -151,7 +153,7 @@ func Run(ctx context.Context, cfg Config) error {
return fmt.Errorf("auth db: %w", err)
}
defer store.Close()
- srv := newDaemonHTTPServer(cfg.Addr, withAccessLog(slogLog, routes(cfg.StatsDir, cfg.AuthDB, store)),
+ srv := newDaemonHTTPServer(cfg.Addr, withAccessLog(slogLog, routes(cfg.StatsDir, cfg.AuthDB, cfg.DB, store)),
slog.NewLogLogger(textHandler, slog.LevelError))
slogLog.Info("daemon_listen", "addr", cfg.Addr)
errCh := make(chan error, 1)