Files
drip/internal/server/metrics/metrics.go
Gouryella 11ca454659 feat(server): Adds server configuration management commands and metric monitoring functionality.
- Add a new `server config` command to display server configuration.
- Supports displaying the full token via the --full flag.
- Add the metrics-token configuration option for monitoring access control.
- Integrate Prometheus metrics monitoring system
- Add the /metrics endpoint to provide monitoring data in Prometheus format.
- Add detailed metric collection for tunnels, connections, traffic, etc.
- Add a link to the metrics endpoint on the homepage
refactor: Refactor the token display logic to support full display options.
- Refactor the token mask logic in the configuration display
- Supports controlling the token display method via the configFull flag.
build: Update dependency versions
- Updated github.com/spf13/cobra from v1.10.1 to v1.10.2
- Updated golang.org/x/crypto from v0.45.0 to v0.46.0
- Updated golang.org/x/net from v0.47.0 to v0.48.0
- Update golang.org/x/sys from v0.38.0 to v0.39.0
- Added several new indirect dependency packages, including Prometheus-related components.
- Update the versions of several existing dependency packages.
2026-01-03 16:50:28 +08:00

107 lines
3.2 KiB
Go

package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
// Tunnel metrics
TunnelCount = promauto.NewGauge(prometheus.GaugeOpts{
Name: "drip_tunnel_count",
Help: "Current number of active tunnels",
})
TunnelRegistrations = promauto.NewCounter(prometheus.CounterOpts{
Name: "drip_tunnel_registrations_total",
Help: "Total number of tunnel registrations",
})
TunnelRegistrationFailures = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "drip_tunnel_registration_failures_total",
Help: "Total number of failed tunnel registrations",
}, []string{"reason"})
TunnelsByIP = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "drip_tunnels_by_ip",
Help: "Number of tunnels per client IP",
}, []string{"ip"})
// Connection metrics
ActiveConnections = promauto.NewGauge(prometheus.GaugeOpts{
Name: "drip_active_connections",
Help: "Current number of active TCP connections",
})
TotalConnections = promauto.NewCounter(prometheus.CounterOpts{
Name: "drip_connections_total",
Help: "Total number of connections handled",
})
// Traffic metrics
BytesReceived = promauto.NewCounter(prometheus.CounterOpts{
Name: "drip_bytes_received_total",
Help: "Total bytes received",
})
BytesSent = promauto.NewCounter(prometheus.CounterOpts{
Name: "drip_bytes_sent_total",
Help: "Total bytes sent",
})
RequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "drip_requests_total",
Help: "Total number of HTTP requests handled",
})
// Per-tunnel metrics
TunnelBytesReceived = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "drip_tunnel_bytes_received_total",
Help: "Total bytes received per tunnel",
}, []string{"tunnel_id", "subdomain", "type"})
TunnelBytesSent = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "drip_tunnel_bytes_sent_total",
Help: "Total bytes sent per tunnel",
}, []string{"tunnel_id", "subdomain", "type"})
TunnelActiveConnections = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "drip_tunnel_active_connections",
Help: "Current number of active connections per tunnel",
}, []string{"tunnel_id", "subdomain", "type"})
// Rate limiting metrics
RateLimitRejections = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "drip_rate_limit_rejections_total",
Help: "Total number of rate limit rejections",
}, []string{"type", "ip"})
// System metrics
PanicTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "drip_panic_total",
Help: "Total number of panics recovered",
})
WorkerPoolSize = promauto.NewGauge(prometheus.GaugeOpts{
Name: "drip_worker_pool_size",
Help: "Current worker pool size",
})
WorkerPoolActiveWorkers = promauto.NewGauge(prometheus.GaugeOpts{
Name: "drip_worker_pool_active_workers",
Help: "Current number of active workers",
})
// HTTP proxy metrics
HTTPRequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "drip_http_request_duration_seconds",
Help: "HTTP request duration in seconds",
Buckets: prometheus.DefBuckets,
}, []string{"method", "status"})
HTTPRequestsInFlight = promauto.NewGauge(prometheus.GaugeOpts{
Name: "drip_http_requests_in_flight",
Help: "Current number of HTTP requests being processed",
})
)