-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MemoryUsage: new Monitoring Rule Definition
fixes #406
- Loading branch information
1 parent
934f6d6
commit 06880c2
Showing
10 changed files
with
250 additions
and
4 deletions.
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
53 changes: 53 additions & 0 deletions
53
library/Vspheredb/Daemon/RpcNamespace/RpcNamespaceProcess.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,53 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Vspheredb\Daemon\RpcNamespace; | ||
|
||
use Evenement\EventEmitterInterface; | ||
use Evenement\EventEmitterTrait; | ||
use React\EventLoop\LoopInterface; | ||
|
||
class RpcNamespaceProcess implements EventEmitterInterface | ||
{ | ||
use EventEmitterTrait; | ||
|
||
const ON_RESTART = 'restart'; | ||
|
||
/** @var LoopInterface */ | ||
protected $loop; | ||
|
||
public function __construct(LoopInterface $loop) | ||
{ | ||
$this->loop = $loop; | ||
} | ||
|
||
/* | ||
public function infoRequest() | ||
{ | ||
return $this->prepareProcessInfo($this->daemon); | ||
} | ||
protected function prepareProcessInfo(Daemon $daemon) | ||
{ | ||
$details = $this->daemon->getProcessDetails()->getPropertiesToInsert(); | ||
$details['process_info'] = \json_decode($details['process_info']); | ||
return (object) [ | ||
'state' => $this->daemon->getProcessState()->getInfo(), | ||
'details' => (object) $details, | ||
]; | ||
} | ||
*/ | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function restartRequest() | ||
{ | ||
// Grant some time to ship the response | ||
$this->loop->addTimer(0.1, function () { | ||
$this->emit(self::ON_RESTART); | ||
}); | ||
|
||
return true; | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
library/Vspheredb/Monitoring/Rule/Definition/ActiveMemoryUsageRuleDefinition.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,28 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Vspheredb\Monitoring\Rule\Definition; | ||
|
||
use Icinga\Module\Vspheredb\DbObject\BaseDbObject; | ||
use Icinga\Module\Vspheredb\Monitoring\Rule\Enum\ObjectType; | ||
|
||
class ActiveMemoryUsageRuleDefinition extends MemoryUsageRuleDefinition | ||
{ | ||
public const SUPPORTED_OBJECT_TYPES = [ | ||
ObjectType::VIRTUAL_MACHINE, | ||
]; | ||
|
||
public static function getIdentifier(): string | ||
{ | ||
return 'ActiveMemoryUsage'; | ||
} | ||
|
||
public function getLabel(): string | ||
{ | ||
return $this->translate('Active Memory Usage'); | ||
} | ||
|
||
protected function getUsedMemory(BaseDbObject $quickStats) | ||
{ | ||
return $quickStats->get('guest_memory_usage_mb') * MemoryUsageHelper::MEGA_BYTE; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
library/Vspheredb/Monitoring/Rule/Definition/ComputeResourceUsageRuleSet.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,21 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Vspheredb\Monitoring\Rule\Definition; | ||
|
||
class ComputeResourceUsageRuleSet extends MonitoringRuleSetDefinition | ||
{ | ||
public const RULE_CLASSES = [ | ||
MemoryUsageRuleDefinition::class, | ||
ActiveMemoryUsageRuleDefinition::class, | ||
]; | ||
|
||
public function getLabel(): string | ||
{ | ||
return $this->translate('Compute Resource Usage'); | ||
} | ||
|
||
public static function getIdentifier(): string | ||
{ | ||
return 'ComputeResourceUsage'; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
library/Vspheredb/Monitoring/Rule/Definition/MemoryUsageRuleDefinition.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,69 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Vspheredb\Monitoring\Rule\Definition; | ||
|
||
use Icinga\Module\Vspheredb\DbObject\BaseDbObject; | ||
use Icinga\Module\Vspheredb\DbObject\HostQuickStats; | ||
use Icinga\Module\Vspheredb\DbObject\HostSystem; | ||
use Icinga\Module\Vspheredb\DbObject\VirtualMachine; | ||
use Icinga\Module\Vspheredb\DbObject\VmQuickStats; | ||
use Icinga\Module\Vspheredb\Monitoring\Rule\Enum\ObjectType; | ||
use Icinga\Module\Vspheredb\Monitoring\Rule\Settings; | ||
|
||
class MemoryUsageRuleDefinition extends MonitoringRuleDefinition | ||
{ | ||
public const SUPPORTED_OBJECT_TYPES = [ | ||
ObjectType::HOST_SYSTEM, | ||
ObjectType::VIRTUAL_MACHINE, | ||
]; | ||
|
||
public static function getIdentifier(): string | ||
{ | ||
return 'MemoryUsage'; | ||
} | ||
|
||
public function getLabel(): string | ||
{ | ||
return $this->translate('Memory Usage'); | ||
} | ||
|
||
public function getInternalDefaults(): array | ||
{ | ||
return [ | ||
'threshold_precedence' => 'best_wins' | ||
]; | ||
} | ||
|
||
protected function getUsedMemory(BaseDbObject $quickStats) | ||
{ | ||
if ($quickStats instanceof VmQuickStats) { | ||
return $quickStats->get('host_memory_usage_mb') * MemoryUsageHelper::MEGA_BYTE; | ||
} | ||
|
||
return $quickStats->get('overall_memory_usage_mb') * MemoryUsageHelper::MEGA_BYTE; | ||
} | ||
|
||
public function checkObject(BaseDbObject $object, Settings $settings): array | ||
{ | ||
$this->assertSupportedObject($object); | ||
if ($object instanceof HostSystem) { | ||
$quickStats = HostQuickStats::loadFor($object); | ||
$capacity = $object->get('hardware_memory_size_mb') * MemoryUsageHelper::MEGA_BYTE; | ||
} elseif ($object instanceof VirtualMachine) { | ||
$quickStats = VmQuickStats::loadFor($object); | ||
$capacity = $object->get('hardware_memorymb') * MemoryUsageHelper::MEGA_BYTE; | ||
} else { | ||
throw new \InvalidArgumentException('Cannot load QuickStats for ' . get_class($object)); | ||
} | ||
$used = $this->getUsedMemory($quickStats); | ||
$free = $capacity - $used; | ||
return [ | ||
MemoryUsageHelper::prepareState($settings, $free, $capacity) | ||
]; | ||
} | ||
|
||
public function getParameters(): array | ||
{ | ||
return MemoryUsageHelper::getParameters(); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Vspheredb\Web\Form; | ||
|
||
use gipfl\IcingaWeb2\Icon; | ||
use gipfl\Translation\TranslationHelper; | ||
use gipfl\Web\Form\Feature\NextConfirmCancel; | ||
use gipfl\Web\InlineForm; | ||
use Icinga\Module\Vspheredb\Daemon\RemoteClient; | ||
use React\EventLoop\LoopInterface; | ||
use function Clue\React\Block\await; | ||
|
||
class RestartDaemonForm extends InlineForm | ||
{ | ||
use TranslationHelper; | ||
|
||
/** @var RemoteClient */ | ||
protected $client; | ||
|
||
/** @var LoopInterface */ | ||
protected $loop; | ||
|
||
public function __construct(RemoteClient $client, LoopInterface $loop) | ||
{ | ||
$this->client = $client; | ||
$this->loop = $loop; | ||
} | ||
|
||
protected function assemble() | ||
{ | ||
(new NextConfirmCancel( | ||
NextConfirmCancel::buttonNext($this->translate('Restart'), [ | ||
'title' => $this->translate('Click to restart the vSphereDB background daemon'), | ||
]), | ||
NextConfirmCancel::buttonConfirm($this->translate('Yes, please restart')), | ||
NextConfirmCancel::buttonCancel($this->translate('Cancel')) | ||
))->addToForm($this); | ||
} | ||
|
||
protected function onSuccess() | ||
{ | ||
await($this->client->request('process.restart'), $this->loop); | ||
} | ||
} |