This guide explains how to configure the experimental Prometheus metrics endpoint in GoModel.Documentation Index
Fetch the complete documentation index at: https://gomodel-docs-providers-restructure.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Quick Start
Disabled by Default
Metrics are disabled by default. To enable metrics collection, setMETRICS_ENABLED=true and start GoModel:
Disable Metrics
Option 1: Environment VariableCustom Metrics Endpoint
Change the default/metrics path:
Configuration Options
Via Environment Variables
| Variable | Default | Description |
|---|---|---|
METRICS_ENABLED | false | Enable/disable metrics collection |
METRICS_ENDPOINT | /metrics | HTTP path for metrics endpoint |
Via config.yaml
Examples
Production Setup (Metrics Enabled)
.envDevelopment Setup (Metrics Disabled)
.envCustom Endpoint for Internal Monitoring
config.yamlVerification
Check if Metrics are Enabled
Start the server and look for log messages: Metrics Enabled:Test Metrics Endpoint
When Enabled:Performance Impact
Metrics Enabled
- Minimal overhead: ~100ns per request for hook execution
- Memory: ~1MB for metric storage (depends on cardinality)
- CPU: Negligible impact (
<0.1%in benchmarks)
Metrics Disabled
- Zero overhead: no hooks registered, no collection
- The metrics library is still linked but inactive
- Recommended for maximum performance in non-production environments
Security Considerations
Exposing the Metrics Endpoint
The/metrics endpoint is protected by master key authentication when a master
key is configured, just like other HTTP endpoints. If no master key is
configured, the endpoint is accessible without authentication, which allows
Prometheus to scrape metrics without credentials.
If you need to protect the metrics endpoint further:
-
Use a custom internal path:
-
Use network-level security:
- Configure firewall rules to allow only the Prometheus server
- Use a private network for metrics collection
- Deploy Prometheus in the same VPC/network
-
Reverse proxy with authentication:
Prometheus Configuration
Scrape Config
prometheus.ymlWith Custom Endpoint
Troubleshooting
Metrics Endpoint Returns 404
Cause: metrics are disabled (the default). Solution:No Metrics Data Appearing
Cause: no requests have been made yet. Solution: make some requests to generate metrics:Custom Endpoint Not Working
Cause: the endpoint must start with/.
Incorrect:
Best Practices
Development
- Disable metrics for faster startup and reduced noise
- Enable only when testing observability features
Staging
- Enable metrics to test the monitoring setup
- Use a custom endpoint if needed for security
Production
- Enable metrics for full observability
- Set up Prometheus alerting
- Use Grafana dashboards for visualization
- Consider a custom endpoint for security
- Monitor metric cardinality to avoid explosion
See Also
- Configuration — full environment variable reference
- config.yaml — YAML configuration reference