Skip to content

Commit

Permalink
feat(sns): Add indication of whether a canister is frozen in `sns hea…
Browse files Browse the repository at this point in the history
…lth` (#2804)

Example output:

| Name | Memory | Cycles | Upgrades Remaining |

|-------------------------|---------------------|--------------------------------------------------------------------------------------------------------------------------------|--------------------|
| BOOM DAO | 👍 | ❌ governance: (6.96 TC), index: (0.00 TC 🥶) | 24 |
| CYCLES-TRANSFER-STATION | 👍 | 👍 | 8 |
| Catalyze | 👍 | ❌ governance: (9.76 TC), swap: (8.83 TC), archive:
(9.30 TC) | 1 |

(This is using test data, BOOM DAO's index canister is fine)

The benefit of this is that it draws attention to the canisters that are
really in trouble - the frozen ones.

The definition of frozen used by the tool is: the number of cycles is
below the freezing threshold (as reported by the canister summary)
  • Loading branch information
anchpop authored Nov 25, 2024
1 parent a73289e commit d11cedb
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions rs/sns/cli/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ pub struct HealthArgs {
include_dapps: bool,
}

#[derive(Debug, Serialize, Deserialize)]
struct Cycles {
cycles: u128,
freezing_threshold: u64,
}

#[derive(Debug, Serialize, Deserialize)]
struct SnsHealthInfo {
name: String,
memory_consumption: Vec<(u64, SnsCanisterType)>,
cycles: Vec<(u64, SnsCanisterType)>,
cycles: Vec<(Cycles, SnsCanisterType)>,
num_remaining_upgrade_steps: usize,
}

Expand All @@ -34,16 +40,21 @@ impl TableRow for SnsHealthInfo {
}

fn column_values(&self) -> Vec<String> {
const MEMORY_THRESHOLD_GIB: f64 = 2.5;
const CYCLES_THRESHOLD_TC: f64 = 10.0;
const GIB: f64 = 1024.0 * 1024.0 * 1024.0;
const TC: f64 = 1000.0 * 1000.0 * 1000.0 * 1000.0;

let high_memory_consumption = self
.memory_consumption
.iter()
.filter(|(memory_consumption, _)| {
(*memory_consumption as f64) > 2.5 * 1024.0 * 1024.0 * 1024.0
(*memory_consumption as f64) > MEMORY_THRESHOLD_GIB * GIB
})
.map(|(memory_consumption, canister_type)| {
format!(
"{canister_type}: ({:.2} GiB)",
*memory_consumption as f64 / 1024.0 / 1024.0 / 1024.0
*memory_consumption as f64 / GIB
)
})
.join(", ");
Expand All @@ -57,11 +68,16 @@ impl TableRow for SnsHealthInfo {
let low_cycles = self
.cycles
.iter()
.filter(|(cycles, _)| (*cycles as f64) < 10.0 * 1000.0 * 1000.0 * 1000.0 * 1000.0)
.filter(|(cycles, _)| (cycles.cycles as f64) < CYCLES_THRESHOLD_TC * TC)
.map(|(cycles, canister_type)| {
format!(
"{canister_type}: ({:.2} TC)",
*cycles as f64 / 1000.0 / 1000.0 / 1000.0 / 1000.0
"{canister_type}: ({:.2} TC{frozen})",
cycles.cycles as f64 / TC,
frozen = if cycles.cycles < cycles.freezing_threshold as u128 {
" 🥶".to_string()
} else {
"".to_string()
}
)
})
.join(", ");
Expand Down Expand Up @@ -128,7 +144,16 @@ pub async fn exec(args: HealthArgs, agent: &Agent) -> Result<()> {
.map(|(canister_status, ctype)| {
(
(u64::try_from(canister_status.memory_size.0).unwrap(), ctype),
(u64::try_from(canister_status.cycles.0).unwrap(), ctype),
(
Cycles {
freezing_threshold: u64::try_from(
canister_status.settings.freezing_threshold.0,
)
.unwrap(),
cycles: u128::try_from(canister_status.cycles.0).unwrap(),
},
ctype,
),
)
})
.unzip();
Expand Down

0 comments on commit d11cedb

Please sign in to comment.