#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate prometheus;
extern crate prometheus_static_metric;
use prometheus::IntCounterVec;
use prometheus_static_metric::make_static_metric;
make_static_metric! {
pub struct HttpRequestStatistics: IntCounter {
"method" => {
post,
get,
put,
delete,
},
"version" => {
http1: "HTTP/1",
http2: "HTTP/2",
},
"product" => {
foo,
bar,
},
}
}
lazy_static! {
pub static ref HTTP_COUNTER_VEC: IntCounterVec =
register_int_counter_vec!(
"http_requests_total",
"Number of HTTP requests.",
&["product", "method", "version"] ).unwrap();
pub static ref HTTP_COUNTER: HttpRequestStatistics = HttpRequestStatistics
::from(&HTTP_COUNTER_VEC);
}
fn main() {
HTTP_COUNTER.post.http1.foo.inc_by(4);
assert_eq!(
HTTP_COUNTER_VEC
.with_label_values(&["foo", "post", "HTTP/1"])
.get(),
4
);
HTTP_COUNTER
.try_get("delete")
.unwrap()
.try_get("HTTP/1")
.unwrap()
.foo
.inc_by(7);
assert_eq!(
HTTP_COUNTER_VEC
.with_label_values(&["foo", "delete", "HTTP/1"])
.get(),
7
);
}