1
- # Autometrics : chart_with_upwards_trend : : sparkles :
1
+ # Autometrics 📈✨
2
2
> Easily add metrics to your system -- and actually understand them using automatically customized Prometheus queries.
3
3
4
4
[ ![ Documentation] ( https://docs.rs/autometrics/badge.svg )] ( https://docs.rs/autometrics )
5
5
[ ![ Crates.io] ( https://img.shields.io/crates/v/autometrics.svg )] ( https://crates.io/crates/autometrics )
6
6
[ ![ Discord Shield] ( https://discordapp.com/api/guilds/950489382626951178/widget.png?style=shield )] ( https://discord.gg/kHtwcH8As9 )
7
7
8
8
Metrics are powerful and relatively inexpensive, but they are still hard to use. Developers need to:
9
- - Think about what metrics to track and which metric type to use (counter, gauge... : confused : )
10
- - Figure out how to write PromQL or another query language to get some data : confounded :
11
- - Verify that the data returned actually answers the right question : tired_face :
9
+ - Think about what metrics to track and which metric type to use (counter, gauge... 😕 )
10
+ - Figure out how to write PromQL or another query language to get some data 😖
11
+ - Verify that the data returned actually answers the right question 😫
12
12
13
13
Autometrics makes it easy to add metrics to any function in your codebase.
14
- Then, automatically generates common Prometheus for each function to help you easily understand the data.
14
+ Then, it automatically generates common Prometheus for each function to help you easily understand the data.
15
15
Explore your production metrics directly from your editor/IDE.
16
16
17
- ### : one : Add ` #[autometrics] ` to your code
17
+ ### 1️⃣ Add ` #[autometrics] ` to your code
18
18
19
19
``` rust
20
20
#[autometrics]
@@ -23,15 +23,15 @@ async fn create_user(Json(payload): Json<CreateUser>) -> Result<Json<User>, ApiE
23
23
}
24
24
```
25
25
26
- ### : two : Hover over the function name to see the generated queries
26
+ ### 2️⃣ Hover over the function name to see the generated queries
27
27
28
28
<img src =" ./assets/vs-code-example.png " alt =" VS Code Hover Example " width =" 500 " >
29
29
30
- ### : three : Click a query link to go directly to the Prometheus chart for that function
30
+ ### 3️⃣ Click a query link to go directly to the Prometheus chart for that function
31
31
32
32
<img src =" ./assets/prometheus-chart.png " alt =" Prometheus Chart " width =" 500 " >
33
33
34
- ### : four : Go back to shipping features : rocket :
34
+ ### 4️⃣ Go back to shipping features 🚀
35
35
36
36
## See it in action
37
37
@@ -95,21 +95,21 @@ Autometrics includes optional functions to help collect and prepare metrics to b
95
95
In your ` Cargo.toml ` file, enable the optional ` prometheus-exporter ` feature:
96
96
97
97
``` toml
98
- autometrics = {
git =
" ssh://[email protected] /fiberplane/autometrics-rs.git " , branch = " main " ,
features = [
" prometheus-exporter" ] }
98
+ autometrics = { version = " * " , features = [" prometheus-exporter" ] }
99
99
```
100
100
101
101
Then, call the ` global_metrics_exporter ` function in your ` main ` function:
102
102
``` rust
103
103
pub fn main () {
104
- let _exporter = global_metrics_exporter ();
104
+ let _exporter = autometrics :: global_metrics_exporter ();
105
105
// ...
106
106
}
107
107
```
108
108
109
109
And create a route on your API (probably mounted under ` /metrics ` ) that returns the following:
110
110
``` rust
111
111
pub fn get_metrics () -> (StatusCode , String ) {
112
- match encode_global_metrics () {
112
+ match autometrics :: encode_global_metrics () {
113
113
Ok (metrics ) => (StatusCode :: OK , metrics ),
114
114
Err (err ) => (StatusCode :: INTERNAL_SERVER_ERROR , format! (" {:?}" , err ))
115
115
}
0 commit comments