Skip to content

Commit

Permalink
Added lustre user stats output
Browse files Browse the repository at this point in the history
  • Loading branch information
breuhan authored and jgrund committed May 8, 2024
1 parent 3757bad commit e3b0ee6
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
36 changes: 36 additions & 0 deletions fixtures/stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,42 @@
}
}
},
{
"Target": {
"Changelog": {
"kind": "Mdt",
"param": "changelog_users",
"target": "ai400x2-MDT0000",
"value": {
"users":
[
{
"user": "cl2",
"index": 8,
"idle_secs": 180
}
],
"current_index": 50
}
}
}
},
{
"Target": {
"Changelog": {
"kind": "Mdt",
"param": "changelog_users",
"target": "ai400x2-MDT0001",
"value": {
"users":
[

],
"current_index": 0
}
}
}
},
{
"Target": {
"Stats": {
Expand Down
70 changes: 69 additions & 1 deletion src/brw_stats.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{collections::BTreeMap, ops::Deref};

use lustre_collector::{BrwStats, BrwStatsBucket, OssStat, Stat, TargetStat, TargetStats};
use lustre_collector::{
BrwStats, BrwStatsBucket, ChangeLogUser, ChangelogStat, OssStat, Stat, TargetStat, TargetStats,
};
use prometheus_exporter_base::{prelude::*, Yes};

use crate::{
Expand Down Expand Up @@ -197,6 +199,24 @@ static OST_CREATE_STATS: Metric = Metric {
r#type: MetricType::Gauge,
};

static CHANGELOG_CURRENT_INDEX: Metric = Metric {
name: "lustre_changelog_current_index",
help: "current changelog index.",
r#type: MetricType::Gauge,
};

static CHANGELOG_USER_INDEX: Metric = Metric {
name: "lustre_changelog_user_index",
help: "current, maximum changelog index per registered changelog user.",
r#type: MetricType::Gauge,
};

static CHANGELOG_USER_IDLE_SEC: Metric = Metric {
name: "lustre_changelog_user_idle_sec",
help: "current changelog user idle seconds.",
r#type: MetricType::Gauge,
};

fn build_oss_stats(x: OssStat, stats_map: &mut BTreeMap<&'static str, PrometheusMetric<'static>>) {
let OssStat { param, stats } = x;

Expand Down Expand Up @@ -224,6 +244,53 @@ fn build_oss_stats(x: OssStat, stats_map: &mut BTreeMap<&'static str, Prometheus
}
}

fn build_changelog_stats(
x: TargetStat<ChangelogStat>,
stats_map: &mut BTreeMap<&'static str, PrometheusMetric<'static>>,
) {
let TargetStat {
kind: _,
target,
param: _,
value,
} = x;

let ChangelogStat {
current_index,
users,
} = value;

for user in users {
let ChangeLogUser {
user,
index,
idle_secs,
} = user;

let user_index = PrometheusInstance::new()
.with_label("user", user.as_str())
.with_label("target", target.deref())
.with_value(index);

let user_idle = PrometheusInstance::new()
.with_label("user", user.as_str())
.with_value(idle_secs);

stats_map
.get_mut_metric(CHANGELOG_USER_INDEX)
.render_and_append_instance(&user_index);
stats_map
.get_mut_metric(CHANGELOG_USER_IDLE_SEC)
.render_and_append_instance(&user_idle);
}
let current_index = PrometheusInstance::new()
.with_label("target", target.deref())
.with_value(current_index);
stats_map
.get_mut_metric(CHANGELOG_CURRENT_INDEX)
.render_and_append_instance(&current_index);
}

fn rw_inst<'a>(
x: BrwStatsBucket,
kind: &'a str,
Expand Down Expand Up @@ -359,5 +426,6 @@ pub fn build_target_stats(
TargetStats::QuotaStats(_) => {}
TargetStats::QuotaStatsOsd(_) => {}
TargetStats::Oss(x) => build_oss_stats(x, stats_map),
TargetStats::Changelog(x) => build_changelog_stats(x, stats_map),

Check warning on line 429 in src/brw_stats.rs

View workflow job for this annotation

GitHub Actions / Check

unreachable pattern

Check warning on line 429 in src/brw_stats.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unreachable pattern

Check failure on line 429 in src/brw_stats.rs

View workflow job for this annotation

GitHub Actions / clippy

unreachable pattern

error: unreachable pattern --> src/brw_stats.rs:429:9 | 429 | TargetStats::Changelog(x) => build_changelog_stats(x, stats_map), | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D unreachable-patterns` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unreachable_patterns)]`
};
}
13 changes: 13 additions & 0 deletions src/snapshots/lustrefs_exporter__tests__stats.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ lustre_capacity_kilobytes{component="mdt",target="ai400x2-MDT0000"} 427170984
lustre_capacity_kilobytes{component="ost",target="ai400x2-OST0000"} 34750424936
lustre_capacity_kilobytes{component="ost",target="ai400x2-OST0001"} 34750424936

# HELP lustre_changelog_current_index current changelog index.
# TYPE lustre_changelog_current_index gauge
lustre_changelog_current_index{target="ai400x2-MDT0000"} 50
lustre_changelog_current_index{target="ai400x2-MDT0001"} 0

# HELP lustre_changelog_user_idle_sec current changelog user idle seconds.
# TYPE lustre_changelog_user_idle_sec gauge
lustre_changelog_user_idle_sec{user="cl2"} 180

# HELP lustre_changelog_user_index current, maximum changelog index per registered changelog user.
# TYPE lustre_changelog_user_index gauge
lustre_changelog_user_index{user="cl2",target="ai400x2-MDT0000"} 8

# HELP lustre_connected_clients Number of connected clients
# TYPE lustre_connected_clients gauge
lustre_connected_clients{component="mdt",target="ai400x2-MDT0000"} 1
Expand Down

0 comments on commit e3b0ee6

Please sign in to comment.