<commit_before>extern crate libc;
extern crate numbat;

use std::mem::zeroed;
use std::ffi::CString;
use forza;

fn get_disk_usage(mountpoint: &str) -> Result<f64, String> {
  unsafe {
    let mut stats: libc::statvfs = zeroed();
    match libc::statvfs(CString::new(mountpoint).unwrap().as_ptr(), &mut stats) {
      -1 => Err(String::from("statvfs() failed")),
      _ => {
        let total = stats.f_blocks * stats.f_frsize;
        let used = total - (stats.f_bavail * stats.f_bsize);
        Ok(used as f64 / total as f64)
      }
    }
  }
}

pub struct DiskUsage<'a> {
  emitter: numbat::Emitter<'a>,
}

impl<'a> DiskUsage<'a> {
  pub fn new(emitter: numbat::Emitter<'a>) -> DiskUsage {
    DiskUsage {
      emitter: emitter
    }
  }

  fn send(&mut self) {
    let ret = get_disk_usage("/");
    match ret {
      Ok(usage) => {
        self.emitter.emit("disk-usage", usage);
      },
      Err(e) => panic!("statvfs() failed: {}", e)
    }

  }
}

impl<'a> forza::ForzaPlugin for DiskUsage<'a> {
  fn start(&mut self) {
    println!("starting disk usage plugin");
    forza::schedule_repeating(move || {
      self.send();
    }, 120);
  }
}<commit_msg>feat: send disk usage for / and /mnt<commit_after>extern crate libc;
extern crate numbat;

use std::mem::zeroed;
use std::ffi::CString;
use forza;

fn get_disk_usage(mountpoint: &str) -> Result<f64, String> {
  unsafe {
    let mut stats: libc::statvfs = zeroed();
    match libc::statvfs(CString::new(mountpoint).unwrap().as_ptr(), &mut stats) {
      -1 => Err(String::from("statvfs() failed")),
      _ => {
        let total = stats.f_blocks * stats.f_frsize;
        let used = total - (stats.f_bavail * stats.f_bsize);
        Ok(used as f64 / total as f64)
      }
    }
  }
}

pub struct DiskUsage<'a> {
  emitter: numbat::Emitter<'a>,
}

impl<'a> DiskUsage<'a> {
  pub fn new(emitter: numbat::Emitter<'a>) -> DiskUsage {
    DiskUsage {
      emitter: emitter
    }
  }

  fn send(&mut self) {
    self.send_for_mountpoint("/");
    self.send_for_mountpoint("/mnt");
  }

  fn send_for_mountpoint(&mut self, mountpoint: &str) {
    let usage = get_disk_usage(mountpoint);
    if usage.is_ok() {
      self.emitter.emit(&(String::from("disk-usage.") + mountpoint), usage.unwrap());
    }
  }
}

impl<'a> forza::ForzaPlugin for DiskUsage<'a> {
  fn start(&mut self) {
    println!("starting disk usage plugin");
    forza::schedule_repeating(move || {
      self.send();
    }, 120);
  }
}
{'fraction_non_alphanumeric': 0.1709991876523152, 'fraction_numerical': 0.008123476848090982, 'mean_word_length': 3.0710743801652893, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7288408', 'n_tokens_mistral': 933, 'n_tokens_neox': 906, 'n_words': 187}