diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 5492e9d..7612846 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -52,6 +52,8 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->post('batchjob', 'TrafficController::batchjob'); $routes->post('batchjob_delete', 'TrafficController::batchjob_delete'); $routes->get('download/(:alpha)', 'TrafficController::download/$1'); + $routes->get('dashboard', 'TrafficController::dashboard'); + $routes->post('data', 'TrafficController::getAggregatedData'); }); $routes->group('collector', ['namespace' => 'App\Controllers\Admin'], function ($routes) { $routes->get('/', 'CollectorController::index'); diff --git a/app/Controllers/Admin/TrafficController.php b/app/Controllers/Admin/TrafficController.php index ccd198c..3af54e6 100644 --- a/app/Controllers/Admin/TrafficController.php +++ b/app/Controllers/Admin/TrafficController.php @@ -25,7 +25,7 @@ class TrafficController extends AdminController } protected function action_init_process(string $action): void { - $fields = ['client', 'server', 'switch', 'server_ip', 'interface', 'ip', 'status']; + $fields = ['client', 'server', 'switch', 'server_ip', 'interface', 'ip', 'status']; $filters = ['status']; switch ($action) { case 'create': @@ -71,4 +71,46 @@ class TrafficController extends AdminController { return parent::view_process($uid); } + public function dashboard(): string + { + $this->action_init_process(__FUNCTION__); + return $this->action_render_process($this->getActionPaths(), __FUNCTION__, $this->getViewDatas()); + } + /** + * AJAX 요청을 처리하고, 모델에서 집계된 데이터를 JSON 형식으로 반환합니다. + */ + public function getAggregatedData(): ResponseInterface + { + $uid = $this->request->getPost('uid'); + $entity = $this->service->getEntity($uid); + if (!$entity instanceof TrafficEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생:{$uid}에 해당하는 트래픽정보를 찾을수없습니다."); + } + $startDate = $this->request->getPost('startDate'); + $endDate = $this->request->getPost('endDate'); + // 입력값 검증 (실제 프로덕션에서는 반드시 수행해야 함) + if (empty($startDate) || empty($endDate)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => 'error', + 'message' => '필수 파라미터(날짜 또는 집계 기준)가 누락되었습니다.', + ]); + } + try { + // 모델 로드 및 데이터 조회 + $collectorService = service('collectorservice'); + $data = $collectorService->getAggregated($entity, $startDate, $endDate); + // 데이터를 JSON 형식으로 반환 + return $this->response->setJSON([ + 'status' => 'success', + 'data' => $data // 이 데이터는 이제 사용자가 제공한 필드 구조를 가집니다. + ]); + } catch (\Exception $e) { + // 예외 처리 + log_message('error', 'Traffic data aggregation error: ' . $e->getMessage()); + return $this->response->setStatusCode(500)->setJSON([ + 'status' => 'error', + 'message' => '데이터 처리 중 서버 오류가 발생했습니다.', + ]); + } + } } diff --git a/app/Services/CollectorService.php b/app/Services/CollectorService.php index f0a21c8..6646051 100644 --- a/app/Services/CollectorService.php +++ b/app/Services/CollectorService.php @@ -76,6 +76,10 @@ class CollectorService extends CommonService $this->model->orLike($this->model->getTable() . "." . $this->model->getTitleField(), $word, 'both'); parent::setSearchWord($word); } + //Chart용 + public function getAggregated(TrafficEntity $trafficEntity, string $startDate, string $endDate) { + d + } //SNMP연결 private function getSNMPOctets(TrafficEntity $trafficEntity, string $oid): ?int { diff --git a/app/Views/templates/admin/traffic/dashboard.php b/app/Views/templates/admin/traffic/dashboard.php new file mode 100644 index 0000000..d00ef70 --- /dev/null +++ b/app/Views/templates/admin/traffic/dashboard.php @@ -0,0 +1,331 @@ + + + + + + + <?= $title ?? '대시보드' ?> + + + + + + + + + + +
+
+

+

기간 및 집계 기준을 선택하여 트래픽 추이를 확인하세요.

+
+ + +
+
+

데이터 조회 설정

+
+ +
+ + +
+ + +
+ + +
+ + +
+ +
+ + + + +
+
+
+ + +
+
+ + +
+
+ +

트래픽 속도 추이 (Kbit/s)

+ +

+ + + + + +
+ +
+
+
+
+ + + + + + + + \ No newline at end of file