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
39
40
41
42
43
44
45
46
47
48
// Copyright 2015-2018 Deyan Ginev. See the LICENSE
// file at the top-level directory of this distribution.
//
// Licensed under the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>.
// This file may not be copied, modified, or distributed
// except according to those terms.

//! Convenience reports for system info (experimental)

use std::collections::HashMap;
use sys_info::*;

/// Prepare a report for the file system metrics offered by `sys_info`
pub fn report<S: ::std::hash::BuildHasher>(
  store: &mut HashMap<String, String, S>,
) -> Result<(), Error> {
  store.insert("sys_os_type".to_string(), os_type().unwrap());
  store.insert("sys_os_release".to_string(), os_release().unwrap());
  store.insert("sys_cpu".to_string(), cpu_num().unwrap().to_string());
  store.insert(
    "sys_cpu_speed".to_string(),
    cpu_speed().unwrap().to_string(),
  );

  store.insert(
    "sys_proc_total".to_string(),
    proc_total().unwrap().to_string(),
  );
  let load = loadavg().unwrap();
  store.insert("sys_load_one".to_string(), load.one.to_string());
  store.insert("sys_load_five".to_string(), load.five.to_string());
  store.insert("sys_load_fifteen".to_string(), load.fifteen.to_string());
  let mem = mem_info().unwrap();
  store.insert("sys_mem_total".to_string(), mem.total.to_string());
  store.insert("sys_mem_free".to_string(), mem.free.to_string());
  store.insert("sys_mem_avail".to_string(), mem.avail.to_string());
  store.insert("sys_mem_buffers".to_string(), mem.buffers.to_string());
  store.insert("sys_mem_cached".to_string(), mem.cached.to_string());

  store.insert("sys_mem_swap_total".to_string(), mem.swap_total.to_string());
  store.insert("sys_mem_swap_free".to_string(), mem.swap_free.to_string());

  let disk = disk_info().unwrap();
  store.insert("sys_disk_total".to_string(), disk.total.to_string());
  store.insert("sys_disk_free".to_string(), disk.free.to_string());
  store.insert("sys_hostname".to_string(), hostname().unwrap());
  Ok(())
}