SunOs.php 1.9 KB

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