summaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-25 19:59:14 +0100
committertv <tv@krebsco.de>2026-10-25 19:59:14 +0100
commit72472131a4bb3798759884da597cfb4ef7793782 (patch)
tree5f094dfda00da31e1b564cc033ef5f1d24ba89df /src/api
parent866924934d635df8a8f222a022f806c44581a5f5 (diff)
allow to persist document
Diffstat (limited to 'src/api')
-rw-r--r--src/api/stats.rs4
-rw-r--r--src/api/stats/prometheus.rs72
2 files changed, 50 insertions, 26 deletions
diff --git a/src/api/stats.rs b/src/api/stats.rs
index 8899421..fa11b45 100644
--- a/src/api/stats.rs
+++ b/src/api/stats.rs
@@ -49,6 +49,8 @@ struct DiskStats {
read_bytes: u64,
writes: u64,
written_bytes: u64,
+ appends: u64,
+ appended_bytes: u64,
errors: u64,
}
@@ -220,6 +222,8 @@ async fn collect(state: &AppState) -> StatsResponse {
read_bytes: counts.read_bytes,
writes: counts.writes,
written_bytes: counts.written_bytes,
+ appends: counts.appends,
+ appended_bytes: counts.appended_bytes,
errors: counts.errors,
};
(kind.as_str(), stats)
diff --git a/src/api/stats/prometheus.rs b/src/api/stats/prometheus.rs
index e267042..74c18e9 100644
--- a/src/api/stats/prometheus.rs
+++ b/src/api/stats/prometheus.rs
@@ -54,6 +54,45 @@ impl Out {
}
}
+const DISK_COUNTERS: usize = 7;
+
+/// Name, help and value of each counter of one kind of file.
+fn disk_counters(c: &super::DiskStats) -> [(&'static str, &'static str, u64); DISK_COUNTERS] {
+ [
+ (
+ "disk_reads_total",
+ "Reads of this node's own files.",
+ c.reads,
+ ),
+ (
+ "disk_read_bytes_total",
+ "Bytes read from them.",
+ c.read_bytes,
+ ),
+ ("disk_writes_total", "Whole files written.", c.writes),
+ (
+ "disk_written_bytes_total",
+ "Bytes of them.",
+ c.written_bytes,
+ ),
+ (
+ "disk_appends_total",
+ "Appends to this node's own files.",
+ c.appends,
+ ),
+ (
+ "disk_appended_bytes_total",
+ "Bytes appended.",
+ c.appended_bytes,
+ ),
+ (
+ "disk_errors_total",
+ "Failed reads, writes and appends.",
+ c.errors,
+ ),
+ ]
+}
+
fn escape(value: &str) -> String {
value
.replace('\\', "\\\\")
@@ -297,32 +336,13 @@ pub(super) async fn render(state: &AppState, stats: &StatsResponse) -> String {
stats.stale_hello_replies as f64,
);
- type Field = fn(&super::DiskStats) -> u64;
- let disk: [(&str, &str, Field); 5] = [
- ("disk_reads_total", "Reads of this node's own files.", |c| {
- c.reads
- }),
- ("disk_read_bytes_total", "Bytes read from them.", |c| {
- c.read_bytes
- }),
- (
- "disk_writes_total",
- "Writes of this node's own files.",
- |c| c.writes,
- ),
- ("disk_written_bytes_total", "Bytes written to them.", |c| {
- c.written_bytes
- }),
- (
- "disk_errors_total",
- "Failed reads and writes of them.",
- |c| c.errors,
- ),
- ];
- for (name, help, field) in disk {
- out.family(name, "counter", help);
- for (kind, counts) in &stats.disk {
- out.sample(name, &[("file", *kind)], field(counts) as f64);
+ for counter in 0..DISK_COUNTERS {
+ for (i, (kind, counts)) in stats.disk.iter().enumerate() {
+ let (name, help, value) = disk_counters(counts)[counter];
+ if i == 0 {
+ out.family(name, "counter", help);
+ }
+ out.sample(name, &[("file", *kind)], value as f64);
}
}