trafficmonitor init...2
This commit is contained in:
parent
c9848db6f7
commit
ce9f4bd52c
@ -9,4 +9,24 @@ class CollectorEntity extends CommonEntity
|
|||||||
const PK = CollectorModel::PK;
|
const PK = CollectorModel::PK;
|
||||||
const TITLE = CollectorModel::TITLE;
|
const TITLE = CollectorModel::TITLE;
|
||||||
//기본기능용
|
//기본기능용
|
||||||
|
public function getTrafficInfoUID(): int
|
||||||
|
{
|
||||||
|
return $this->attributes['trafficinfo_uid'];
|
||||||
|
}
|
||||||
|
public function getIn(): int
|
||||||
|
{
|
||||||
|
return $this->attributes['in'];
|
||||||
|
}
|
||||||
|
public function getOut(): int
|
||||||
|
{
|
||||||
|
return $this->attributes['out'];
|
||||||
|
}
|
||||||
|
public function getRawIn(): int
|
||||||
|
{
|
||||||
|
return $this->attributes['raw_in'];
|
||||||
|
}
|
||||||
|
public function getRawOut(): int
|
||||||
|
{
|
||||||
|
return $this->attributes['raw_out'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,4 +26,12 @@ class CollectorModel extends CommonModel
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLastEntity($uid): CollectorEntity
|
||||||
|
{
|
||||||
|
return $this
|
||||||
|
->where('trafficinfo_uid', $uid)
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->first(); // 첫 번째 레코드(=가장 최신)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -108,18 +108,18 @@ class CollectorService extends CommonService
|
|||||||
log_message('warning', $message);
|
log_message('warning', $message);
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
// 이전 데이터를 조회하여 Rate 계산에 사용 (trafficModel 사용)
|
// 이전 데이터를 조회하여 Rate 계산에 사용
|
||||||
$lastEntry = $this->model->getLastEntryByInfoUid($trafficEntity->getPK());
|
$lastEntity = $this->model->getLastEntity($trafficEntity->getPK());
|
||||||
$inKbitsSec = 0.0;
|
$inKbitsSec = 0.0;
|
||||||
$outKbitsSec = 0.0;
|
$outKbitsSec = 0.0;
|
||||||
// 이전 데이터가 있어야만 Rate 계산 가능
|
// 이전 데이터가 있어야만 Rate 계산 가능
|
||||||
if ($lastEntry !== null) {
|
if ($lastEntity !== null) {
|
||||||
$lastTime = Time::parse($lastEntry['created_at'])->getTimestamp();
|
$lastTime = Time::parse($lastEntity->getCreatedAt())->getTimestamp();
|
||||||
$deltaTime = Time::now()->getTimestamp() - $lastTime;
|
$deltaTime = Time::now()->getTimestamp() - $lastTime;
|
||||||
if ($deltaTime > 0) {
|
if ($deltaTime > 0) {
|
||||||
// Raw Octets 값의 차분 계산
|
// Raw Octets 값의 차분 계산
|
||||||
$deltaInOctets = $currentInOctets - $lastEntry['raw_in_octets'];
|
$deltaInOctets = $currentInOctets - $lastEntity->getRawIn();
|
||||||
$deltaOutOctets = $currentOutOctets - $lastEntry['raw_out_octets'];
|
$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;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user