api.systeminfo.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /**
  3. * Basic system health report
  4. */
  5. class SystemInfo {
  6. /**
  7. * Contains alter config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * System hardware info instance placeholder
  14. *
  15. * @var object
  16. */
  17. protected $hwInfo = '';
  18. /**
  19. * Contains binpaths config as key=>value
  20. *
  21. * @var array
  22. */
  23. protected $binPaths = array();
  24. /**
  25. * Storages instance placeholder.
  26. *
  27. * @var object
  28. */
  29. protected $storages = '';
  30. /**
  31. * System messages helper instance placeholder
  32. *
  33. * @var object
  34. */
  35. protected $messages = '';
  36. public function __construct() {
  37. $this->initMessages();
  38. $this->loadConfigs();
  39. $this->initStorages();
  40. $this->initHwInfo();
  41. }
  42. /**
  43. * Inits system messages helper
  44. *
  45. * @return void
  46. */
  47. protected function initMessages() {
  48. $this->messages = new UbillingMessageHelper();
  49. }
  50. /**
  51. * Loads all required configs
  52. *
  53. * @global object $ubillingConfig
  54. *
  55. * @return void
  56. */
  57. protected function loadConfigs() {
  58. global $ubillingConfig;
  59. $this->altCfg = $ubillingConfig->getAlter();
  60. $this->binPaths = $ubillingConfig->getBinpaths();
  61. }
  62. /**
  63. * Inits storages into protected prop for further usage
  64. *
  65. * @return void
  66. */
  67. protected function initStorages() {
  68. $this->storages = new Storages();
  69. }
  70. /**
  71. * Inits system hw info instance
  72. *
  73. * @return void
  74. */
  75. protected function initHwInfo() {
  76. $this->hwInfo = new SystemHwInfo();
  77. }
  78. /**
  79. * Renders current system load average stats
  80. *
  81. * @return string
  82. */
  83. public function renderSysLoad() {
  84. $size=280;
  85. $container=$size+20;
  86. $result = '';
  87. $result .= wf_tag('h3') . __('System load') . wf_tag('h3', true);
  88. $laOpts = '
  89. max: 100,
  90. min: 0,
  91. width: ' . $size . ', height: ' . $size . ',
  92. greenFrom: 0, greenTo: 40,
  93. yellowFrom:40, yellowTo: 70,
  94. redFrom: 70, redTo: 100,
  95. minorTicks: 5
  96. ';
  97. $result .= wf_renderGauge($this->hwInfo->getloadAvgPercent(), ' ' . __('on average'), '%', $laOpts, $container);
  98. $result .= wf_renderGauge($this->hwInfo->getLoadPercent1(), '1' . ' ' . __('minutes'), '%', $laOpts, $container);
  99. $result .= wf_renderGauge($this->hwInfo->getLoadPercent5(), '5' . ' ' . __('minutes'), '%', $laOpts, $container);
  100. $result .= wf_renderGauge($this->hwInfo->getLoadPercent15(), '15' . ' ' . __('minutes'), '%', $laOpts, $container);
  101. $result .= wf_CleanDiv();
  102. return ($result);
  103. }
  104. /**
  105. * Renders some free space data about free disk space
  106. *
  107. * @return string
  108. */
  109. public function renderDisksCapacity() {
  110. $size=280;
  111. $usedSpaceArr = array();
  112. $mountPoints = array();
  113. $mountPointNames = array();
  114. $availableStorages = $this->storages->getAllStoragesData();
  115. $allStorageNames = $this->storages->getAllStorageNamesLocalized();
  116. //root fs
  117. $mountPoints[0]='/';
  118. $mountPointNames['/'] = __('System');
  119. if (!empty($availableStorages)) {
  120. foreach ($availableStorages as $storageId => $each) {
  121. $mountPoints[$each['id']] = $each['path'];
  122. $mountPointNames[$each['path']] = $allStorageNames[$each['id']];
  123. }
  124. }
  125. $this->hwInfo->setMountPoints($mountPoints);
  126. $usedSpaceArr = $this->hwInfo->getAllDiskStats();
  127. $reservedPercent = $this->altCfg['STORAGE_RESERVED_SPACE'];
  128. $maxCapacity = 100;
  129. $greenFrom = 0;
  130. $greenTo = $maxCapacity - $reservedPercent;
  131. $yellowFrom = $greenTo;
  132. $yellowTo = ($maxCapacity - $reservedPercent) + ($reservedPercent / 2);
  133. $redFrom = $yellowTo;
  134. $redTo = $maxCapacity;
  135. $result = '';
  136. $result .= wf_tag('h3') . __('Storages capacity') . wf_tag('h3', true);
  137. $opts = '
  138. max: 100,
  139. min: 0,
  140. width: ' . $size . ', height: ' . $size . ',
  141. greenFrom:' . $greenFrom . ', greenTo: ' . $greenTo . ',
  142. yellowFrom:' . $yellowFrom . ', yellowTo: ' . $yellowTo . ',
  143. redFrom:' . $redFrom . ', redTo:' . $redTo . ',
  144. minorTicks: 5
  145. ';
  146. if (!empty($usedSpaceArr)) {
  147. foreach ($usedSpaceArr as $mountPoint => $spaceStats) {
  148. $freeLabel = wr_convertSize($spaceStats['free']);
  149. $totalLabel = wr_convertSize($spaceStats['total']);
  150. $partitionLabel = $mountPointNames[$mountPoint] . ' - ' . $freeLabel . ' ' . __('of') . ' ' . $totalLabel . ' ' . __('Free');
  151. $result .= wf_renderGauge(round($spaceStats['usedpercent']), $partitionLabel, '%', $opts, ($size+20));
  152. }
  153. } else {
  154. $result .= $this->messages->getStyledMessage(__('No storages available'), 'warning');
  155. }
  156. $result .= wf_CleanDiv();
  157. return ($result);
  158. }
  159. /**
  160. * Renders current instance serial as info-box
  161. *
  162. * @return string
  163. */
  164. public function renderSerialInfo() {
  165. $result = '';
  166. $instanceSerial = wr_SerialGet();
  167. if (!empty($instanceSerial)) {
  168. $rawRelease = file_get_contents('RELEASE');
  169. $infoLabel = __('WolfRecorder') . ' ' . $rawRelease . ', ';
  170. $infoLabel .= __('This system serial number') . ': ' . wf_tag('b') . $instanceSerial . wf_tag('b', true);
  171. $result .= $this->messages->getStyledMessage(wf_tag('center') . $infoLabel . wf_tag('center', true), 'info');
  172. } else {
  173. $result .= $this->messages->getStyledMessage(__('Something went wrong'), 'error');
  174. }
  175. $cpuName = $this->hwInfo->getCpuName();
  176. $cpuCores = $this->hwInfo->getCpuCores();
  177. $memTotal = $this->hwInfo->getMemTotal();
  178. $uptime = $this->hwInfo->getUptime();
  179. $osLabel = $this->hwInfo->getOs() . ' ' . $this->hwInfo->getOsRelease() . ', ';
  180. $phpLabel = __('PHP') . ': ' . $this->hwInfo->getPhpVersion() . ', ';
  181. $memLabel = wr_convertSize($memTotal) . ' ' . __('RAM') . '.';
  182. $uptimeLabel = __('Uptime') . ': ' . zb_formatTime($uptime);
  183. $sysLabel = __('CPU') . ': ' . $cpuName . ', ' . $cpuCores . ' ' . __('Cores') . ', ' . $memLabel;
  184. $sysLabel .= ' ' . $osLabel . ' ' . $phpLabel . ' ' . $uptimeLabel;
  185. $result .= $this->messages->getStyledMessage(wf_tag('center') . $sysLabel . wf_tag('center', true), 'success');
  186. $result .= wf_delimiter(0);
  187. return ($result);
  188. }
  189. }