-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from neighborhoods/feature/KOJO-137
Feature/KOJO-137 | Add host information to Metadata, and memory info to process
- Loading branch information
Showing
10 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata; | ||
|
||
class Host implements HostInterface | ||
{ | ||
const KEY_HOST_NAME = 'host_name'; | ||
const KEY_LOAD_AVERAGE = 'load_average'; | ||
|
||
/** @var string */ | ||
protected $host_name; | ||
/** @var float */ | ||
protected $load_average; | ||
|
||
public function getHostName() : string | ||
{ | ||
return gethostname(); | ||
} | ||
|
||
public function getLoadAverage() : float | ||
{ | ||
return (float)current(sys_getloadavg()); | ||
} | ||
|
||
public function jsonSerialize() | ||
{ | ||
$data = get_object_vars($this); | ||
$data[self::KEY_HOST_NAME] = $this->getHostName(); | ||
$data[self::KEY_LOAD_AVERAGE] = $this->getLoadAverage(); | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
services: | ||
neighborhoods.kojo.neighborhoods.kojo.src.process.pool.logger.message.metadata.host: | ||
class: Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata\Host | ||
shared: true |
54 changes: 54 additions & 0 deletions
54
src/Process/Pool/Logger/Message/Metadata/Host/AwareTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata\Host; | ||
|
||
use Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata\HostInterface; | ||
|
||
/** @codeCoverageIgnore */ | ||
trait AwareTrait | ||
{ | ||
protected $NeighborhoodsKojoProcessPoolLoggerMessageMetadataHost; | ||
|
||
public function setProcessPoolLoggerMessageMetadataHost( | ||
HostInterface $ProcessPoolLoggerMessageMetadataHost | ||
) : self | ||
{ | ||
if ($this->hasProcessPoolLoggerMessageMetadataHost()) { | ||
throw new \LogicException( | ||
'NeighborhoodsKojoProcessPoolLoggerMessageMetadataHost is already set.' | ||
); | ||
} | ||
$this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHost = $ProcessPoolLoggerMessageMetadataHost; | ||
|
||
return $this; | ||
} | ||
|
||
protected function getProcessPoolLoggerMessageMetadataHost() : HostInterface | ||
{ | ||
if (!$this->hasProcessPoolLoggerMessageMetadataHost()) { | ||
throw new \LogicException( | ||
'NeighborhoodsKojoProcessPoolLoggerMessageMetadataHost is not set.' | ||
); | ||
} | ||
|
||
return $this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHost; | ||
} | ||
|
||
protected function hasProcessPoolLoggerMessageMetadataHost() : bool | ||
{ | ||
return isset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHost); | ||
} | ||
|
||
protected function unsetProcessPoolLoggerMessageMetadataHost() : self | ||
{ | ||
if (!$this->hasProcessPoolLoggerMessageMetadataHost()) { | ||
throw new \LogicException( | ||
'NeighborhoodsKojoProcessPoolLoggerMessageMetadataHost is not set.' | ||
); | ||
} | ||
unset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHost); | ||
|
||
return $this; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Process/Pool/Logger/Message/Metadata/HostInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata; | ||
|
||
interface HostInterface extends \JsonSerializable | ||
{ | ||
public function getHostName() : string; | ||
|
||
public function getLoadAverage() : float; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters