add timeseries container
This commit is contained in:
parent
825e4327c4
commit
cf9ea67452
|
|
@ -0,0 +1,20 @@
|
||||||
|
pub struct Container {
|
||||||
|
max_samples: u32,
|
||||||
|
pub data: Vec<Vec<f32>>, // TODO: make this private, pass iterator instead
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Container {
|
||||||
|
pub fn new(max_samples: u32) -> Container {
|
||||||
|
Container {
|
||||||
|
max_samples: max_samples,
|
||||||
|
data: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn push(&mut self, data: Vec<f32>) {
|
||||||
|
if self.data.len() as u32 > self.max_samples {
|
||||||
|
self.data.pop();
|
||||||
|
}
|
||||||
|
self.data.push(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
|
mod container;
|
||||||
mod observables;
|
mod observables;
|
||||||
|
|
||||||
|
use container::Container;
|
||||||
use draw::{StackedConfig, StackedSeries, StackedSeriesConfig, stacked};
|
use draw::{StackedConfig, StackedSeries, StackedSeriesConfig, stacked};
|
||||||
use imageproc::window::display_image;
|
|
||||||
use observables::CpuObservable;
|
use observables::CpuObservable;
|
||||||
use protocol::Protocol;
|
use protocol::Protocol;
|
||||||
|
use std::{thread, time};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cfg = StackedConfig {
|
let cfg = StackedConfig {
|
||||||
|
|
@ -18,21 +20,22 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Ok(mut proto) = Protocol::new("/var/run/collectd-unixsock") {
|
if let Ok(mut proto) = Protocol::new("/var/run/collectd-unixsock") {
|
||||||
let mut data: Vec<Vec<f32>> = vec![];
|
|
||||||
// loop {
|
// loop {
|
||||||
let cpu = CpuObservable::discover(&mut proto).unwrap();
|
let cpu = CpuObservable::discover(&mut proto).unwrap();
|
||||||
|
let mut container = Container::new(cfg.max_samples);
|
||||||
for _ in 1..10 {
|
for _ in 1..10 {
|
||||||
if data.len() > 10 {
|
|
||||||
data.pop();
|
|
||||||
}
|
|
||||||
let sample = cpu.sample(&mut proto).unwrap();
|
let sample = cpu.sample(&mut proto).unwrap();
|
||||||
data.push(sample);
|
container.push(sample);
|
||||||
|
|
||||||
let img = stacked(StackedSeries {
|
let img = stacked(StackedSeries {
|
||||||
config: &cfg,
|
config: &cfg,
|
||||||
data: &data,
|
data: &container.data,
|
||||||
});
|
});
|
||||||
display_image("bzn", &img, 500, 500);
|
img.save("bzn.png").unwrap();
|
||||||
|
|
||||||
|
thread::sleep(time::Duration::from_secs(1));
|
||||||
|
|
||||||
|
// display_image("bzn", &img, 500, 500);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic!("sock not found!");
|
panic!("sock not found!");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue