mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-09-17 07:02:43 +00:00
Implements optional Prometheus metrics collection with secure endpoint for monitoring and observability. Features: - Disabled by default, enabled via ENABLE_METRICS environment variable - Secure token-based authentication with Argon2 hashing support - Comprehensive metrics collection across all system components - Conditional compilation with enable_metrics feature flag - HTTP request instrumentation with automatic path normalization - Database connection pool and query performance monitoring - Authentication attempt tracking and session management - Business metrics for users, organizations, and vault items - System uptime and build information tracking Security: - Token authentication required (METRICS_TOKEN configuration) - Support for both plain text and Argon2 hashed tokens - Path normalization prevents high cardinality metric explosion - No-op implementations when metrics disabled for zero overhead - Network access controls recommended for production deployment Implementation: - Added prometheus dependency with conditional compilation - Created secure /metrics endpoint with request guard authentication - Implemented HTTP middleware fairing for automatic instrumentation - Added database metrics utilities with timing macros - Comprehensive unit and integration test coverage - Complete documentation with Prometheus, Grafana, and alerting examples Files added: - src/metrics.rs - Core metrics collection module - src/api/metrics.rs - Secure metrics endpoint implementation - src/api/middleware.rs - HTTP request instrumentation - src/db/metrics.rs - Database timing utilities - METRICS.md - Configuration and usage guide - MONITORING.md - Complete monitoring setup documentation - examples/metrics-config.env - Configuration examples - scripts/test-metrics.sh - Automated testing script - Comprehensive test suites for both enabled/disabled scenarios This implementation follows security best practices with disabled-by-default configuration and provides production-ready monitoring capabilities for Vaultwarden deployments. |
||
---|---|---|
.. | ||
metrics_integration_test.rs |