1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::io::ErrorKind;
use crate::scanner_rust::generic_array::typenum::U24;
use crate::scanner_rust::{ScannerAscii, ScannerError};
#[derive(Default, Debug, Clone)]
pub struct LoadAverage {
pub one: f64,
pub five: f64,
pub fifteen: f64,
}
#[inline]
pub fn get_load_average() -> Result<LoadAverage, ScannerError> {
let mut sc: ScannerAscii<_, U24> = ScannerAscii::scan_path2("/proc/loadavg")?;
let one = sc.next_f64()?.ok_or(ErrorKind::UnexpectedEof)?;
let five = sc.next_f64()?.ok_or(ErrorKind::UnexpectedEof)?;
let fifteen = sc.next_f64()?.ok_or(ErrorKind::UnexpectedEof)?;
Ok(LoadAverage {
one,
five,
fifteen,
})
}