Translated using Weblate (Czech)
[phpmyadmin.git] / libraries / classes / SysInfoLinux.php
blob3fc4f612745365e619c171baff69f56a8768cc74
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Hold PhpMyAdmin\SysInfoLinux class
6 * @package PhpMyAdmin
7 */
8 namespace PhpMyAdmin;
10 use PhpMyAdmin\SysInfo;
11 use PhpMyAdmin\SysInfoBase;
13 /**
14 * Linux based SysInfo class
16 * @package PhpMyAdmin
18 class SysInfoLinux extends SysInfoBase
20 public $os = 'Linux';
22 /**
23 * Gets load information
25 * @return array with load data
27 function loadavg()
29 $buf = file_get_contents('/proc/stat');
30 $nums = preg_split(
31 "/\s+/",
32 mb_substr(
33 $buf,
35 mb_strpos($buf, "\n")
39 return Array(
40 'busy' => $nums[1] + $nums[2] + $nums[3],
41 'idle' => intval($nums[4]),
45 /**
46 * Checks whether class is supported in this environment
48 * @return true on success
50 public function supported()
52 return @is_readable('/proc/meminfo') && @is_readable('/proc/stat');
55 /**
56 * Gets information about memory usage
58 * @return array with memory usage data
60 function memory()
62 preg_match_all(
63 SysInfo::MEMORY_REGEXP,
64 file_get_contents('/proc/meminfo'),
65 $matches
68 $mem = array_combine($matches[1], $matches[2]);
70 $defaults = array(
71 'MemTotal' => 0,
72 'MemFree' => 0,
73 'Cached' => 0,
74 'Buffers' => 0,
75 'SwapTotal' => 0,
76 'SwapFree' => 0,
77 'SwapCached' => 0,
80 $mem = array_merge($defaults, $mem);
82 foreach ($mem as $idx => $value) {
83 $mem[$idx] = intval($value);
86 $mem['MemUsed'] = $mem['MemTotal']
87 - $mem['MemFree'] - $mem['Cached'] - $mem['Buffers'];
89 $mem['SwapUsed'] = $mem['SwapTotal']
90 - $mem['SwapFree'] - $mem['SwapCached'];
92 return $mem;