metrics: No need to set instance

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2025-02-06 22:01:54 +01:00
parent 074a033a02
commit 4cc634e07e
No known key found for this signature in database
2 changed files with 3 additions and 6 deletions

View file

@ -24,7 +24,7 @@ This will expose the following metrics on `http://127.0.0.1:42042/metrics`:
iocaine_requests_total 1 iocaine_requests_total 1
# TYPE process_start_time_seconds gauge # TYPE process_start_time_seconds gauge
process_start_time_seconds{instance="127.0.0.1:42042",service="iocaine"} 1738873005.2406795 process_start_time_seconds{service="iocaine"} 1738873005.2406795
``` ```
The `process_start_time_seconds` metric is *always* present, and its value only changes when `iocaine` is restarted. For the sake of brevity, it is excluded from all other examples. The `process_start_time_seconds` metric is *always* present, and its value only changes when `iocaine` is restarted. For the sake of brevity, it is excluded from all other examples.

View file

@ -162,16 +162,13 @@ impl Iocaine {
#[cfg(feature = "prometheus")] #[cfg(feature = "prometheus")]
async fn start_metrics_server(metrics_bind: String) -> std::result::Result<(), std::io::Error> { async fn start_metrics_server(metrics_bind: String) -> std::result::Result<(), std::io::Error> {
let metrics_listener = tokio::net::TcpListener::bind(metrics_bind.clone()).await?; let metrics_listener = tokio::net::TcpListener::bind(metrics_bind).await?;
let app = Self::metrics_app().await; let app = Self::metrics_app().await;
let ts = SystemTime::now() let ts = SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.expect("Time went backwards"); .expect("Time went backwards");
let labels = [ let labels = [("service", "iocaine".to_string())];
("instance", metrics_bind),
("service", "iocaine".to_string()),
];
metrics::gauge!("process_start_time_seconds", &labels).set(ts); metrics::gauge!("process_start_time_seconds", &labels).set(ts);
axum::serve(metrics_listener, app) axum::serve(metrics_listener, app)