rrd: pack multiple rrd values into th estat list
This commit is contained in:
parent
ba1c249eec
commit
a4a3f7ca5e
@ -20,15 +20,20 @@ use crate::api2::types::*;
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Read CPU stats
|
/// Read node stats
|
||||||
fn get_cpu_stats(
|
fn get_node_stats(
|
||||||
timeframe: RRDTimeFrameResolution,
|
timeframe: RRDTimeFrameResolution,
|
||||||
cf: RRDMode,
|
cf: RRDMode,
|
||||||
_param: Value,
|
_param: Value,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
|
||||||
crate::rrd::extract_data("host/cpu", timeframe, cf)
|
crate::rrd::extract_data_list(
|
||||||
|
"host",
|
||||||
|
&["cpu", "iowait", "memtotal", "memused"],
|
||||||
|
timeframe,
|
||||||
|
cf,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ROUTER: Router = Router::new()
|
pub const ROUTER: Router = Router::new()
|
||||||
.get(&API_METHOD_GET_CPU_STATS);
|
.get(&API_METHOD_GET_NODE_STATS);
|
||||||
|
@ -601,7 +601,7 @@ async fn run_stat_generator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_host_stats() {
|
async fn generate_host_stats() {
|
||||||
use proxmox::sys::linux::procfs::read_proc_stat;
|
use proxmox::sys::linux::procfs::{read_meminfo, read_proc_stat};
|
||||||
use proxmox_backup::rrd;
|
use proxmox_backup::rrd;
|
||||||
|
|
||||||
match read_proc_stat() {
|
match read_proc_stat() {
|
||||||
@ -614,4 +614,17 @@ async fn generate_host_stats() {
|
|||||||
eprintln!("read_proc_stat failed - {}", err);
|
eprintln!("read_proc_stat failed - {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
match read_meminfo() {
|
||||||
|
Ok(meminfo) => {
|
||||||
|
if let Err(err) = rrd::update_value("host/memtotal", meminfo.memtotal as f64) {
|
||||||
|
eprintln!("rrd::update_value 'host/memtotal' failed - {}", err);
|
||||||
|
}
|
||||||
|
if let Err(err) = rrd::update_value("host/memused", meminfo.memused as f64) {
|
||||||
|
eprintln!("rrd::update_value 'host/memused' failed - {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("read_meminfo failed - {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,3 +82,30 @@ pub fn extract_data(
|
|||||||
Ok(RRD::new().extract_data(now, timeframe, mode))
|
Ok(RRD::new().extract_data(now, timeframe, mode))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn extract_data_list(
|
||||||
|
base: &str,
|
||||||
|
items: &[&str],
|
||||||
|
timeframe: RRDTimeFrameResolution,
|
||||||
|
mode: RRDMode,
|
||||||
|
) -> Result<Value, Error> {
|
||||||
|
|
||||||
|
let now = now()?;
|
||||||
|
|
||||||
|
let map = RRD_CACHE.read().unwrap();
|
||||||
|
|
||||||
|
let mut list: Vec<(&str, &RRD)> = Vec::new();
|
||||||
|
|
||||||
|
let empty_rrd = RRD::new();
|
||||||
|
|
||||||
|
for name in items.iter() {
|
||||||
|
if let Some(rrd) = map.get(&format!("{}/{}", base, name)) {
|
||||||
|
list.push((name, rrd));
|
||||||
|
} else {
|
||||||
|
list.push((name, &empty_rrd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(extract_rrd_data(&list, now, timeframe, mode))
|
||||||
|
}
|
||||||
|
@ -6,8 +6,7 @@ use serde_json::{json, Value};
|
|||||||
|
|
||||||
use crate::api2::types::{RRDMode, RRDTimeFrameResolution};
|
use crate::api2::types::{RRDMode, RRDTimeFrameResolution};
|
||||||
|
|
||||||
const RRD_DATA_ENTRIES: usize = 70;
|
pub const RRD_DATA_ENTRIES: usize = 70;
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Default, Copy, Clone)]
|
#[derive(Default, Copy, Clone)]
|
||||||
@ -209,3 +208,54 @@ impl RRD {
|
|||||||
self.last_update = epoch;
|
self.last_update = epoch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn extract_rrd_data(
|
||||||
|
rrd_list: &[(&str, &RRD)],
|
||||||
|
epoch: u64,
|
||||||
|
timeframe: RRDTimeFrameResolution,
|
||||||
|
mode: RRDMode,
|
||||||
|
) -> Value {
|
||||||
|
|
||||||
|
let reso = timeframe as u64;
|
||||||
|
|
||||||
|
let end = reso*(epoch/reso);
|
||||||
|
let start = end - reso*(RRD_DATA_ENTRIES as u64);
|
||||||
|
|
||||||
|
let mut list = Vec::new();
|
||||||
|
|
||||||
|
let mut t = start;
|
||||||
|
let mut index = ((t/reso) % (RRD_DATA_ENTRIES as u64)) as usize;
|
||||||
|
for _ in 0..RRD_DATA_ENTRIES {
|
||||||
|
let mut item = json!({ "time": t });
|
||||||
|
for (name, rrd) in rrd_list.iter() {
|
||||||
|
let rrd_end = reso*(rrd.last_update/reso);
|
||||||
|
let rrd_start = rrd_end - reso*(RRD_DATA_ENTRIES as u64);
|
||||||
|
|
||||||
|
if t < rrd_start || t > rrd_end {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
let data = match timeframe {
|
||||||
|
RRDTimeFrameResolution::Hour => &rrd.hour,
|
||||||
|
RRDTimeFrameResolution::Day => &rrd.day,
|
||||||
|
RRDTimeFrameResolution::Week => &rrd.week,
|
||||||
|
RRDTimeFrameResolution::Month => &rrd.month,
|
||||||
|
RRDTimeFrameResolution::Year => &rrd.year,
|
||||||
|
};
|
||||||
|
let entry = data[index];
|
||||||
|
if entry.count == 0 {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
let value = match mode {
|
||||||
|
RRDMode::Max => entry.max,
|
||||||
|
RRDMode::Average => entry.average,
|
||||||
|
};
|
||||||
|
item[name] = value.into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.push(item);
|
||||||
|
t += reso; index = (index + 1) % RRD_DATA_ENTRIES;
|
||||||
|
}
|
||||||
|
|
||||||
|
list.into()
|
||||||
|
}
|
||||||
|
@ -12,16 +12,26 @@ Ext.define('pve-rrd-node', {
|
|||||||
extend: 'Ext.data.Model',
|
extend: 'Ext.data.Model',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'value',
|
name: 'cpu',
|
||||||
// percentage
|
// percentage
|
||||||
convert: function(value) {
|
convert: function(value) {
|
||||||
return value*100;
|
return value*100;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'iowait',
|
||||||
|
// percentage
|
||||||
|
convert: function(value) {
|
||||||
|
return value*100;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"memtotal",
|
||||||
|
"memused",
|
||||||
{ type: 'date', dateFormat: 'timestamp', name: 'time' }
|
{ type: 'date', dateFormat: 'timestamp', name: 'time' }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Ext.define('PBS.DataStoreStatus', {
|
Ext.define('PBS.DataStoreStatus', {
|
||||||
extend: 'Ext.panel.Panel',
|
extend: 'Ext.panel.Panel',
|
||||||
alias: 'widget.pbsDataStoreStatus',
|
alias: 'widget.pbsDataStoreStatus',
|
||||||
@ -53,10 +63,17 @@ Ext.define('PBS.DataStoreStatus', {
|
|||||||
{
|
{
|
||||||
xtype: 'proxmoxRRDChart',
|
xtype: 'proxmoxRRDChart',
|
||||||
title: gettext('CPU usage'),
|
title: gettext('CPU usage'),
|
||||||
fields: ['value'],
|
fields: ['cpu','iowait'],
|
||||||
fieldTitles: [gettext('CPU usage')],
|
fieldTitles: [gettext('CPU usage'), gettext('IO delay')],
|
||||||
store: rrdstore
|
store: rrdstore
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
xtype: 'proxmoxRRDChart',
|
||||||
|
title: gettext('Memory usage'),
|
||||||
|
fields: ['memtotal','memused'],
|
||||||
|
fieldTitles: [gettext('Total'), gettext('RAM usage')],
|
||||||
|
store: rrdstore
|
||||||
|
},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user