Skip to content

metrics/service: Add background_jobs metric #4121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2021
Merged
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
6 changes: 5 additions & 1 deletion src/metrics/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! As a rule of thumb, if the metric is not straight up fetched from the database it's probably an
//! instance-level metric, and you should add it to `src/metrics/instance.rs`.

use crate::schema::{crates, versions};
use crate::schema::{background_jobs, crates, versions};
use crate::util::errors::AppResult;
use diesel::{dsl::count_star, prelude::*, PgConnection};
use prometheus::{proto::MetricFamily, IntGauge};
Expand All @@ -21,6 +21,8 @@ metrics! {
crates_total: IntGauge,
/// Number of versions ever published
versions_total: IntGauge,
/// Number of queued up background jobs
background_jobs: IntGauge,
}

// All service metrics will be prefixed with this namespace.
Expand All @@ -33,6 +35,8 @@ impl ServiceMetrics {
.set(crates::table.select(count_star()).first(conn)?);
self.versions_total
.set(versions::table.select(count_star()).first(conn)?);
self.background_jobs
.set(background_jobs::table.select(count_star()).first(conn)?);

Ok(self.registry.gather())
}
Expand Down