mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-20 03:22:18 +00:00
support some peer rest api
Signed-off-by: mujunxiang <1948535941@qq.com>
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use ecstore::{
|
||||
config::storageclass::{RRS, STANDARD},
|
||||
global::GLOBAL_BackgroundHealState,
|
||||
heal::{background_heal_ops::get_local_disks_to_heal, heal_ops::BG_HEALING_UUID},
|
||||
new_object_layer_fn,
|
||||
store_api::{StorageAPI, StorageDisk},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct MRFStatus {
|
||||
bytes_healed: u64,
|
||||
items_healed: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct SetStatus {
|
||||
pub id: String,
|
||||
pub pool_index: i32,
|
||||
pub set_index: i32,
|
||||
pub heal_status: String,
|
||||
pub heal_priority: String,
|
||||
pub total_objects: usize,
|
||||
pub disks: Vec<StorageDisk>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct BgHealState {
|
||||
offline_endpoints: Vec<String>,
|
||||
scanned_items_count: u64,
|
||||
heal_disks: Vec<String>,
|
||||
sets: Vec<SetStatus>,
|
||||
mrf: HashMap<String, MRFStatus>,
|
||||
scparity: HashMap<String, usize>,
|
||||
}
|
||||
|
||||
pub async fn get_local_background_heal_status() -> (BgHealState, bool) {
|
||||
let (bg_seq, ok) = GLOBAL_BackgroundHealState
|
||||
.read()
|
||||
.await
|
||||
.get_heal_sequence_by_token(BG_HEALING_UUID)
|
||||
.await;
|
||||
if !ok {
|
||||
return (BgHealState::default(), false);
|
||||
}
|
||||
let bg_seq = bg_seq.unwrap();
|
||||
let mut status = BgHealState {
|
||||
scanned_items_count: bg_seq.read().await.get_scanned_items_count() as u64,
|
||||
..Default::default()
|
||||
};
|
||||
let mut heal_disks_map = HashSet::new();
|
||||
for ep in get_local_disks_to_heal().await.iter() {
|
||||
heal_disks_map.insert(ep.to_string());
|
||||
}
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
let healing = GLOBAL_BackgroundHealState.read().await.get_local_healing_disks().await;
|
||||
for disk in healing.values() {
|
||||
status.heal_disks.push(disk.endpoint.clone());
|
||||
}
|
||||
return (status, true);
|
||||
}
|
||||
};
|
||||
|
||||
let si = store.local_storage_info().await;
|
||||
let mut indexed = HashMap::new();
|
||||
for disk in si.disks.iter() {
|
||||
let set_idx = format!("{}-{}", disk.pool_index, disk.set_index);
|
||||
// indexed.insert(set_idx, disk);
|
||||
indexed.entry(set_idx).or_insert(Vec::new()).push(disk);
|
||||
}
|
||||
|
||||
for (id, disks) in indexed {
|
||||
let mut ss = SetStatus {
|
||||
id,
|
||||
set_index: disks[0].set_index,
|
||||
pool_index: disks[0].pool_index,
|
||||
..Default::default()
|
||||
};
|
||||
for disk in disks {
|
||||
ss.disks.push(disk.clone());
|
||||
if disk.healing {
|
||||
ss.heal_status = "healing".to_string();
|
||||
ss.heal_priority = "high".to_string();
|
||||
status.heal_disks.push(disk.endpoint.clone());
|
||||
}
|
||||
}
|
||||
ss.disks.sort_by(|a, b| {
|
||||
if a.pool_index != b.pool_index {
|
||||
return a.pool_index.cmp(&b.pool_index);
|
||||
}
|
||||
if a.set_index != b.set_index {
|
||||
return a.set_index.cmp(&b.set_index);
|
||||
}
|
||||
a.disk_index.cmp(&b.disk_index)
|
||||
});
|
||||
status.sets.push(ss);
|
||||
}
|
||||
status.sets.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
let backend_info = store.backend_info().await;
|
||||
status
|
||||
.scparity
|
||||
.insert(STANDARD.to_string(), backend_info.standard_sc_parity.unwrap_or_default());
|
||||
status
|
||||
.scparity
|
||||
.insert(RRS.to_string(), backend_info.rr_sc_parity.unwrap_or_default());
|
||||
|
||||
(status, true)
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
@@ -49,3 +51,127 @@ pub fn get_cpus() -> Cpus {
|
||||
// todo
|
||||
Cpus::default()
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct Partition {
|
||||
pub error: String,
|
||||
device: String,
|
||||
model: String,
|
||||
revision: String,
|
||||
mountpoint: String,
|
||||
fs_type: String,
|
||||
mount_options: String,
|
||||
space_total: u64,
|
||||
space_free: u64,
|
||||
inode_total: u64,
|
||||
inode_free: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct Partitions {
|
||||
node_common: NodeCommon,
|
||||
partitions: Vec<Partition>,
|
||||
}
|
||||
|
||||
pub fn get_partitions() -> Partitions {
|
||||
Partitions::default()
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct OsInfo {
|
||||
node_common: NodeCommon,
|
||||
}
|
||||
|
||||
pub fn get_os_info() -> OsInfo {
|
||||
OsInfo::default()
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct ProcInfo {
|
||||
node_common: NodeCommon,
|
||||
pid: i32,
|
||||
is_background: bool,
|
||||
cpu_percent: f64,
|
||||
children_pids: Vec<i32>,
|
||||
cmd_line: String,
|
||||
num_connections: usize,
|
||||
create_time: u64,
|
||||
cwd: String,
|
||||
exec_path: String,
|
||||
gids: Vec<i32>,
|
||||
// io_counters:
|
||||
is_running: bool,
|
||||
// mem_info:
|
||||
// mem_maps:
|
||||
mem_percent: f32,
|
||||
name: String,
|
||||
nice: i32,
|
||||
//num_ctx_switches:
|
||||
num_fds: i32,
|
||||
num_threads: i32,
|
||||
// page_faults:
|
||||
ppid: i32,
|
||||
status: String,
|
||||
tgid: i32,
|
||||
uids: Vec<i32>,
|
||||
username: String,
|
||||
}
|
||||
|
||||
pub fn get_proc_info(addr: &str) -> ProcInfo {
|
||||
ProcInfo::default()
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct SysService {
|
||||
name: String,
|
||||
status: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct SysServices {
|
||||
node_common: NodeCommon,
|
||||
services: Vec<SysService>,
|
||||
}
|
||||
|
||||
pub fn get_sys_services(_add: &str) -> SysServices {
|
||||
SysServices::default()
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct SysConfig {
|
||||
node_common: NodeCommon,
|
||||
config: HashMap<String, String>,
|
||||
}
|
||||
|
||||
pub fn get_sys_config(_addr: &str) -> SysConfig {
|
||||
SysConfig::default()
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct SysErrors {
|
||||
node_common: NodeCommon,
|
||||
errors: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn get_sys_errors(_add: &str) -> SysErrors {
|
||||
SysErrors::default()
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct MemInfo {
|
||||
node_common: NodeCommon,
|
||||
total: u64,
|
||||
used: u64,
|
||||
free: u64,
|
||||
available: u64,
|
||||
shared: u64,
|
||||
cache: u64,
|
||||
buffers: u64,
|
||||
swap_space_total: u64,
|
||||
swap_space_free: u64,
|
||||
limit: u64,
|
||||
}
|
||||
|
||||
pub fn get_mem_info(_addr: &str) -> MemInfo {
|
||||
MemInfo::default()
|
||||
}
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
pub mod heal_command;
|
||||
pub mod health;
|
||||
pub mod metrics;
|
||||
pub mod net;
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct TimedAction {
|
||||
count: u64,
|
||||
acc_time: u64,
|
||||
bytes: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct DiskIOStats {
|
||||
read_ios: u64,
|
||||
read_merges: u64,
|
||||
read_sectors: u64,
|
||||
read_ticks: u64,
|
||||
write_ios: u64,
|
||||
write_merges: u64,
|
||||
write_sectors: u64,
|
||||
write_ticks: u64,
|
||||
current_ios: u64,
|
||||
total_ticks: u64,
|
||||
req_ticks: u64,
|
||||
discard_ios: u64,
|
||||
discard_merges: u64,
|
||||
discard_sectors: u64,
|
||||
discard_ticks: u64,
|
||||
flush_ios: u64,
|
||||
flush_ticks: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct DiskMetric {
|
||||
collected_at: u64,
|
||||
n_disks: usize,
|
||||
offline: usize,
|
||||
healing: usize,
|
||||
life_time_ops: HashMap<String, u64>,
|
||||
last_minute: HashMap<String, TimedAction>,
|
||||
io_stats: DiskIOStats,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct Metrics {}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct RealtimeMetrics {
|
||||
errors: Vec<String>,
|
||||
hosts: Vec<String>,
|
||||
aggregated: Metrics,
|
||||
by_host: HashMap<String, Metrics>,
|
||||
by_disk: HashMap<String, DiskMetric>,
|
||||
finally: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct CollectMetricsOpts {
|
||||
hosts: HashSet<String>,
|
||||
disks: HashSet<String>,
|
||||
job_id: String,
|
||||
dep_id: String,
|
||||
}
|
||||
|
||||
pub type MetricType = u64;
|
||||
|
||||
pub fn collect_local_metrics(_types: MetricType, _opts: &CollectMetricsOpts) -> RealtimeMetrics {
|
||||
RealtimeMetrics::default()
|
||||
}
|
||||
@@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::health::NodeCommon;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod net_linux;
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user