Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / SysInfoLinux.php
blobc2afba8b12b16202661987fb66735d155b2d9926
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Hold PMA\libraries\SysInfoLinux class
6 * @package PMA
7 */
8 namespace PMA\libraries;
10 /**
11 * Linux based SysInfo class
13 * @package PhpMyAdmin-sysinfo
15 class SysInfoLinux extends \PMA\libraries\SysInfo
17 public $os = 'Linux';
19 /**
20 * Gets load information
22 * @return array with load data
24 function loadavg()
26 $buf = file_get_contents('/proc/stat');
27 $nums = preg_split(
28 "/\s+/",
29 mb_substr(
30 $buf,
32 mb_strpos($buf, "\n")
36 return Array(
37 'busy' => $nums[1] + $nums[2] + $nums[3],
38 'idle' => intval($nums[4]),
42 /**
43 * Checks whether class is supported in this environment
45 * @return true on success
47 public function supported()
49 return @is_readable('/proc/meminfo') && @is_readable('/proc/stat');
52 /**
53 * Gets information about memory usage
55 * @return array with memory usage data
57 function memory()
59 preg_match_all(
60 MEMORY_REGEXP,
61 file_get_contents('/proc/meminfo'),
62 $matches
65 $mem = array_combine($matches[1], $matches[2]);
67 $defaults = array(
68 'MemTotal' => 0,
69 'MemFree' => 0,
70 'Cached' => 0,
71 'Buffers' => 0,
72 'SwapTotal' => 0,
73 'SwapFree' => 0,
74 'SwapCached' => 0,
77 $mem = array_merge($defaults, $mem);
79 foreach ($mem as $idx => $value) {
80 $mem[$idx] = intval($value);
83 $mem['MemUsed'] = $mem['MemTotal']
84 - $mem['MemFree'] - $mem['Cached'] - $mem['Buffers'];
86 $mem['SwapUsed'] = $mem['SwapTotal']
87 - $mem['SwapFree'] - $mem['SwapCached'];
89 return $mem;