trafficmonitor init...2

This commit is contained in:
choi.jh 2025-11-12 15:15:17 +09:00
parent e1f2ddbfa3
commit a821014573

View File

@ -110,8 +110,8 @@ class CollectorService extends CommonService
} }
// 이전 데이터를 조회하여 Rate 계산에 사용 // 이전 데이터를 조회하여 Rate 계산에 사용
$lastEntity = $this->model->getLastEntity($trafficEntity->getPK()); $lastEntity = $this->model->getLastEntity($trafficEntity->getPK());
$inKbitsSec = 0.0; $inKbitsSec = 0;
$outKbitsSec = 0.0; $outKbitsSec = 0;
// 이전 데이터가 있어야만 Rate 계산 가능 // 이전 데이터가 있어야만 Rate 계산 가능
if ($lastEntity !== null) { if ($lastEntity !== null) {
$lastTime = Time::parse($lastEntity->getCreatedAt())->getTimestamp(); $lastTime = Time::parse($lastEntity->getCreatedAt())->getTimestamp();
@ -120,7 +120,6 @@ class CollectorService extends CommonService
// Raw Octets 값의 차분 계산 // Raw Octets 값의 차분 계산
$deltaInOctets = $currentInOctets - $lastEntity->getRawIn(); $deltaInOctets = $currentInOctets - $lastEntity->getRawIn();
$deltaOutOctets = $currentOutOctets - $lastEntity->getRawOut(); $deltaOutOctets = $currentOutOctets - $lastEntity->getRawOut();
// Kbit/s 계산: (Delta_Octets * 8 bits) / Delta_Time_Seconds / 1000 (-> Kbit/s) // Kbit/s 계산: (Delta_Octets * 8 bits) / Delta_Time_Seconds / 1000 (-> Kbit/s)
$inKbitsSec = ($deltaInOctets * 8) / $deltaTime / 1000; $inKbitsSec = ($deltaInOctets * 8) / $deltaTime / 1000;
$outKbitsSec = ($deltaOutOctets * 8) / $deltaTime / 1000; $outKbitsSec = ($deltaOutOctets * 8) / $deltaTime / 1000;
@ -131,8 +130,8 @@ class CollectorService extends CommonService
// DB에 저장할 데이터를 배열로 반환 // DB에 저장할 데이터를 배열로 반환
return [ return [
'trafficinfo_uid' => $trafficEntity->getPK(), 'trafficinfo_uid' => $trafficEntity->getPK(),
'in' => round($inKbitsSec, 2), 'in' => $inKbitsSec,
'out' => round($outKbitsSec, 2), 'out' => $outKbitsSec,
'raw_in' => $currentInOctets, 'raw_in' => $currentInOctets,
'raw_out' => $currentOutOctets, 'raw_out' => $currentOutOctets,
]; ];