Skip to content

Commit 2231812

Browse files
committed
refactoring
1 parent f10552f commit 2231812

File tree

3 files changed

+118
-263
lines changed

3 files changed

+118
-263
lines changed

backend/src/models/api.rs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,37 @@ pub struct Disk {
3131
pub iops: u64,
3232
}
3333

34+
impl Disk {
35+
#[must_use]
36+
pub fn from_metrics(
37+
disk_name: String,
38+
disk_path: String,
39+
raw_metrics: &dto::MetricsSnapshotModel,
40+
raw_space: &dto::SpaceInfo,
41+
) -> Self {
42+
let status = DiskStatus::from_space_info(raw_space, &disk_name);
43+
let used_space = raw_space
44+
.occupied_disk_space_by_disk
45+
.get(&disk_name)
46+
.copied()
47+
.unwrap_or_default();
48+
let iops = raw_metrics
49+
.metrics
50+
.get(&format!("hardware.disks.{:?}_iops", disk_name))
51+
.cloned()
52+
.unwrap_or_default()
53+
.value;
54+
Self {
55+
name: disk_name,
56+
path: disk_path,
57+
status,
58+
total_space: raw_space.total_disk_space_bytes,
59+
used_space,
60+
iops,
61+
}
62+
}
63+
}
64+
3465
/// Defines kind of problem on disk
3566
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Serialize, Hash)]
3667
#[cfg_attr(all(feature = "swagger", debug_assertions), derive(ToSchema))]
@@ -189,6 +220,12 @@ pub enum NodeStatus {
189220
Offline,
190221
}
191222

223+
impl Default for NodeStatus {
224+
fn default() -> Self {
225+
Self::Offline
226+
}
227+
}
228+
192229
impl NodeStatus {
193230
#[must_use]
194231
pub fn from_problems(problems: Vec<NodeProblem>) -> Self {
@@ -343,7 +380,7 @@ pub enum VDiskStatus {
343380
Offline,
344381
}
345382

346-
#[derive(Debug, Clone, Serialize)]
383+
#[derive(Default, Debug, Clone, Serialize)]
347384
#[cfg_attr(all(feature = "swagger", debug_assertions), derive(ToSchema))]
348385
pub struct DetailedNode {
349386
pub name: String,
@@ -360,7 +397,7 @@ pub struct DetailedNode {
360397
pub disks: Vec<Disk>,
361398
}
362399

363-
#[derive(Debug, Clone, Serialize)]
400+
#[derive(Default, Debug, Clone, Serialize)]
364401
#[cfg_attr(all(feature = "swagger", debug_assertions), derive(ToSchema))]
365402
#[serde(rename_all = "camelCase")]
366403
pub struct DetailedNodeMetrics {
@@ -381,6 +418,22 @@ pub struct DetailedNodeMetrics {
381418
pub descr_amount: u64,
382419
}
383420

421+
impl DetailedNodeMetrics {
422+
#[must_use]
423+
pub fn from_metrics(metrics: &TypedMetrics, space: SpaceInfo) -> Self {
424+
Self {
425+
rps: RPS::from_metrics(metrics),
426+
alien_count: metrics[RawMetricEntry::BackendAlienCount].value,
427+
corrupted_count: metrics[RawMetricEntry::BackendCorruptedBlobCount].value,
428+
space,
429+
cpu_load: metrics[RawMetricEntry::HardwareBobCpuLoad].value,
430+
total_ram: metrics[RawMetricEntry::HardwareTotalRam].value,
431+
used_ram: metrics[RawMetricEntry::HardwareUsedRam].value,
432+
descr_amount: metrics[RawMetricEntry::HardwareDescrAmount].value,
433+
}
434+
}
435+
}
436+
384437
/// Types of operations on BOB cluster
385438
#[derive(Debug, Clone, Serialize, Hash, Eq, PartialEq, PartialOrd, Ord, EnumIter)]
386439
#[cfg_attr(all(feature = "swagger", debug_assertions), derive(ToSchema))]

0 commit comments

Comments
 (0)