Skip to main content
Prometheus support is experimental. The metric names, labels, and configuration surface may change without notice. Pin to a specific GoModel version if you depend on a stable schema.
This guide explains how to configure the experimental Prometheus metrics endpoint in GoModel.

Quick Start

Disabled by Default

Metrics are disabled by default. To enable metrics collection, set METRICS_ENABLED=true and start GoModel:
The rest of this guide shows just the variable being set. Apply it via whichever launcher you picked above — .env plus --env-file, an inline -e flag, or export before ./bin/gomodel — and restart GoModel.

Disable Metrics

Option 1: Environment Variable
Option 2: .env file
Option 3: config.yaml

Custom Metrics Endpoint

Change the default /metrics path:

Configuration Options

Via Environment Variables

VariableDefaultDescription
METRICS_ENABLEDfalseEnable/disable metrics collection
METRICS_ENDPOINT/metricsHTTP path for metrics endpoint

Via config.yaml

Examples

Production Setup (Metrics Enabled)

.env

Development Setup (Metrics Disabled)

.env

Custom Endpoint for Internal Monitoring

config.yaml

Verification

Check if Metrics are Enabled

Start the server and look for log messages: Metrics Enabled:
Metrics Disabled:

Test Metrics Endpoint

When Enabled:
When Disabled:

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:
  1. Use a custom internal path:
  2. 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
  3. Reverse proxy with authentication:

Prometheus Configuration

Scrape Config

prometheus.yml

With Custom Endpoint

Troubleshooting

Metrics Endpoint Returns 404

Cause: metrics are disabled (the default). Solution:
Set METRICS_ENABLED=true via your .env file, an inline -e METRICS_ENABLED=true flag, or export METRICS_ENABLED=true (see the Quick Start for the three launch forms), then restart GoModel.

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:
Correct:

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