aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorScott Lawrence <scott+git@ineffectivetheory.com>2024-11-26 23:23:39 -0700
committerScott Lawrence <scott+git@ineffectivetheory.com>2024-11-26 23:23:39 -0700
commit0b8779738bf7e673173498f1f0c5610abeb757e7 (patch)
treee5a9c165789176c03e53957ab840f478d9263cc3 /src
parentb5ad4356a26dbe9b28df2422cbd65fd182e6094a (diff)
downloadvaranus-0b8779738bf7e673173498f1f0c5610abeb757e7.tar.gz
varanus-0b8779738bf7e673173498f1f0c5610abeb757e7.tar.bz2
varanus-0b8779738bf7e673173498f1f0c5610abeb757e7.zip
Calling sysinfo
Diffstat (limited to 'src')
-rw-r--r--src/main.rs56
1 files changed, 53 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index cd5df09..0848754 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,6 +18,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+/* TODO
+ *
+ * Remove socket file when daemon exits.
+ *
+ * Accept command-line arguments to query only part of JSON
+ *
+ * Fix delay
+ *
+ */
+
use std::error;
use std::fs::remove_file;
use std::io::{Read,Write};
@@ -30,6 +40,36 @@ use std::time::{Duration,Instant,SystemTime};
use clap::Parser;
use serde::{Serialize,Deserialize};
+#[derive(Default)]
+#[repr(C)]
+struct Sysinfo {
+ uptime: cty::c_long,
+ loads: [cty::c_ulong; 3],
+ totalram: cty::c_ulong,
+ freeram: cty::c_ulong,
+ sharedram: cty::c_ulong,
+ bufferram: cty::c_ulong,
+ totalswap: cty::c_ulong,
+ freeswap: cty::c_ulong,
+ procs: cty::c_ushort,
+ totalhigh: cty::c_ulong,
+ freehigh: cty::c_ulong,
+ mem_unit: cty::c_uint,
+ /*char _f[20-2*sizeof(long)-sizeof(int)];*/
+}
+
+extern "C" {
+ fn sysinfo(si: *mut Sysinfo) -> cty::c_int;
+}
+
+impl Sysinfo {
+ fn new() -> Self {
+ let mut si = Sysinfo::default();
+ unsafe { sysinfo(&mut si) };
+ return si;
+ }
+}
+
#[derive(Parser)]
struct Cli {
#[arg(short='d', long)]
@@ -61,11 +101,18 @@ struct Process {
}
#[derive(Debug, Serialize, Deserialize)]
+struct ProcFS {
+}
+
+impl ProcFS {
+}
+
+#[derive(Debug, Serialize, Deserialize)]
struct Memory {
}
impl Memory {
- fn new() -> Self {
+ fn new(si: Sysinfo) -> Self {
return Memory{}
}
}
@@ -73,6 +120,7 @@ impl Memory {
#[derive(Debug, Serialize, Deserialize)]
struct State {
asof: SystemTime,
+ uptime: i64,
power: Power,
memory: Memory,
}
@@ -80,10 +128,12 @@ struct State {
impl State {
fn new() -> Self {
let asof = SystemTime::now();
+ let si = Sysinfo::new();
return State {
asof: asof,
+ uptime: si.uptime,
power: Power::new(),
- memory: Memory::new()
+ memory: Memory::new(si)
}
}
@@ -109,7 +159,7 @@ fn main() {
let args = Cli::parse();
if args.daemon {
let start = Instant::now();
- let delay_ms: u64 = args.delay * 1000;
+ let delay_ms: u64 = args.delay * 1000; // TODO not right
let mut cycle: u64 = 0;
let state_mutex = Arc::new(Mutex::new(State::new()));
let listen_thread = {