SysInfoSunOS.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Hold PhpMyAdmin\SysInfoSunOS class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin;
  9. use PhpMyAdmin\SysInfoBase;
  10. /**
  11. * SunOS based SysInfo class
  12. *
  13. * @package PhpMyAdmin
  14. */
  15. class SysInfoSunOS extends SysInfoBase
  16. {
  17. public $os = 'SunOS';
  18. /**
  19. * Read value from kstat
  20. *
  21. * @param string $key Key to read
  22. *
  23. * @return string with value
  24. */
  25. private function _kstat($key)
  26. {
  27. if ($m = shell_exec('kstat -p d ' . $key)) {
  28. list(, $value) = preg_split("/\t/", trim($m), 2);
  29. return $value;
  30. } else {
  31. return '';
  32. }
  33. }
  34. /**
  35. * Gets load information
  36. *
  37. * @return array with load data
  38. */
  39. public function loadavg()
  40. {
  41. $load1 = $this->_kstat('unix:0:system_misc:avenrun_1min');
  42. return array('loadavg' => $load1);
  43. }
  44. /**
  45. * Checks whether class is supported in this environment
  46. *
  47. * @return true on success
  48. */
  49. public function supported()
  50. {
  51. return @is_readable('/proc/meminfo');
  52. }
  53. /**
  54. * Gets information about memory usage
  55. *
  56. * @return array with memory usage data
  57. */
  58. public function memory()
  59. {
  60. $pagesize = $this->_kstat('unix:0:seg_cache:slab_size');
  61. $mem = array();
  62. $mem['MemTotal']
  63. = $this->_kstat('unix:0:system_pages:pagestotal') * $pagesize;
  64. $mem['MemUsed']
  65. = $this->_kstat('unix:0:system_pages:pageslocked') * $pagesize;
  66. $mem['MemFree']
  67. = $this->_kstat('unix:0:system_pages:pagesfree') * $pagesize;
  68. $mem['SwapTotal'] = $this->_kstat('unix:0:vminfo:swap_avail') / 1024;
  69. $mem['SwapUsed'] = $this->_kstat('unix:0:vminfo:swap_alloc') / 1024;
  70. $mem['SwapFree'] = $this->_kstat('unix:0:vminfo:swap_free') / 1024;
  71. return $mem;
  72. }
  73. }