]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/bin/proxmox-backup-proxy.rs: gather root disk stats
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 25 May 2020 09:10:07 +0000 (11:10 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 25 May 2020 09:10:07 +0000 (11:10 +0200)
src/bin/proxmox-backup-proxy.rs

index 748958a751af10010ba0882bca2d7442df03ef18..347e6b7b74e54a7b405298004ec38119f1fd8df4 100644 (file)
@@ -658,5 +658,35 @@ async fn generate_host_stats() {
                 eprintln!("read_prox_net_dev failed - {}", err);
             }
         }
+
+        match disk_usage(std::path::Path::new("/")) {
+            Ok((total, used, _avail)) => {
+                if let Err(err) = rrd::update_value("host/roottotal", total as f64, rrd::DST::Gauge) {
+                    eprintln!("rrd::update_value 'host/roottotal' failed - {}", err);
+                }
+                if let Err(err) = rrd::update_value("host/rootused", used as f64, rrd::DST::Gauge) {
+                    eprintln!("rrd::update_value 'host/rootused' failed - {}", err);
+                }
+            }
+            Err(err) => {
+                eprintln!("read root disk_usage failed - {}", err);
+            }
+        }
+
     });
 }
+
+// Returns (total, used, avail)
+fn disk_usage(path: &std::path::Path) -> Result<(u64, u64, u64), Error> {
+
+    let mut stat: libc::statfs64 = unsafe { std::mem::zeroed() };
+
+    use nix::NixPath;
+
+    let res = path.with_nix_path(|cstr| unsafe { libc::statfs64(cstr.as_ptr(), &mut stat) })?;
+    nix::errno::Errno::result(res)?;
+
+    let bsize = stat.f_bsize as u64;
+
+    Ok((stat.f_blocks*bsize, (stat.f_blocks-stat.f_bfree)*bsize, stat.f_bavail*bsize))
+}