1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/../../Base/Model.php');
|
---|
4 |
|
---|
5 | class Platform extends Model
|
---|
6 | {
|
---|
7 | var $Id;
|
---|
8 |
|
---|
9 | function __construct($System)
|
---|
10 | {
|
---|
11 | parent::__construct($System);
|
---|
12 | }
|
---|
13 |
|
---|
14 | function MemoryUsage()
|
---|
15 | {
|
---|
16 | $Output = array();
|
---|
17 | exec('free -b', $Output);
|
---|
18 | $Row = $Output[2];
|
---|
19 | while(strpos($Row, ' ') !== false) $Row = str_replace(' ', ' ', $Row);
|
---|
20 | $RowParts = explode(' ', $Row);
|
---|
21 | $Row = $Output[3];
|
---|
22 | while(strpos($Row, ' ') !== false) $Row = str_replace(' ', ' ', $Row);
|
---|
23 | $RowParts2 = explode(' ', $Row);
|
---|
24 | return($RowParts[2] + $RowParts2[2]);
|
---|
25 | }
|
---|
26 |
|
---|
27 | function MemoryTotal()
|
---|
28 | {
|
---|
29 | $Output = array();
|
---|
30 | exec('free -b', $Output);
|
---|
31 | $Row = $Output[1];
|
---|
32 | while(strpos($Row, ' ') !== false) $Row = str_replace(' ', ' ', $Row);
|
---|
33 | $RowParts = explode(' ', $Row);
|
---|
34 | return($RowParts[1]);
|
---|
35 | }
|
---|
36 |
|
---|
37 | function SystemUptime()
|
---|
38 | {
|
---|
39 | $File = fopen('/proc/uptime', 'r');
|
---|
40 | $Uptime = fgets($File);
|
---|
41 | fclose($File);
|
---|
42 | $UptimeParts = explode(' ', $Uptime);
|
---|
43 | return($UptimeParts[0]);
|
---|
44 | }
|
---|
45 |
|
---|
46 | function State()
|
---|
47 | {
|
---|
48 | $State = array();
|
---|
49 | $State['MemoryUsed'] = $this->MemoryUsage();
|
---|
50 | $State['MemoryTotal'] = $this->MemoryTotal();
|
---|
51 | $State['Uptime'] = $this->SystemUptime();
|
---|
52 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Server`');
|
---|
53 | $DbRow = $DbResult->fetch_row();
|
---|
54 | $State['ServerCount'] = $DbRow[0];
|
---|
55 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Server` WHERE `Online` = 1');
|
---|
56 | $DbRow = $DbResult->fetch_row();
|
---|
57 | $State['ServerOnlineCount'] = $DbRow[0];
|
---|
58 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `User`');
|
---|
59 | $DbRow = $DbResult->fetch_row();
|
---|
60 | $State['UserCount'] = $DbRow[0];
|
---|
61 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Emulator`');
|
---|
62 | $DbRow = $DbResult->fetch_row();
|
---|
63 | $State['EmulatorCount'] = $DbRow[0];
|
---|
64 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Backup`');
|
---|
65 | $DbRow = $DbResult->fetch_row();
|
---|
66 | $State['BackupCount'] = $DbRow[0];
|
---|
67 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Task`');
|
---|
68 | $DbRow = $DbResult->fetch_row();
|
---|
69 | $State['TaskCount'] = $DbRow[0];
|
---|
70 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Database`');
|
---|
71 | $DbRow = $DbResult->fetch_row();
|
---|
72 | $State['DatabaseCount'] = $DbRow[0];
|
---|
73 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Task` WHERE `State` != 2');
|
---|
74 | $DbRow = $DbResult->fetch_row();
|
---|
75 | $State['TaskQueued'] = $DbRow[0];
|
---|
76 | $State['ServerMaxCount'] = $this->Config['MaxServerCount'];
|
---|
77 | return($State);
|
---|
78 | }
|
---|
79 | }
|
---|