Self-contained HTTP/HTTPS/TCP/UDP reverse proxy manager written in Go, with SQLite storage, a Bootstrap 5 admin UI (Go templates, no JS framework), and a REST API under /api/v1. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QTXFrNP1imCW7jtfL5SZrw
70 lines
2.5 KiB
Go
70 lines
2.5 KiB
Go
// Package metrics exposes Prometheus counters/gauges/histograms for HTTP,
|
|
// TCP/UDP, backend, and TLS activity.
|
|
package metrics
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
)
|
|
|
|
var (
|
|
HTTPRequestsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Name: "vibeproxy_http_requests_total",
|
|
Help: "Total HTTP requests handled by the proxy.",
|
|
}, []string{"proxy_host", "method", "status"})
|
|
|
|
HTTPRequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
Name: "vibeproxy_http_request_duration_seconds",
|
|
Help: "HTTP request latency observed by the proxy, end to end.",
|
|
Buckets: prometheus.DefBuckets,
|
|
}, []string{"proxy_host"})
|
|
|
|
BackendRequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
Name: "vibeproxy_backend_request_duration_seconds",
|
|
Help: "Backend response latency as observed by the proxy.",
|
|
Buckets: prometheus.DefBuckets,
|
|
}, []string{"proxy_host", "backend"})
|
|
|
|
BytesTransferred = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Name: "vibeproxy_bytes_transferred_total",
|
|
Help: "Bytes transferred through the proxy.",
|
|
}, []string{"direction", "protocol"}) // direction=in|out, protocol=http|tcp|udp
|
|
|
|
ActiveConnections = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
|
Name: "vibeproxy_active_connections",
|
|
Help: "Currently active connections.",
|
|
}, []string{"protocol"}) // http|tcp|udp
|
|
|
|
BackendHealth = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
|
Name: "vibeproxy_backend_healthy",
|
|
Help: "1 if the backend is currently considered healthy, else 0.",
|
|
}, []string{"proxy_host", "backend"})
|
|
|
|
TCPConnectionsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Name: "vibeproxy_tcp_connections_total",
|
|
Help: "Total TCP stream connections accepted.",
|
|
}, []string{"stream"})
|
|
|
|
UDPPacketsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Name: "vibeproxy_udp_packets_total",
|
|
Help: "Total UDP packets proxied.",
|
|
}, []string{"stream", "direction"})
|
|
|
|
TLSHandshakesTotal = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Name: "vibeproxy_tls_handshakes_total",
|
|
Help: "Total TLS handshakes, by result.",
|
|
}, []string{"result"}) // ok|error
|
|
|
|
CertificateExpirySeconds = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
|
Name: "vibeproxy_certificate_expiry_seconds",
|
|
Help: "Seconds until certificate expiry (negative if already expired).",
|
|
}, []string{"name"})
|
|
)
|
|
|
|
func Handler() http.Handler {
|
|
return promhttp.Handler()
|
|
}
|