Skip to content

Commit

Permalink
Merge pull request #105 from Icinga/metric-graphs-for-workloads
Browse files Browse the repository at this point in the history
Add metric charts for workloads
  • Loading branch information
lippserd authored Dec 18, 2024
2 parents 51170da + 2ce18c8 commit 18d0858
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 248 deletions.
446 changes: 254 additions & 192 deletions library/Kubernetes/Common/Metrics.php

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions library/Kubernetes/Web/DaemonSetDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace Icinga\Module\Kubernetes\Web;

use DateInterval;
use DateTime;
use Icinga\Module\Kubernetes\Common\Auth;
use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Common\Format;
use Icinga\Module\Kubernetes\Common\Metrics;
use Icinga\Module\Kubernetes\Common\ResourceDetails;
use Icinga\Module\Kubernetes\Model\DaemonSet;
use Icinga\Module\Kubernetes\Model\DaemonSetCondition;
Expand Down Expand Up @@ -39,6 +42,14 @@ public function __construct(DaemonSet $daemonSet)
protected function assemble(): void
{
$this->addHtml(
new DetailMetricCharts(
Metrics::daemonSetMetrics(
(new DateTime())->sub(new DateInterval('PT12H')),
$this->daemonSet->uuid,
Metrics::POD_CPU_USAGE,
Metrics::POD_MEMORY_USAGE,
)
),
new Details(new ResourceDetails($this->daemonSet, [
$this->translate('Min Ready Duration') => (new HtmlDocument())->addHtml(
new Icon('stopwatch'),
Expand Down
11 changes: 11 additions & 0 deletions library/Kubernetes/Web/DeploymentDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace Icinga\Module\Kubernetes\Web;

use DateInterval;
use DateTime;
use Icinga\Module\Kubernetes\Common\Auth;
use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Common\Format;
use Icinga\Module\Kubernetes\Common\Metrics;
use Icinga\Module\Kubernetes\Common\ResourceDetails;
use Icinga\Module\Kubernetes\Model\Deployment;
use Icinga\Module\Kubernetes\Model\Event;
Expand Down Expand Up @@ -38,6 +41,14 @@ public function __construct(Deployment $deployment)
protected function assemble(): void
{
$this->addHtml(
new DetailMetricCharts(
Metrics::deploymentMetrics(
(new DateTime())->sub(new DateInterval('PT12H')),
$this->deployment->uuid,
Metrics::POD_CPU_USAGE,
Metrics::POD_MEMORY_USAGE,
)
),
new Details(new ResourceDetails($this->deployment, [
$this->translate('Min Ready Duration') => (new HtmlDocument())->addHtml(
new Icon('stopwatch'),
Expand Down
45 changes: 45 additions & 0 deletions library/Kubernetes/Web/DetailMetricCharts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/* Icinga for Kubernetes Web | (c) 2024 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\Metrics;
use ipl\Html\BaseHtmlElement;

class DetailMetricCharts extends BaseHtmlElement
{
protected $metrics;

protected $tag = 'section';

public function __construct(array $metrics)
{
$this->metrics = $metrics;
}

protected function assemble(): void
{
$metricRow = [];
if (isset($this->metrics[Metrics::NODE_CPU_USAGE])) {
$metricRow[] = new LineChart(
'chart-medium',
implode(', ', $this->metrics[Metrics::NODE_CPU_USAGE]),
implode(', ', array_keys($this->metrics[Metrics::NODE_CPU_USAGE])),
'CPU Usage',
Metrics::COLOR_CPU
);
}
if (isset($this->metrics[Metrics::NODE_MEMORY_USAGE])) {
$metricRow[] = new LineChart(
'chart-medium',
implode(', ', $this->metrics[Metrics::NODE_MEMORY_USAGE]),
implode(', ', array_keys($this->metrics[Metrics::NODE_MEMORY_USAGE])),
'Memory Usage',
Metrics::COLOR_MEMORY
);
}

$this->addHtml(new MetricCharts($metricRow));
}
}
35 changes: 8 additions & 27 deletions library/Kubernetes/Web/NodeDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,15 @@ public function __construct(Node $node)

protected function assemble(): void
{
$metrics = new Metrics(Database::connection());
$nodeMetricsPeriod = $metrics->getNodeMetrics(
(new DateTime())->sub(new DateInterval('PT12H')),
$this->node->uuid,
Metrics::NODE_CPU_USAGE,
Metrics::NODE_MEMORY_USAGE
);
$metricRow = [];
if (isset($nodeMetricsPeriod[Metrics::NODE_CPU_USAGE])) {
$metricRow[] = new LineChart(
'chart-medium',
implode(', ', $nodeMetricsPeriod[Metrics::NODE_CPU_USAGE]),
implode(', ', array_keys($nodeMetricsPeriod[Metrics::NODE_CPU_USAGE])),
'CPU Usage',
Metrics::COLOR_CPU
);
}
if (isset($nodeMetricsPeriod[Metrics::NODE_MEMORY_USAGE])) {
$metricRow[] = new LineChart(
'chart-medium',
implode(', ', $nodeMetricsPeriod[Metrics::NODE_MEMORY_USAGE]),
implode(', ', array_keys($nodeMetricsPeriod[Metrics::NODE_MEMORY_USAGE])),
'Memory Usage',
Metrics::COLOR_MEMORY
);
}
$this->addHtml(
new MetricCharts($metricRow),
new DetailMetricCharts(
Metrics::nodeMetrics(
(new DateTime())->sub(new DateInterval('PT12H')),
$this->node->uuid,
Metrics::NODE_CPU_USAGE,
Metrics::NODE_MEMORY_USAGE
)
),
new Details([
$this->translate('Name') => $this->node->name,
$this->translate('UID') => $this->node->uid,
Expand Down
38 changes: 9 additions & 29 deletions library/Kubernetes/Web/PodDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,15 @@ protected function assemble(): void
$containerRestarts += $container->restart_count;
}

$metrics = new Metrics(Database::connection());
$podMetricsPeriod = $metrics->getPodMetrics(
(new DateTime())->sub(new DateInterval('PT12H')),
$this->pod->uuid,
Metrics::POD_CPU_USAGE,
Metrics::POD_MEMORY_USAGE
);
$metricRow = [];
if (isset($podMetricsPeriod[Metrics::POD_CPU_USAGE])) {
$metricRow[] = new LineChart(
'chart-medium',
implode(', ', $podMetricsPeriod[Metrics::POD_CPU_USAGE]),
implode(', ', array_keys($podMetricsPeriod[Metrics::POD_CPU_USAGE])),
'CPU Usage',
Metrics::COLOR_CPU
);
}
if (isset($podMetricsPeriod[Metrics::POD_MEMORY_USAGE])) {
$metricRow[] = new LineChart(
'chart-medium',
implode(', ', $podMetricsPeriod[Metrics::POD_MEMORY_USAGE]),
implode(', ', array_keys($podMetricsPeriod[Metrics::POD_MEMORY_USAGE])),
'Memory Usage',
Metrics::COLOR_MEMORY
);
}

$this->addHtml(
new MetricCharts($metricRow),
new DetailMetricCharts(
Metrics::podMetrics(
(new DateTime())->sub(new DateInterval('PT12H')),
$this->pod->uuid,
Metrics::POD_CPU_USAGE,
Metrics::POD_MEMORY_USAGE
)
),
new Details(new ResourceDetails($this->pod, [
$this->translate('IP') => $this->pod->ip ??
new EmptyState($this->translate('None')),
Expand All @@ -93,7 +73,7 @@ protected function assemble(): void
new Icon('recycle'),
new Text($this->pod->restart_policy)
),
$this->translate('Quality of Service') => (new HtmlDocument())->addHtml(
$this->translate('Quality of Service') => (new HtmlDocument())->addHtml(
new Icon('life-ring'),
new Text($this->pod->qos)
),
Expand Down
11 changes: 11 additions & 0 deletions library/Kubernetes/Web/ReplicaSetDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace Icinga\Module\Kubernetes\Web;

use DateInterval;
use DateTime;
use Icinga\Module\Kubernetes\Common\Auth;
use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Common\Format;
use Icinga\Module\Kubernetes\Common\Metrics;
use Icinga\Module\Kubernetes\Common\ResourceDetails;
use Icinga\Module\Kubernetes\Model\Event;
use Icinga\Module\Kubernetes\Model\ReplicaSet;
Expand Down Expand Up @@ -38,6 +41,14 @@ public function __construct(ReplicaSet $replicaSet)
protected function assemble(): void
{
$this->addHtml(
new DetailMetricCharts(
Metrics::replicaSetMetrics(
(new DateTime())->sub(new DateInterval('PT12H')),
$this->replicaSet->uuid,
Metrics::POD_CPU_USAGE,
Metrics::POD_MEMORY_USAGE,
)
),
new Details(new ResourceDetails($this->replicaSet, [
$this->translate('Min Ready Duration') => (new HtmlDocument())->addHtml(
new Icon('stopwatch'),
Expand Down
11 changes: 11 additions & 0 deletions library/Kubernetes/Web/StatefulSetDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace Icinga\Module\Kubernetes\Web;

use DateInterval;
use DateTime;
use Icinga\Module\Kubernetes\Common\Auth;
use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Common\Format;
use Icinga\Module\Kubernetes\Common\Metrics;
use Icinga\Module\Kubernetes\Common\ResourceDetails;
use Icinga\Module\Kubernetes\Model\Event;
use Icinga\Module\Kubernetes\Model\StatefulSet;
Expand Down Expand Up @@ -39,6 +42,14 @@ public function __construct(StatefulSet $statefulSet)
protected function assemble(): void
{
$this->addHtml(
new DetailMetricCharts(
Metrics::statefulSetMetrics(
(new DateTime())->sub(new DateInterval('PT12H')),
$this->statefulSet->uuid,
Metrics::POD_CPU_USAGE,
Metrics::POD_MEMORY_USAGE,
)
),
new Details(new ResourceDetails($this->statefulSet, [
$this->translate('Min Ready Duration') => (new HtmlDocument())->addHtml(
new Icon('stopwatch'),
Expand Down

0 comments on commit 18d0858

Please sign in to comment.