123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- use PHPUnit\Framework\TestCase;
- define('APP_ID', 'test');
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_CORE_PATH . '/lrlz.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- class TestArwMonitor extends TestCase
- {
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- }
- public function testMonitor()
- {
- $str = '/mnt:7.3T,5.7T#/dev/shm:28G,28G#/run/lock:5.0M,5.0M#cur_time:2023-08-24-16-08-02#/home/dongpeng:687M .#/data:7.3T,6.8T';
- $convert_time = function ($stime)
- {
- $val = explode('-', $stime);
- $val = "$val[0]-$val[1]-$val[2] $val[3]:$val[4]:$val[5]";
- $time = strtotime($val);
- return $time;
- };
- $calc_bytes = function ($str_capacity)
- {
- $total = strtolower(trim($str_capacity));
- $last = $total[-1];
- $total = intval($total);
- if($last == 't') {
- $per = 1024 * 1024 * 1024 * 1024;
- }
- elseif($last == 'g') {
- $per = 1024 * 1024 * 1024;
- }
- elseif($last == 'm') {
- $per = 1024 * 1024;
- }
- elseif($last == 'k') {
- $per = 1024;
- }
- else {
- $per = 1;
- }
- return $total * $per;
- };
- $format_detail = function ($detail) use ($calc_bytes)
- {
- $detail = trim($detail);
- $items = explode(',',$detail);
- if(count($items) < 2) {
- return $detail;
- }
- $total = strtolower(trim($items[0]));
- $avaliable = strtolower(trim($items[1]));
- $ratio = $calc_bytes($avaliable) / $calc_bytes($total);
- $ratio = number_format($ratio * 100,2);
- return "$avaliable / $total = $ratio%";
- };
- $disk_monitoring_data = function ($str) use ($convert_time,$format_detail)
- {
- $result = [];
- $details = preg_split("/[\s#]+/", $str, 0, PREG_SPLIT_DELIM_CAPTURE);
- foreach ($details as $item)
- {
- $data = explode(':', $item);
- if(count($data) != 2) continue;
- $dir = trim($data[0]);
- if($dir == 'cur_time') {
- $val = $convert_time(trim($data[1]));
- } else {
- $val = $format_detail($data[1]);
- }
- $result[$dir] = $val;
- }
- return $result;
- };
- $details = $disk_monitoring_data($str);
- $cur_time = $convert_time('2023-08-24-16-08-02');
- $arr = "/mnt:7.3T,5.7T";
- $data = preg_split("/[\s:]+/", $arr, 0, PREG_SPLIT_DELIM_CAPTURE);
- $key = ltrim($data[0], '/');
- $value = $data[1];
- // global $config;
- // $servers = $config['server'];
- // $ins = Cache::getInstance('cacheredis');
- // $name = 'disk_monitor';
- // $disk_monitoring_data = $ins->hget($name, '');
- // $result = [];
- // $cur_time = time();
- // $ago_time = 0;
- //
- // array_map(function ($ip, $server_name) use($disk_monitoring_data) {
- // $hash_str = $disk_monitoring_data[$ip];
- // $item = [];
- // if(!empty($hash_str)){
- // $hash_str = str_replace('\t', "", $hash_str);
- // $arrs = explode('#', $hash_str);
- // }
- // }, $servers);
- }
- }
- //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAccount::testLog)( .*)?$/" --test-suffix TestAccount.php /var/www/html/test
|