procshot_server Build Status

A lame attempt of a rust crate (refer this for crate documentation) to record /proc stats periodically. This library just records the stats. Processing to be done separately. This is written as a part of learning rust.

Server example

```rust use procshotserver::{Config, checksudo, scanproc}; use std::process; use users::getcurrentuid; use procshotclient; const DATADIR: &'static str = "/var/log/procshot/data";

fn main() { match checksudo(getcurrentuid()) { Err(e) => { eprintln!("Error encountered checking privileges, {:?}", e); process::exit(1); }, _ => (), } std::fs::createdirall(DATADIR).unwrap(); let config: Config = Config::new(); match config.server{ true => scanproc(config.delay, config.hostname, DATADIR), false => procshotclient::readtest_data(), } } ```

This will generate a binary with the following cli options

```bash

procshot 1.0 nohupped@gmail.com Snapshots proc periodically. All the options except delay works when 'server' option is not used.

USAGE: procshot [FLAGS] [OPTIONS] [SUBCOMMAND]

FLAGS: -h, --help Prints help information -o Sort result by Memory or CPU. Accepted values are... -t Read stats from a specific time. Accepted format: 2015-09-05 23:56:04 -V, --version Prints version information

OPTIONS: -d, --delay Sets delay in seconds before it scans /proc every time. Defaults to 60 seconds. [default: 60]

SUBCOMMANDS: help Prints this message or the help of the given subcommand(s) server Decides whether to run as server or client ```

Client example on how to read the stored data

```rust use std::fs::File; use std::io::Read; use procshotserver::EncoDecode; pub fn readtestdata() { let mut file = File::open("./testdata.procshot").unwrap(); let mut data = Vec::new(); file.readtoend(&mut data).unwrap(); let decoded: EncoDecode = bincode::deserialize(&data[..]).unwraporelse(|x| panic!("Error reading saved data. This was either created with an older version of procshot, or the file is corrupt. Error is {}", x)); println!("Decoded test file data: {:#?}", decoded); }

```

Sample output of stored data

$ sudo ./target/release/procshot ```shell
Decoded test file data: EncoDecode { hostname: "localghost", pidmaplist: { 169883: PidStatus { ppid: 3284, euid: 1000, cmdlong: [ "/opt/google/chrome/chrome --type=renderer --field-trial-handle=11321657219978072658,9761930160602287450,131072 --lang=en-US --disable-client-side-phishing-detection --enable-auto-reload --num-raster-threads=4 --enable-main-frame-before-activation --service-request-channel-token=1438087544763584805 --renderer-client-id=214 --no-v8-untrusted-code-mitigations --shared-files=v8contextsnapshotdata:100,v8nativesdata:101", ], name: "chrome", cmdshort: "chrome", tracerpid: 0, fdsize: 64, state: "S (sleeping)", vmpeak: Some( 549888, ), vmsize: Some( 525300, ), rsspages: 13139, rssbytes: 53817344, rsslimbytes: 18446744073709551615, processorlastexecuted: Some( 4, ), utime: 5, stime: 2, usercpuusage: 0.0, syscpuusage: 0.0, }, 2078: PidStatus { ppid: 1783, euid: 1000, cmdlong: [ "/usr/lib/at-spi2-registryd", "--use-gnome-session", ], name: "at-spi2-registr", cmdshort: "at-spi2-registr", tracerpid: 0, fdsize: 64, state: "S (sleeping)", vmpeak: Some( 229136, ), vmsize: Some( 163600, ), rsspages: 1472, rssbytes: 6029312, rsslimbytes: 18446744073709551615, processorlastexecuted: Some( 2, ), utime: 1, stime: 0, usercpuusage: 0.0, syscpuusage: 0.0, }, 2130: PidStatus { ppid: 1783, euid: 1000, cmdlong: [ "/usr/lib/gsd-screensaver-proxy", ], name: "gsd-screensaver", cmdshort: "gsd-screensaver", tracerpid: 0, fdsize: 64, state: "S (sleeping)", vmpeak: Some( 234084, ), vmsize: Some( 234084, ), rsspages: 1094, rssbytes: 4481024, rsslimbytes: 18446744073709551615, processorlastexecuted: Some( 6, ), utime: 1, stime: 0, usercpuusage: 0.0, syscpuusage: 0.0, }, 2112: PidStatus { ppid: 1783, euid: 1000, cmdlong: [ "/usr/lib/gsd-housekeeping", ], name: "gsd-housekeepin", cmdshort: "gsd-housekeepin", tracerpid: 0, fdsize: 64, state: "S (sleeping)", vmpeak: Some( 375152, ), vmsize: Some( 310204, ), rsspages: 1764, rssbytes: 7225344, rsslimbytes: 18446744073709551615, processorlastexecuted: Some( 10, ), utime: 7, stime: 7, usercpuusage: 0.0, syscpu_usage: 0.0, }, ..... snip .....

time_epoch: 1563617611,
delay: 5,
total_cpu_time: 6331606,

```