You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+81
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,87 @@ See [Why Autometrics?](https://github.com/autometrics-dev#why-autometrics) for m
24
24
-[⚙️ Configurable](#metrics-libraries) metric collection library (`opentelemetry`, `prometheus`, or `metrics`)
25
25
- ⚡ Minimal runtime overhead
26
26
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
+
defmetrics():
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
+
27
108
## Using autometrics-py
28
109
29
110
- Set up a [Prometheus instance](https://prometheus.io/download/)
0 commit comments