diff --git a/README.md b/README.md index b42ef07..de6b147 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,87 @@ See [Why Autometrics?](https://github.com/autometrics-dev#why-autometrics) for m - [⚙️ Configurable](#metrics-libraries) metric collection library (`opentelemetry`, `prometheus`, or `metrics`) - ⚡ Minimal runtime overhead +1. Add `autometrics` to your project: + + ```sh + pip3 install autometrics + ``` + +2. Instrument your functions with the [`@autometrics`](https://pypi.org/project/autometrics/) decorator + +
+ + Tip: Adding autometrics to all pub functions (not necessarily recommended 😅) + +
+ + You can use a search and replace to add autometrics to all public functions. Yes, this is a bit nuts. + + Use a regular expression search to replace: + + ``` + ((?:async)? def .*) + ``` + + With: + + ``` + @autometrics + $1 + ``` + + And then check which files you need to add `from autometrics import autometrics` at the top of. + +
+ +3. Export the metrics for Prometheus + +
+ + + For projects not currently using Prometheus metrics + + +
+ + Autometrics includes optional functions to help collect and prepare metrics to be collected by Prometheus. + + Create a route on your API (probably mounted under `/metrics`) that returns the following: + + ```py + from autometrics import autometrics + from fastapi import FastAPI, Response + from prometheus_client import start_http_server + + app = FastAPI() + + @app.get("/metrics") + def metrics(): + return Response(generate_latest()) + + ``` + +
+ +
+ + + For projects already using custom Prometheus metrics + + +
+ + Configure `autometrics` to use the same underlying metrics library you use with the appropriate feature flag (see [below](#metrics-libraries)). + + The `autometrics` metrics will be produced alongside yours. + + You do not need to use the Prometheus exporter functions this library provides (you can leave out the `prometheus-exporter` feature flag) and you do not need a separate endpoint for autometrics' metrics. + +
+ +4. [Configure Prometheus](https://github.com/autometrics-dev#5-configuring-prometheus) to scrape your metrics endpoint +5. (Optional) If you have Grafana, import the [Autometrics dashboards](https://github.com/autometrics-dev/autometrics-shared#dashboards) for an overview and detailed view of the function metrics + ## Using autometrics-py - Set up a [Prometheus instance](https://prometheus.io/download/)