An example fastapi app that makes use of autometrics.
Skip this if you already have Prometheus set up locally
There is a docker-compose setup in the Quickmetrics repo, which can spin up Prometheus (and other components) for you.
Follow instructions in autometrics-dev. I used Docker:
docker pull prom/prometheus
# I'm using port 8063 for prometheus because 9090 is already taken on my machine
docker run \
-p 8063:9090 \
-v /absolute/path/to/this/project/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
where the prometheus.yml
file is similar to the one in this repo:
scrape_configs:
- job_name: python-autometrics-example-fastapi
metrics_path: /metrics
static_configs:
- targets: ["localhost:8080"]
# 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
Create and activate a virtual env
python3 -m venv .venv
source .venv/bin/activate
Install dependencies
pip install -r requirements.txt
Run the app
uvicorn fastapi-example:app --reload --port=8080
...
Update the VSCode Extension settings to use the url to your local Prometheus server. Since I'm not using the default port (9090
), I need to update the settings:
{
"autometrics.prometheusUrl": "http://localhost:8063"
}