-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemAlert.php
42 lines (30 loc) · 920 Bytes
/
memAlert.php
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
<?php
// include __DIR__.'/vendor/autoload.php';
// use Joli\JoliNotif\Notification;
// use Joli\JoliNotif\NotifierFactory;
ini_set('max_execution_time', '0');
$icon = __DIR__ . '/icon.png';
while (true) {
$notify = false;
$conf = explode(',', file_get_contents(__DIR__ . '/conf.txt'));
$limitGB = (float)$conf[0];
$intervalSEC = $conf[1];
$data = shell_exec('free -h -t');
$data = explode("\n", $data);
$data = explode(" ", $data[3]);
$tachles = [];
foreach ($data as $val) {
if (!empty($val)) {
$tachles[] = $val;
}
}
if ((float)$tachles[3] < $limitGB || strpos($tachles[3], 'M') > 0) {
$notify = true;
}
var_dump($notify);
if ($notify === true) {
shell_exec("/usr/bin/notify-send -i \"$icon\" \"Low memory\" \"Total: {$tachles[1]} | Available: {$tachles[3]}\"");
}
sleep((int)$intervalSEC);
}
?>