Running Prometheus locally (for testing)
Once you have your code instrumented with Autometrics, you'll need to run Prometheus (opens in a new tab) and point it at your app. The easiest way to run Prometheus locally is with the am
CLI, see here for instructions
Prometheus is pull-based, meaning: it will poll your app on a specified endpoint to scrape the metrics collected. This means that the app should be accessible to the running Prometheus service.
Download and install Prometheus
brew install prometheus
Create a configuration file
Create a file called prometheus.yml
with the following contents:
prometheus.yml
scrape_configs:
- job_name: my-app
metrics_path: /metrics
static_configs:
# Replace the port with the port your /metrics endpoint is running on
- targets: ['localhost:3000']
# For a real deployment, you would want the scrape interval to be
# longer but for testing, you want the data to show up quickly
scrape_interval: 200ms
Run Prometheus
You can now run Prometheus with the configuration file you created:
prometheus --config.file=prometheus.yml
Or with Docker:
docker run \
-p 9090:9090 \
-v prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus