Files
jbergner 4e2c648ede
Some checks failed
release-tag / release-image (push) Has been cancelled
2.0.0 Production-RC
2026-07-24 07:23:59 +02:00

55 lines
2.8 KiB
Go

package app
import (
"fmt"
"net/http"
"sync/atomic"
"time"
)
type metrics struct {
startedAt time.Time
requests atomic.Uint64
badgeRenders atomic.Uint64
validationRequests atomic.Uint64
validationFailures atomic.Uint64
bulkRequests atomic.Uint64
bulkItems atomic.Uint64
bulkFailures atomic.Uint64
panics atomic.Uint64
}
func newMetrics() *metrics { return &metrics{startedAt: time.Now()} }
func (m *metrics) serveHTTP(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/plain; version=0.0.4; charset=utf-8")
w.Header().Set("Cache-Control", "no-store")
fmt.Fprintf(w, "# HELP ai_disclosure_uptime_seconds Process uptime in seconds.\n")
fmt.Fprintf(w, "# TYPE ai_disclosure_uptime_seconds gauge\n")
fmt.Fprintf(w, "ai_disclosure_uptime_seconds %.0f\n", time.Since(m.startedAt).Seconds())
fmt.Fprintf(w, "# HELP ai_disclosure_http_requests_total Total HTTP requests.\n")
fmt.Fprintf(w, "# TYPE ai_disclosure_http_requests_total counter\n")
fmt.Fprintf(w, "ai_disclosure_http_requests_total %d\n", m.requests.Load())
fmt.Fprintf(w, "# HELP ai_disclosure_badge_renders_total Total rendered SVG badges.\n")
fmt.Fprintf(w, "# TYPE ai_disclosure_badge_renders_total counter\n")
fmt.Fprintf(w, "ai_disclosure_badge_renders_total %d\n", m.badgeRenders.Load())
fmt.Fprintf(w, "# HELP ai_disclosure_validation_requests_total Total validation requests.\n")
fmt.Fprintf(w, "# TYPE ai_disclosure_validation_requests_total counter\n")
fmt.Fprintf(w, "ai_disclosure_validation_requests_total %d\n", m.validationRequests.Load())
fmt.Fprintf(w, "# HELP ai_disclosure_validation_failures_total Failed validation requests.\n")
fmt.Fprintf(w, "# TYPE ai_disclosure_validation_failures_total counter\n")
fmt.Fprintf(w, "ai_disclosure_validation_failures_total %d\n", m.validationFailures.Load())
fmt.Fprintf(w, "# HELP ai_disclosure_bulk_requests_total Total bulk API requests.\n")
fmt.Fprintf(w, "# TYPE ai_disclosure_bulk_requests_total counter\n")
fmt.Fprintf(w, "ai_disclosure_bulk_requests_total %d\n", m.bulkRequests.Load())
fmt.Fprintf(w, "# HELP ai_disclosure_bulk_items_total Total items submitted to the bulk API.\n")
fmt.Fprintf(w, "# TYPE ai_disclosure_bulk_items_total counter\n")
fmt.Fprintf(w, "ai_disclosure_bulk_items_total %d\n", m.bulkItems.Load())
fmt.Fprintf(w, "# HELP ai_disclosure_bulk_failures_total Rejected or malformed bulk API requests.\n")
fmt.Fprintf(w, "# TYPE ai_disclosure_bulk_failures_total counter\n")
fmt.Fprintf(w, "ai_disclosure_bulk_failures_total %d\n", m.bulkFailures.Load())
fmt.Fprintf(w, "# HELP ai_disclosure_panics_total Recovered handler panics.\n")
fmt.Fprintf(w, "# TYPE ai_disclosure_panics_total counter\n")
fmt.Fprintf(w, "ai_disclosure_panics_total %d\n", m.panics.Load())
}