public function draw($target_id) { /*取时间范围,获取数据,绘图*/ if (empty($this->chart['select_date'])) { $this->chart['select_date'][] = array('from' => date('Y-m-d H:i:s', time() - 86400)); } /*默认显示24h数据*/ if (!empty($this->chart['select_date'][0]['to'])) { $this->chart['select_date'][0]['to'] = date('Y-m-d', strtotime($this->chart['select_date'][0]['to']) + 86400); } if (!empty($this->chart['select_date'][1]['to'])) { $this->chart['select_date'][1]['to'] = date('Y-m-d', strtotime($this->chart['select_date'][1]['to']) + 86400); } $select_date = $this->chart['select_date'][0]; $this->init_chartData($this->init_data(get_status_log($this->pdo_log, 'idc10', '-1', $this->alert['target_type'], $this->alert['field'], $target_id, $this->alert['table'], 0, array('min' => $select_date['from'], 'max' => $select_date['to'])))); $this->graph['v' . $this->i] = array('title' => $this->get_title($this->alert['target_type'], $target_id), 'color' => $this->get_color($this->i)); $old_select_date = isset($this->chart['select_date'][1]) ? $this->chart['select_date'][1] : false; if (!empty($old_select_date)) { $intval = strtotime($select_date['from']) - strtotime($old_select_date['from']); $this->init_chartData($this->init_data(get_status_log($this->pdo_log, 'idc10', '-1', $this->alert['target_type'], $this->alert['field'], $target_id, $this->alert['table'], 0, array('min' => $old_select_date['from'], 'max' => $old_select_date['to'])), $intval)); $this->graph['v' . $this->i] = array('title' => $this->get_title($this->alert['target_type'], $target_id) . "old", 'color' => $this->get_color($this->i)); } }
} $json_mem_instance = stacked_bar_chart($host_instance_list); //load $load_logs = get_status_log($pdo_log, $cfg['idc'], $cfg['default_host'], 'host', 'loadaverage', $params['host_id'], 'status_log_host_loadaverage', 150); $load_logs_chart = build_chart_data($load_logs, false); $chart_load['title'] = "cpu load"; $chart_load['legend_y'] = "percent"; $chart_load['legend_x'] = ""; $chart_load['values'] = array($load_logs_chart['data']); $chart_load['values_key'] = array('load'); $chart_load['range_max'] = max($load_logs_chart['max'] + 0.5, 0.1); $chart_load['range_step'] = $chart_load['range_max'] / 10; $chart_load['show_step'] = 4; $json_load = create_chart_data($chart_load); //memory $memory_logs = get_status_log($pdo_log, $cfg['idc'], $cfg['default_host'], 'host', 'memoryused', $params['host_id'], 'status_log_host_memoryused', 150); if ($memory_logs) { foreach ($memory_logs as $k => $v) { $memory_logs[$k]['log_value'] = round($v['log_value'] / 1024, 2); } } $memory_logs_chart = build_chart_data($memory_logs, $host_memory * 0.9); $chart_mem['title'] = "memory used"; $chart_mem['legend_y'] = "used(GB)"; $chart_mem['legend_x'] = ""; $chart_mem['values'] = array($memory_logs_chart['data'], $memory_logs_chart['deadline']); $chart_mem['values_key'] = array('memory used', 'deadline'); $chart_mem['range_max'] = max($memory_logs_chart['max'] + 1, 0.1); $chart_mem['range_step'] = $chart_mem['range_max'] / 10; $chart_mem['show_step'] = 4; $json_mem = create_chart_data($chart_mem);