Пример #1
0
 //创建新进程用于采集数据
 $int_pid = pcntl_fork();
 if ($int_pid === false) {
     //进程创建失败
     Baserror::loger("任务子进程[{$server['name']}]创建失败.");
 } elseif ($int_pid != 0) {
     //父进程返回
     $arr_pids[] = $int_pid;
 } else {
     //重定向错误控制
     //Baserror::loger("任务子进程[{$server['name']}]创建成功.");
     Baserror::set('CLI', PATH_LOG, "deamon-woker[{$server['name']}].log", DEAMON_LOG_SHOW, DEAMON_LOG_FILE);
     //子进程,开始采集工作,获取服务器数据.
     if ($obj_dt->fetch($server['url'])) {
         //创建写数据对象
         $obj_dber = new Bkex_Dber($server);
         if ($obj_dber === false) {
             Baserror::loger("Dber can't start!");
             exit;
         }
         //获取信息
         $arr_cpu = $obj_dt->cpu();
         $arr_mem = $obj_dt->mem();
         $arr_disk = $obj_dt->disk();
         $arr_load = $obj_dt->load();
         $arr_network = $obj_dt->network();
         $obj_dber->log_cpu($arr_cpu);
         $obj_dber->log_mem($arr_mem);
         $obj_dber->log_disk($arr_disk);
         $obj_dber->log_load($arr_load);
         $obj_dber->log_network($arr_network);
Пример #2
0
        $obj_dber->log_cpu($arr_cpu);
        $obj_dber->log_mem($arr_mem);
        $obj_dber->log_disk($arr_disk);
        $obj_dber->log_load($arr_load);
        $obj_dber->log_network($arr_network);
        //重新定义时间段
        $get_time_end = time();
        $get_time_start = time() - $get_lay_time * 60;
        //获取目标数据
        $arr_json['data']['cpu'] = $obj_charts->cpu($obj_dber->rt_get_cpu($get_time_start, $get_time_end, 30));
        $arr_json['data']['mem'] = $obj_charts->mem($obj_dber->rt_get_mem($get_time_start, $get_time_end, 30));
        $arr_json['data']['load'] = $obj_charts->load($obj_dber->rt_get_load($get_time_start, $get_time_end, 30));
        $arr_json['data']['disk'] = $obj_charts->disk($obj_dber->rt_get_disk($arr_system['disk'], $get_time_start, $get_time_end, 30));
        $arr_json['data']['network'] = $obj_charts->network($obj_dber->rt_get_network($arr_system['network'], $get_time_start, $get_time_end, 30));
        $arr_json['target'] = $get_host;
        $arr_json['status'] = true;
    } else {
        //日志模式
        $obj_dber = new Bkex_Dber($arr_server);
        //获取目标数据
        $arr_json['data']['cpu'] = $obj_charts->cpu($obj_dber->log_get_cpu($get_time_start, $get_time_end, 60));
        $arr_json['data']['mem'] = $obj_charts->mem($obj_dber->log_get_mem($get_time_start, $get_time_end, 60));
        $arr_json['data']['load'] = $obj_charts->load($obj_dber->log_get_load($get_time_start, $get_time_end, 60));
        $arr_json['data']['disk'] = $obj_charts->disk($obj_dber->log_get_disk($arr_system['disk'], $get_time_start, $get_time_end, 60));
        $arr_json['data']['network'] = $obj_charts->network($obj_dber->log_get_network($arr_system['network'], $get_time_start, $get_time_end, 60));
        $arr_json['target'] = $get_host;
        $arr_json['status'] = true;
    }
}
//打印结果集
echo json_encode($arr_json);