summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-03-10 10:31:46 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-03-10 10:31:46 +0100
commita554772d25026a9cf223514d9422c70fc9b15f69 (patch)
tree0730772dd4e0062a5c4847d9c858074d9dfd2245
parent60a3fa633a33e315c1439a9f2436fcdb48da62ae (diff)
parent120a5fa17b4736c953c64bc2ffc6858679608f6b (diff)
Merge branch 'metrics'
-rw-r--r--src/cli.rs5
-rw-r--r--src/commands/metrics.rs110
-rw-r--r--src/commands/mod.rs3
-rw-r--r--src/main.rs6
4 files changed, 124 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 8547502..bc59171 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -832,6 +832,11 @@ pub fn cli<'a>() -> App<'a> {
.about("A version constraint to search for (optional), E.G. '=1.0.0'")
)
)
+
+ .subcommand(App::new("metrics")
+ .version(crate_version!())
+ .about("Print metrics about butido")
+ )
}
fn script_arg_line_numbers<'a>() -> clap::Arg<'a> {
diff --git a/src/commands/metrics.rs b/src/commands/metrics.rs
new file mode 100644
index 0000000..d7f68fb
--- /dev/null
+++ b/src/commands/metrics.rs
@@ -0,0 +1,110 @@
+//
+// Copyright (c) 2020-2021 science+computing ag and other contributors
+//
+// This program and the accompanying materials are made
+// available under the terms of the Eclipse Public License 2.0
+// which is available at https://www.eclipse.org/legal/epl-2.0/
+//
+// SPDX-License-Identifier: EPL-2.0
+//
+
+use std::path::Path;
+use std::io::Write;
+
+use anyhow::Error;
+use anyhow::Result;
+use diesel::PgConnection;
+use diesel::QueryDsl;
+use diesel::RunQueryDsl;
+use walkdir::WalkDir;
+
+use crate::config::Configuration;
+use crate::repository::Repository;
+
+pub async fn metrics(
+ repo_path: &Path,
+ config: &Configuration,
+ repo: Repository,
+ conn: PgConnection,
+) -> Result<()> {
+ let mut out = std::io::stdout();
+
+ let nfiles = WalkDir::new(repo_path)
+ .follow_links(true)
+ .into_iter()
+ .filter_map(Result::ok)
+ .filter(|d| d.file_type().is_file())
+ .filter(|f| {
+ f.path()
+ .file_name()
+ .map(|name| name == "pkg.toml")
+ .unwrap_or(false)
+ })
+ .count();
+
+ let n_artifacts = async { crate::schema::artifacts::table.count().get_result::<i64>(&conn) };
+ let n_endpoints = async { crate::schema::endpoints::table.count().get_result::<i64>(&conn) };
+ let n_envvars = async { crate::schema::envvars::table.count().get_result::<i64>(&conn) };
+ let n_githashes = async { crate::schema::githashes::table.count().get_result::<i64>(&conn) };
+ let n_images = async { crate::schema::images::table.count().get_result::<i64>(&conn) };
+ let n_jobs = async { crate::schema::jobs::table.count().get_result::<i64>(&conn) };
+ let n_packages = async { crate::schema::packages::table.count().get_result::<i64>(&conn) };
+ let n_releasestores = async { crate::schema::release_stores::table.count().get_result::<i64>(&conn) };
+ let n_releases = async { crate::schema::releases::table.count().get_result::<i64>(&conn) };
+ let n_submits = async { crate::schema::submits::table.count().get_result::<i64>(&conn) };
+
+ let (
+ n_artifacts,
+ n_endpoints,
+ n_envvars,
+ n_githashes,
+ n_images,
+ n_jobs,
+ n_packages,
+ n_releasestores,
+ n_releases,
+ n_submits,
+ ) = tokio::try_join!(n_artifacts, n_endpoints, n_envvars, n_githashes, n_images, n_jobs, n_packages, n_releasestores, n_releases, n_submits)?;
+
+ write!(out, "{}", indoc::formatdoc!(r#"
+ Butido release {release}
+
+ {configured_endpoints} Configured endpoints
+ {configured_images} Configured images
+ {configured_release_stores} Configured release stores
+ {configured_phases} Configures phases
+
+ {nfiles} packages in repository
+ {repo_packages} packages in repository
+
+ {n_artifacts} artifacts in database
+ {n_endpoints} endpoints in database
+ {n_envvars} envvars in database
+ {n_githashes} githashes in database
+ {n_images} images in database
+ {n_jobs} jobs in database
+ {n_packages} packages in database
+ {n_releasestores} releasestores in database
+ {n_releases} releases in database
+ {n_submits} submits in database
+ "#,
+ release = clap::crate_version!(),
+ configured_endpoints = config.docker().endpoints().len(),
+ configured_images = config.docker().images().len(),
+ configured_release_stores = config.release_stores().len(),
+ configured_phases = config.available_phases().len(),
+ nfiles = nfiles,
+ repo_packages = repo.packages().count(),
+ n_artifacts = n_artifacts,
+ n_endpoints = n_endpoints,
+ n_envvars = n_envvars,
+ n_githashes = n_githashes,
+ n_images = n_images,
+ n_jobs = n_jobs,
+ n_packages = n_packages,
+ n_releasestores = n_releasestores,
+ n_releases = n_releases,
+ n_submits = n_submits,
+ )).map_err(Error::from)
+}
+
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 473596a..3f35c63 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -44,4 +44,7 @@ pub use versions_of::versions_of;
mod tree_of;
pub use tree_of::tree_of;
+mod metrics;
+pub use metrics::metrics;
+
mod util;
diff --git a/src/main.rs b/src/main.rs
index b43a401..35c0ffb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -184,6 +184,12 @@ async fn main() -> Result<()> {
crate::commands::tree_of(matches, repo, progressbars).await?
}
+ Some(("metrics", _)) => {
+ let repo = load_repo()?;
+ let conn = crate::db::establish_connection(db_connection_config)?;
+ crate::commands::metrics(&repo_path, &config, repo, conn).await?
+ }
+
Some((other, _)) => return Err(anyhow!("Unknown subcommand: {}", other)),
None => return Err(anyhow!("No subcommand")),
}