-
Notifications
You must be signed in to change notification settings - Fork 10
/
with_endpoint.rs
42 lines (33 loc) · 1.25 KB
/
with_endpoint.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Will create an exporter with a single metric that does not change
use env_logger::{
Builder,
Env,
};
use log::info;
use prometheus_exporter::prometheus::register_gauge;
use std::net::SocketAddr;
fn main() {
// Setup logger with default level info so we can see the messages from
// prometheus_exporter.
Builder::from_env(Env::default().default_filter_or("info")).init();
// Parse address used to bind exporter to.
let addr_raw = "0.0.0.0:9184";
let addr: SocketAddr = addr_raw.parse().expect("can not parse listen addr");
// Create metric
let metric = register_gauge!("simple_the_answer", "to everything")
.expect("can not create gauge simple_the_answer");
metric.set(42.0);
let endpoint = "some/long/path";
// Start exporter
let mut builder = prometheus_exporter::Builder::new(addr);
builder
.with_endpoint(endpoint)
.expect("failed to set endpoint");
builder.start().expect("can not start exporter");
// Get metrics from exporter
let body = reqwest::blocking::get(format!("http://{addr_raw}/{endpoint}"))
.expect("can not get metrics from exporter")
.text()
.expect("can not body text from request");
info!("Exporter metrics:\n{}", body);
}