From 506890535e384f3dc0ba101eedd1b080778a135b Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Thu, 13 Nov 2025 14:10:00 +0900 Subject: [PATCH] trafficmonitor init...1 --- app/Controllers/Admin/TrafficController.php | 5 +++-- app/Services/CollectorService.php | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Controllers/Admin/TrafficController.php b/app/Controllers/Admin/TrafficController.php index 3af54e6..eee1177 100644 --- a/app/Controllers/Admin/TrafficController.php +++ b/app/Controllers/Admin/TrafficController.php @@ -98,11 +98,12 @@ class TrafficController extends AdminController try { // 모델 로드 및 데이터 조회 $collectorService = service('collectorservice'); - $data = $collectorService->getAggregated($entity, $startDate, $endDate); + $aggregateDatas = $collectorService->getAggregateDatas($entity, $startDate, $endDate); // 데이터를 JSON 형식으로 반환 return $this->response->setJSON([ + 'message' => sprintf("[%s~%s] %s 트랙픽차트 ", $startDate, $endDate, $entity->getCustomTitle("%s[%s]", ['client', 'server_ip'])), 'status' => 'success', - 'data' => $data // 이 데이터는 이제 사용자가 제공한 필드 구조를 가집니다. + 'data' => $aggregateDatas // 이 데이터는 이제 사용자가 제공한 필드 구조를 가집니다. ]); } catch (\Exception $e) { // 예외 처리 diff --git a/app/Services/CollectorService.php b/app/Services/CollectorService.php index 6646051..3116089 100644 --- a/app/Services/CollectorService.php +++ b/app/Services/CollectorService.php @@ -77,8 +77,13 @@ class CollectorService extends CommonService parent::setSearchWord($word); } //Chart용 - public function getAggregated(TrafficEntity $trafficEntity, string $startDate, string $endDate) { - d + public function getAggregateDatas(TrafficEntity $trafficEntity, string $startDate, string $endDate): array + { + $entities = []; + foreach ($this->getEntities(["trafficinfo_uid" => $trafficEntity->getPK(), "created_at >=" => $startDate, "created_at <=" => $endDate]) as $entity) { + $entities[] = ['in_kbits' => $entity->getIn(), 'out_kbits' => $entity->getOut(), 'created_at' => $entity->getCreatedAt()]; + } + return $entities; } //SNMP연결 private function getSNMPOctets(TrafficEntity $trafficEntity, string $oid): ?int