Add internal/metrics package with dedicated Prometheus registry exposing SSH connection, auth attempt, session, and build info metrics. Wire into SSH server (4 instrumentation points) and web server (/metrics endpoint). Add dockerImage output to flake.nix via dockerTools.buildLayeredImage. Bump version to 0.7.0. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package web
|
|
|
|
import (
|
|
"embed"
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"git.t-juice.club/torjus/oubliette/internal/storage"
|
|
)
|
|
|
|
//go:embed static/*
|
|
var staticFS embed.FS
|
|
|
|
// Server is the web dashboard HTTP server.
|
|
type Server struct {
|
|
store storage.Store
|
|
logger *slog.Logger
|
|
mux *http.ServeMux
|
|
tmpl *templateSet
|
|
}
|
|
|
|
// NewServer creates a new web Server with routes registered.
|
|
// If metricsHandler is non-nil, a /metrics endpoint is registered.
|
|
func NewServer(store storage.Store, logger *slog.Logger, metricsHandler http.Handler) (*Server, error) {
|
|
tmpl, err := loadTemplates()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
s := &Server{
|
|
store: store,
|
|
logger: logger,
|
|
mux: http.NewServeMux(),
|
|
tmpl: tmpl,
|
|
}
|
|
|
|
s.mux.Handle("GET /static/", http.FileServerFS(staticFS))
|
|
s.mux.HandleFunc("GET /sessions/{id}", s.handleSessionDetail)
|
|
s.mux.HandleFunc("GET /api/sessions/{id}/events", s.handleAPISessionEvents)
|
|
s.mux.HandleFunc("GET /", s.handleDashboard)
|
|
s.mux.HandleFunc("GET /fragments/stats", s.handleFragmentStats)
|
|
s.mux.HandleFunc("GET /fragments/active-sessions", s.handleFragmentActiveSessions)
|
|
|
|
if metricsHandler != nil {
|
|
s.mux.Handle("GET /metrics", metricsHandler)
|
|
}
|
|
|
|
return s, nil
|
|
}
|
|
|
|
// ServeHTTP delegates to the internal mux.
|
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
s.mux.ServeHTTP(w, r)
|
|
}
|