forked from dtouzeau/artica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.swap-monitor.php
69 lines (46 loc) · 1.83 KB
/
exec.swap-monitor.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
include_once(dirname(__FILE__).'/ressources/class.templates.inc');
include_once(dirname(__FILE__).'/ressources/class.os.system.inc');
include_once(dirname(__FILE__).'/ressources/class.system.network.inc');
include_once(dirname(__FILE__).'/framework/class.unix.inc');
include_once(dirname(__FILE__)."/framework/frame.class.inc");
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
if($argv[1]=='--free'){FreeSync();}
include_once(dirname(__FILE__).'/framework/class.unix.inc');
if(!Build_pid_func(__FILE__,"MAIN")){
writelogs(basename(__FILE__).":Already executed.. aborting the process",basename(__FILE__),__FILE__,__LINE__);
die();
}
$os=new os_system();
$mem=$os->memory();
$swap_percent=$mem["swap"]["percent"];
$swap_used=$mem["swap"]["used"];
$ram_free=$mem["ram"]["free"];
$ram_total=$mem["ram"]["total"];
$operation_disponible=$ram_free-$swap_used;
$max=str_replace(" "," ",FormatBytes(round($ram_total/2)));
$swap_used=$mem["swap"]["used"];
$swap_used_mo=str_replace(" "," ",FormatBytes($swap_used));
$ram_free_mo=FormatBytes($ram_free);
$log="swap used: $swap_percent% ({$swap_used_mo}) , Max $max ; free memory=$ram_free_mo, cache fore back=$operation_disponible";
echo $log."\n";
print_r($mem);
function events($text){
$d=new debuglogs();
$logFile="/var/log/artica-postfix/artica-swap-monitor.debug";
$d->events(basename(__FILE__)." $text",$logFile);
}
function FreeSync(){
if(!Build_pid_func(__FILE__,__FUNCTION__)){return null;}
$unix=new unix();
$sync=$unix->find_program("sync");
@file_put_contents("/proc/sys/vm/drop_cache","1");
shell_exec($sync);
@file_put_contents("/proc/sys/vm/drop_cache","2");
shell_exec($sync);
@file_put_contents("/proc/sys/vm/drop_cache","3");
shell_exec($sync);
shell_exec("swapoff -a && swapon -a");
@file_put_contents("/proc/sys/vm/drop_cache","0");
}
?>