Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions library/Vspheredb/Monitoring/Rule/MonitoringRulesTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,27 @@ public function hasConfigurationForUuid(string $uuid): bool
public function getInheritedSettingsFor(BaseDbObject $object): InheritedSettings
{
$uuid = $object->object()->get('parent_uuid');
$parents = [$uuid, ...$this->listParentUuidsFor($uuid)];

return InheritedSettings::loadForUuids($parents, $this, $this->db);
return InheritedSettings::loadForUuids(
$this->listInheritedParentUuidsFor($uuid),
$this,
$this->db
);
}

/**
* @param string|int|null $uuid
* @return string[]
*/
protected function listInheritedParentUuidsFor(string|int|null $uuid): array
{
if ($uuid === null || $uuid === 0) {
return [MonitoringRuleSet::NO_OBJECT];
}

$uuid = (string) $uuid;

return [$uuid, ...$this->listParentUuidsFor($uuid)];
}

/**
Expand Down
29 changes: 23 additions & 6 deletions library/Vspheredb/Web/Table/VmDiskUsageTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public function renderRow($row)
$this->root = $row;
}

$free = Format::bytes($row->free_space)
. sprintf(' (%0.3f%%)', ($row->free_space / $row->capacity) * 100);

$tr = $this::tr([
$this::td($caption, [
'title' => $caption
]),
$this::td(Format::bytes($row->capacity), ['class' => 'vm-disk-usage-capacity']),
$this::td($free, ['class' => 'vm-disk-usage-free']),
$this::td(
$this->renderFreeSpace($row->free_space, $row->capacity),
['class' => 'vm-disk-usage-free']
),
$this::td($this->makeDisk($row), ['class' => 'vm-disk-usage-usage'])
]);

Expand Down Expand Up @@ -133,11 +133,13 @@ protected function fetchRows()
return;
}

$free = Format::bytes($this->totalFree) . sprintf(' (%0.3f%%)', ($this->totalFree / $this->totalSize) * 100);
$this->getFooter()->add($this::tr([
$this::th(Html::tag('strong', null, $this->translate('Total'))),
$this::th(Format::bytes($this->totalSize), ['class' => 'vm-disk-usage-capacity']),
$this::th($free, ['class' => 'vm-disk-usage-free']),
$this::th(
$this->renderFreeSpace($this->totalFree, $this->totalSize),
['class' => 'vm-disk-usage-free']
),
$this::th($this->makeDisk((object) [
'disk_path' => $this->translate('Total'),
'capacity' => $this->totalSize,
Expand All @@ -158,6 +160,21 @@ protected function makeDisk($disk)
return new SimpleUsageBar($used, $disk->capacity, $disk->disk_path);
}

/**
* @param int|float $freeSpace
* @param int|float $capacity
* @return string Formatted free space with percentage, or "(n/a)" when capacity is zero
*/
protected function renderFreeSpace(int|float $freeSpace, int|float $capacity): string
{
$free = Format::bytes($freeSpace);
if ($capacity > 0) {
return $free . sprintf(' (%0.3f%%)', ($freeSpace / $capacity) * 100);
}

return $free . ' (n/a)';
}

public function prepareQuery()
{
return $this->db()->select()->from(
Expand Down
14 changes: 13 additions & 1 deletion library/Vspheredb/Web/Widget/SimpleUsageBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct($used, $total, $title)

protected function assemble()
{
$usedPercent = $this->used / $this->total;
$usedPercent = $this->getUsedPercent();

$bar = Html::tag('span', [
'href' => '#',
Expand All @@ -50,4 +50,16 @@ protected function assemble()

$this->add([$bar, $style]);
}

/**
* @return float Used fraction in [0, 1]; returns 0.0 when total is zero
*/
protected function getUsedPercent(): float
{
if ($this->total > 0) {
return $this->used / $this->total;
}

return 0.0;
}
}
Loading