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
You can also generate a static `LazyLock` instance by using the `static` attribute. When enabled, the builder methods and `Default` implementation are made private, ensuring the only way to access the metrics is through the static instance:
104
85
105
-
```rust
106
-
useprometric_derive::metrics;
107
-
useprometric::{Counter, Gauge};
108
-
109
-
#[metrics(scope ="app", static)]
110
-
structAppMetrics {
111
-
/// The total number of requests.
112
-
#[metric(labels = ["method"])]
113
-
requests:Counter,
114
-
115
-
/// The current number of active connections.
116
-
#[metric]
117
-
active_connections:Gauge,
118
-
}
119
-
120
-
// Use the static directly (the name is APP_METRICS in SCREAMING_SNAKE_CASE)
121
-
APP_METRICS.requests("GET").inc();
122
-
APP_METRICS.active_connections().set(10);
123
-
124
-
// The following would not compile:
125
-
// let metrics = AppMetrics::builder(); // Error: builder() is private
126
-
// let metrics = AppMetrics::default(); // Error: Default is not implemented
127
-
```
86
+
See [`static_metrics`](./prometric-derive/examples/static_metrics.rs) example for usage.
128
87
129
88
### Exporting Metrics
130
89
131
-
An HTTP exporter is provided by [`prometric::exporter::ExporterBuilder`]. Usage:
90
+
An HTTP exporter is provided by [`prometric::exporter::ExporterBuilder`].
132
91
133
-
```rust
134
-
useprometric::exporter::ExporterBuilder;
135
-
136
-
ExporterBuilder::new()
137
-
// Specify the address to listen on
138
-
.with_address("127.0.0.1:9090")
139
-
// Set the global namespace for the metrics (usually the name of the application)
140
-
.with_namespace("exporter")
141
-
// Install the exporter. This will start an HTTP server and serve metrics on the specified
142
-
// address.
143
-
.install()
144
-
.expect("Failed to install exporter");
145
-
```
92
+
See [`exporter`](./prometric-derive/examples/exporter.rs) example for usage.
0 commit comments