Overview
Secure Link API exposes comprehensive metrics through Prometheus and Micrometer. The application tracks both technical metrics (JVM, HTTP requests) and business metrics (link operations, access patterns).Prometheus Endpoint
Metrics are exposed in Prometheus format:Example Output
Micrometer Integration
The application uses Micrometer for metrics collection, with Prometheus as the export format.Dependencies
Metric Types
Micrometer supports several metric types used throughout the application:- Counter - Monotonically increasing values (link creations, access attempts)
- Timer - Duration and rate of events (link resolution time)
- Gauge - Current value that can go up or down (active sessions)
Custom Business Metrics
Link Creation Metrics
Tracks secure link creation operations. Implementation:br.com.walyson.secure_link.service.impl.CreateLinkServiceImpl:53
secure_link_created_totalType: Counter
Tags:
type- Link type:REDIRECTorDOWNLOAD
Link Resolution Metrics
Tracks link access attempts and outcomes. Implementation:br.com.walyson.secure_link.service.impl.ResolveLinkServiceImpl:53
Attempts Counter
secure_link_resolve_attempts_totalType: Counter
Description: Total number of link resolution attempts (successful and failed)
Success Counter
secure_link_resolve_success_totalType: Counter
Description: Successfully resolved link accesses
Denied Counter
secure_link_resolve_denied_totalType: Counter
Tags:
reason- Denial reason:not_found- Link doesn’t existexpired- Link has expiredrevoked- Link was revokedview_limit_reached- Maximum views exceededinactive- Link is in unexpected statepassword_required- Password authentication neededinvalid_password- Incorrect password provided
Resolution Duration Timer
Measures the time spent resolving link accesses. Implementation:br.com.walyson.secure_link.service.impl.ResolveLinkServiceImpl:48
secure_link_resolve_duration_secondsType: Timer
Description: Time spent processing link resolution requests Usage:
Link Revocation Metrics
Tracks link revocation operations. Implementation:br.com.walyson.secure_link.service.impl.RevokeLinkServiceImpl:31
Revoked Counter
secure_link_revoked_totalType: Counter
Description: Successfully revoked links
Revoke Denied Counter
secure_link_revoke_denied_totalType: Counter
Tags:
reason- Denial reason:not_found
Standard Spring Boot Metrics
In addition to custom metrics, the application automatically exports standard Spring Boot metrics:JVM Metrics
jvm_memory_used_bytes- JVM memory usagejvm_memory_max_bytes- Maximum JVM memoryjvm_gc_pause_seconds- Garbage collection pause timesjvm_threads_live_threads- Current thread countprocess_cpu_usage- Process CPU usage
HTTP Metrics
http_server_requests_seconds- HTTP request duration and count- Tags:
method,status,uri,exception
- Tags:
Database Metrics (HikariCP)
hikaricp_connections_active- Active database connectionshikaricp_connections_idle- Idle database connectionshikaricp_connections_pending- Connections waiting to be acquiredhikaricp_connections_timeout_total- Connection timeout count
Logback Metrics
logback_events_total- Log events by level- Tags:
level(DEBUG, INFO, WARN, ERROR)
- Tags:
Configuration
Enabling Prometheus Endpoint
Enable the Prometheus endpoint inapplication.properties:
Custom Metric Tags
Add global tags to all metrics:Metric Filters
Disable specific metrics if needed:Prometheus Server Configuration
Configure Prometheus to scrape the metrics endpoint:Grafana Dashboard
Recommended Panels
-
Link Creation Rate
-
Access Success Rate
-
Average Resolution Time
-
Error Rate by Reason
-
JVM Memory Usage
-
HTTP Request Rate
Alerting Rules
High Error Rate
Slow Response Times
High Memory Usage
All custom business metrics use the
secure_link_ prefix for easy identification and filtering in Prometheus queries.Best Practices
- Use Consistent Naming - Follow the
<namespace>_<name>_<unit>convention - Add Meaningful Tags - Use tags to enable flexible querying and aggregation
- Avoid High Cardinality - Don’t use user IDs or timestamps as tag values
- Monitor What Matters - Focus on metrics that indicate user impact
- Set Up Alerts - Configure alerts for critical business and technical metrics
- Track Trends - Monitor rate of change, not just absolute values
Troubleshooting
Metrics Not Appearing
Check:- Actuator dependency is included
- Prometheus endpoint is exposed in configuration
- Prometheus is successfully scraping the endpoint
- No firewall blocking the metrics endpoint
High Metric Cardinality
Symptoms: Prometheus performance degradation, high memory usage Causes: Using high-cardinality values as metric tags (user IDs, correlation IDs) Resolution: Remove high-cardinality tags, use labels sparinglyMissing Custom Metrics
Verify:MeterRegistryis properly injected- Metric registration code is executed
- Metric names don’t contain invalid characters
- Counter
.increment()is actually called
