aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-04-15 23:19:55 +0200
committermetamuffin <metamuffin@disroot.org>2024-04-15 23:19:55 +0200
commitf369728cc783493f8f6cab921b3c609d127bf6f2 (patch)
tree638a2a23e27a4c843237186708daa1e07b1f28ba
parent29a62d702b24d8ea30c72e17569d9a98ad2775b9 (diff)
downloadjellything-f369728cc783493f8f6cab921b3c609d127bf6f2.tar
jellything-f369728cc783493f8f6cab921b3c609d127bf6f2.tar.bz2
jellything-f369728cc783493f8f6cab921b3c609d127bf6f2.tar.zst
database statistics
-rw-r--r--Cargo.lock17
-rw-r--r--base/src/database.rs17
-rw-r--r--server/Cargo.toml2
-rw-r--r--server/src/routes/ui/admin/mod.rs61
-rw-r--r--web/style/layout.css5
5 files changed, 88 insertions, 14 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a68547d..aef72af 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -762,12 +762,6 @@ dependencies = [
]
[[package]]
-name = "edit-distance"
-version = "2.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bbbaaaf38131deb9ca518a274a45bfdb8771f139517b073b16c2d3d32ae5037b"
-
-[[package]]
name = "either"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1236,6 +1230,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
+name = "humansize"
+version = "2.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7"
+dependencies = [
+ "libm",
+]
+
+[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1591,10 +1594,10 @@ dependencies = [
"bincode",
"chashmap",
"chrono",
- "edit-distance",
"env_logger",
"futures",
"glob",
+ "humansize",
"jellybase",
"jellycommon",
"jellyimport",
diff --git a/base/src/database.rs b/base/src/database.rs
index 9d29adb..7755016 100644
--- a/base/src/database.rs
+++ b/base/src/database.rs
@@ -12,7 +12,13 @@ use jellycommon::{
use log::info;
use redb::{Database, TableDefinition};
use serde::{Deserialize, Serialize};
-use std::{borrow::Borrow, fs::create_dir_all, ops::Deref, path::Path, sync::RwLock};
+use std::{
+ borrow::Borrow,
+ fs::create_dir_all,
+ ops::Deref,
+ path::Path,
+ sync::{Arc, RwLock},
+};
use tantivy::{
directory::MmapDirectory,
schema::{Field, Schema, FAST, INDEXED, STORED, TEXT},
@@ -32,9 +38,10 @@ pub const T_NODE_EXTENDED: TableDefinition<&str, Ser<ExtendedNode>> =
pub const T_NODE_IMPORT: TableDefinition<&str, Ser<Vec<(Vec<usize>, Node)>>> =
TableDefinition::new("node-import");
+#[derive(Clone)]
pub struct DataAcid {
- pub inner: redb::Database,
- pub node_index: NodeIndex,
+ pub inner: Arc<redb::Database>,
+ pub node_index: Arc<NodeIndex>,
}
impl DataAcid {
@@ -45,8 +52,8 @@ impl DataAcid {
info!("opening node index...");
let ft_node = NodeIndex::new(path).context("in node index")?;
let r = Self {
- inner: db,
- node_index: ft_node,
+ inner: db.into(),
+ node_index: ft_node.into(),
};
{
diff --git a/server/Cargo.toml b/server/Cargo.toml
index ade4722..6d5ece3 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -22,7 +22,7 @@ base64 = "0.22.0"
chrono = { version = "0.4.38", features = ["serde"] }
vte = "0.13.0"
chashmap = "2.2.2"
-edit-distance = "2.1.0"
+humansize = "2.1.3"
argon2 = "0.5.3"
aes-gcm-siv = "0.11.1"
diff --git a/server/src/routes/ui/admin/mod.rs b/server/src/routes/ui/admin/mod.rs
index 55ac75d..00a68ac 100644
--- a/server/src/routes/ui/admin/mod.rs
+++ b/server/src/routes/ui/admin/mod.rs
@@ -20,13 +20,19 @@ use crate::{
uri,
};
use anyhow::{anyhow, Context};
+use humansize::{format_size, DECIMAL};
use jellybase::{
assetfed::AssetInner,
- database::{redb::ReadableTable, TableExt, T_INVITE, T_NODE},
+ database::{
+ redb::{ReadableTable, ReadableTableMetadata},
+ tantivy::query::Bm25StatisticsProvider,
+ TableExt, T_INVITE, T_NODE, T_NODE_EXTENDED, T_USER_NODE,
+ },
federation::Federation,
CONF,
};
use jellyimport::{import, is_importing};
+use markup::DynRender;
use rand::Rng;
use rocket::{form::Form, get, post, FromForm, State};
use std::time::Instant;
@@ -60,6 +66,7 @@ pub fn admin_dashboard<'a>(
};
let flash = flash.map(|f| f.map_err(|e| format!("{e:?}")));
+ let database = database.to_owned();
Ok(LayoutPage {
title: "Admin Dashboard".to_string(),
content: markup::new! {
@@ -100,6 +107,12 @@ pub fn admin_dashboard<'a>(
}
}
}}
+
+ h2 { "Database" }
+ @match db_stats(&database) {
+ Ok(s) => { @s }
+ Err(e) => { pre.error { @format!("{e:?}") } }
+ }
},
..Default::default()
})
@@ -215,3 +228,49 @@ pub async fn r_admin_transcode_posters(
))),
)
}
+
+fn db_stats(db: &DataAcid) -> anyhow::Result<DynRender> {
+ let txn = db.inner.begin_read()?;
+ let stats = [
+ ("node", txn.open_table(T_NODE)?.stats()?),
+ ("node-ext", txn.open_table(T_NODE_EXTENDED)?.stats()?),
+ ("user", txn.open_table(T_USER_NODE)?.stats()?),
+ ("user-node", txn.open_table(T_USER_NODE)?.stats()?),
+ ("invite", txn.open_table(T_INVITE)?.stats()?),
+ ];
+
+ let cache_stats = db.node_index.reader.searcher().doc_store_cache_stats();
+ let ft_total_docs = db.node_index.reader.searcher().total_num_docs()?;
+
+ Ok(markup::new! {
+ h3 { "Key-Value-Store Statistics" }
+ table {
+ tbody {
+ tr {
+ th { "table name" }
+ th { "tree height" }
+ th { "stored bytes" }
+ th { "metadata bytes" }
+ th { "fragmented bytes" }
+ th { "branch pages" }
+ th { "leaf pages" }
+ }
+ @for (name, stats) in &stats { tr {
+ td { @name }
+ td { @stats.tree_height() }
+ td { @format_size(stats.stored_bytes(), DECIMAL) }
+ td { @format_size(stats.metadata_bytes(), DECIMAL) }
+ td { @format_size(stats.fragmented_bytes(), DECIMAL) }
+ td { @stats.branch_pages() }
+ td { @stats.leaf_pages() }
+ }}
+ }
+ }
+ h3 { "Search Engine Statistics" }
+ ul {
+ li { "Total documents: " @ft_total_docs }
+ li { "Cache misses: " @cache_stats.cache_misses }
+ li { "Cache hits: " @cache_stats.cache_hits }
+ }
+ })
+}
diff --git a/web/style/layout.css b/web/style/layout.css
index 7cc0e6f..b18b42e 100644
--- a/web/style/layout.css
+++ b/web/style/layout.css
@@ -157,3 +157,8 @@ summary h3 {
.search form input[type="text"] {
width: max(10em, 40%);
}
+
+td,
+th {
+ border: 1px solid gray;
+}