Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autometrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ uuid = { version = "1", features = ["v4"] }
vergen = { version = "8.1", features = ["git", "gitcl"] }

[build-dependencies]
cfg_aliases = "0.1"
cfg_aliases = "0.2.1"

[package.metadata.docs.rs]
all-features = true
Expand Down
13 changes: 6 additions & 7 deletions autometrics/src/tracker/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::constants::*;
use crate::labels::{BuildInfoLabels, CounterLabels, GaugeLabels, HistogramLabels};
use crate::tracker::TrackMetrics;
use metrics::{
describe_counter, describe_gauge, describe_histogram, register_counter, register_gauge,
register_histogram, Gauge, Unit,
counter, describe_counter, describe_gauge, describe_histogram, gauge, histogram, Gauge, Unit,
};
use std::{sync::Once, time::Instant};

Expand Down Expand Up @@ -35,7 +34,7 @@ impl TrackMetrics for MetricsTracker {
describe_metrics();

let gauge = if let Some(gauge_labels) = gauge_labels {
let gauge = register_gauge!(GAUGE_NAME, &gauge_labels.to_array());
let gauge = gauge!(GAUGE_NAME, &gauge_labels.to_array());
gauge.increment(1.0);
Some(gauge)
} else {
Expand All @@ -50,24 +49,24 @@ impl TrackMetrics for MetricsTracker {

fn finish(self, counter_labels: &CounterLabels, histogram_labels: &HistogramLabels) {
let duration = self.start.elapsed().as_secs_f64();
register_counter!(COUNTER_NAME_PROMETHEUS, &counter_labels.to_vec()).increment(1);
register_histogram!(HISTOGRAM_NAME_PROMETHEUS, &histogram_labels.to_vec()).record(duration);
counter!(COUNTER_NAME_PROMETHEUS, &counter_labels.to_vec()).increment(1);
histogram!(HISTOGRAM_NAME_PROMETHEUS, &histogram_labels.to_vec()).record(duration);
if let Some(gauge) = self.gauge {
gauge.decrement(1.0);
}
}

fn set_build_info(build_info_labels: &BuildInfoLabels) {
SET_BUILD_INFO.call_once(|| {
register_gauge!(BUILD_INFO_NAME, &build_info_labels.to_vec()).set(1.0);
gauge!(BUILD_INFO_NAME, &build_info_labels.to_vec()).set(1.0);
});
}

#[cfg(debug_assertions)]
fn intitialize_metrics(function_descriptions: &[FunctionDescription]) {
for function in function_descriptions {
let labels = &CounterLabels::from(function).to_vec();
register_counter!(COUNTER_NAME, labels).increment(0);
counter!(COUNTER_NAME, labels).increment(0);
}
}
}
8 changes: 4 additions & 4 deletions examples/grpc-http/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::net::SocketAddr;
use tonic::transport::Server as TonicServer;
use warp::Filter;
use warp::http::StatusCode;
use warp::Filter;

use autometrics::prometheus_exporter;
use server::MyJobRunner;
Expand Down Expand Up @@ -51,9 +51,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.serve_with_shutdown(grpc_addr, signal);

// Build http /metrics endpoint
let routes = warp::get()
.and(warp::path("metrics"))
.map(|| prometheus_exporter::encode_to_string().map_err(|_| StatusCode::INTERNAL_SERVER_ERROR));
let routes = warp::get().and(warp::path("metrics")).map(|| {
prometheus_exporter::encode_to_string().map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
});

// Build http web server
let (_, web_server) =
Expand Down
Loading