Skip to content

Commit 3f246b8

Browse files
author
Brett Beutell
committed
Quickstart: First pass
1 parent 7ec7ee6 commit 3f246b8

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

README.md

+81
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,87 @@ See [Why Autometrics?](https://github.com/autometrics-dev#why-autometrics) for m
2424
- [⚙️ Configurable](#metrics-libraries) metric collection library (`opentelemetry`, `prometheus`, or `metrics`)
2525
- ⚡ Minimal runtime overhead
2626

27+
1. Add `autometrics` to your project:
28+
29+
```sh
30+
pip3 install autometrics
31+
```
32+
33+
2. Instrument your functions with the [`@autometrics`](https://pypi.org/project/autometrics/) decorator
34+
35+
<details>
36+
37+
<summary> Tip: Adding autometrics to all <code>pub</code> functions (not necessarily recommended 😅)
38+
</summary>
39+
<br />
40+
41+
You can use a search and replace to add autometrics to all public functions. Yes, this is a bit nuts.
42+
43+
Use a regular expression search to replace:
44+
45+
```
46+
((?:async)? def .*)
47+
```
48+
49+
With:
50+
51+
```
52+
@autometrics
53+
$1
54+
```
55+
56+
And then check which files you need to add `from autometrics import autometrics` at the top of.
57+
58+
</details>
59+
60+
3. Export the metrics for Prometheus
61+
62+
<details>
63+
64+
<summary>
65+
For projects not currently using Prometheus metrics
66+
</summary>
67+
68+
<br />
69+
70+
Autometrics includes optional functions to help collect and prepare metrics to be collected by Prometheus.
71+
72+
Create a route on your API (probably mounted under `/metrics`) that returns the following:
73+
74+
```py
75+
from autometrics import autometrics
76+
from fastapi import FastAPI, Response
77+
from prometheus_client import start_http_server
78+
79+
app = FastAPI()
80+
81+
@app.get("/metrics")
82+
def metrics():
83+
return Response(generate_latest())
84+
85+
```
86+
87+
</details>
88+
89+
<details>
90+
91+
<summary>
92+
For projects already using custom Prometheus metrics
93+
</summary>
94+
95+
<br />
96+
97+
Configure `autometrics` to use the same underlying metrics library you use with the appropriate feature flag (see [below](#metrics-libraries)).
98+
99+
The `autometrics` metrics will be produced alongside yours.
100+
101+
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.
102+
103+
</details>
104+
105+
4. [Configure Prometheus](https://github.com/autometrics-dev#5-configuring-prometheus) to scrape your metrics endpoint
106+
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
107+
27108
## Using autometrics-py
28109

29110
- Set up a [Prometheus instance](https://prometheus.io/download/)

0 commit comments

Comments
 (0)