arw_monitor.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class arw_monitorControl extends SystemControl
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. }
  8. public function indexOp()
  9. {
  10. global $config;
  11. $servers = $config['server'];
  12. $ins = Cache::getInstance('cacheredis');
  13. $name = 'disk_monitor';
  14. $hash_data = $ins->hget($name, '');
  15. $result = [];
  16. $cur_time = time();
  17. $ago_time = 0;
  18. $time_check = function($stat_str, $cur_time) {
  19. $value = explode('-', $stat_str);
  20. $value = "$value[0]-$value[1]-$value[2] $value[3]:$value[4]:$value[5]";
  21. $stat_time = strtotime($value);
  22. if($stat_time == false) return false;
  23. $check_seconds = 1800;
  24. $diff_time = $cur_time - $stat_time;
  25. if($diff_time > $check_seconds) {
  26. return false;
  27. }else{
  28. return $diff_time;
  29. }
  30. };
  31. foreach ($servers as $ip => $server_name) {
  32. $hash_str = $hash_data[$ip];
  33. $item = [];
  34. if (!empty($hash_str)) {
  35. $hash_str = str_replace('\t', "", $hash_str);
  36. $hash_str = ltrim($hash_str, '#');
  37. $arrs = explode('#', $hash_str);
  38. foreach ($arrs as $arr) {
  39. $data = explode(':', $arr);
  40. $key = ltrim($data[0], '_');
  41. $value = $data[1];
  42. if ($key == 'cur_time') {
  43. $diff_time = $time_check($value, $cur_time);
  44. if ($diff_time == false) {
  45. $value = '定时更新未正常工作';
  46. } else {
  47. $ago_time = $diff_time;
  48. }
  49. } elseif (strpos($key, 'dev') !== false) {
  50. $key = str_replace('_', "/", $key);
  51. $value = explode(',', $value);
  52. $value = "{$value[1]}/{$value[0]}";
  53. } else {
  54. $key = str_replace('_', "/", $key);
  55. $value = rtrim($value, '.');
  56. }
  57. $item[$key] = $value;
  58. ksort($item);
  59. }
  60. }
  61. $result[$ip . "({$server_name})"] = $item;
  62. }
  63. Tpl::output('data', $result);
  64. Tpl::output('ago_time', $this->elapse_time($ago_time));
  65. Tpl::showpage('arw.monitor');
  66. }
  67. }