summaryrefslogtreecommitdiff
path: root/libs/swap.php
diff options
context:
space:
mode:
Diffstat (limited to 'libs/swap.php')
-rw-r--r--libs/swap.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/libs/swap.php b/libs/swap.php
new file mode 100644
index 0000000..93bd323
--- /dev/null
+++ b/libs/swap.php
@@ -0,0 +1,31 @@
+<?php
+require 'Utils/Misc.class.php';
+
+
+// Free
+if (!($free = shell_exec('grep SwapFree /proc/meminfo | awk \'{print $2}\'')))
+{
+ $free = 0;
+}
+
+// Total
+if (!($total = shell_exec('grep SwapTotal /proc/meminfo | awk \'{print $2}\'')))
+{
+ $total = 0;
+}
+
+// Used
+$used = $total - $free;
+
+// Percent used
+$percent_used = 100 - (round($free / $total * 100));
+
+
+$datas = array(
+ 'used' => Misc::getSize($used * 1024),
+ 'free' => Misc::getSize($free * 1024),
+ 'total' => Misc::getSize($total * 1024),
+ 'percent_used' => $percent_used,
+);
+
+echo json_encode($datas); \ No newline at end of file