Skip to content

Commit e5dc945

Browse files
committed
feat: #206 display usage graphs for nodes
1 parent 2798fa9 commit e5dc945

File tree

11 files changed

+770
-132
lines changed

11 files changed

+770
-132
lines changed

Diff for: app/Http/Controllers/NodeController.php

+40-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Models\Node;
99
use App\Models\NodeTaskGroupType;
1010
use App\Models\Service;
11+
use App\Services\Metrics;
1112
use Illuminate\Http\Request;
1213
use Illuminate\Support\Facades\DB;
1314
use Inertia\Inertia;
@@ -21,9 +22,23 @@ public function index()
2122
{
2223
$nodes = Node::all();
2324

25+
$query = <<<'QUERY'
26+
union(
27+
alias(round(rate(ptah_node_cpu_user + ptah_node_cpu_system) / rate(ptah_node_cpu_total) * 100), "cpu_usage"),
28+
alias(round(ptah_node_memory_used_bytes / ptah_node_memory_total_bytes * 100), "memory_usage"),
29+
alias(round(ptah_node_disk_used_bytes{path="/"} / ptah_node_disk_total_bytes{path="/"} * 100), "disk_usage"),
30+
round({__name__=~"ptah_node_load_avg_(1|5|15)m"}, 0.01),
31+
)
32+
QUERY;
33+
34+
$nodeIds = $nodes->pluck('id')->toArray();
35+
36+
$metrics = Metrics::getMetrics($query, $nodeIds);
37+
2438
return Inertia::render('Nodes/Index', [
2539
'nodes' => $nodes,
2640
'nodesLimitReached' => auth()->user()->currentTeam->quotas()->nodes->quotaReached(),
41+
'metrics' => $metrics,
2742
]);
2843
}
2944

@@ -58,10 +73,33 @@ public function store(StoreNodeRequest $request)
5873
return to_route('nodes.show', ['node' => $node->id]);
5974
}
6075

76+
public function show(Node $node)
77+
{
78+
$query = <<<'QUERY'
79+
union(
80+
alias(round(rate(ptah_node_cpu_user + ptah_node_cpu_system) / rate(ptah_node_cpu_total) * 100), "cpu_usage"),
81+
alias(round(ptah_node_memory_used_bytes / ptah_node_memory_total_bytes * 100), "memory_usage"),
82+
alias(round(ptah_node_swap_used_bytes / ptah_node_swap_total_bytes * 100), "swap_usage"),
83+
alias(round(ptah_node_disk_used_bytes{path="/"} / ptah_node_disk_total_bytes{path="/"} * 100), "disk_usage"),
84+
alias(round(rate(ptah_node_network_rx_bytes / 1024)), "network_rx_bytes"),
85+
alias(round(rate(ptah_node_network_tx_bytes / 1024)), "network_tx_bytes"),
86+
alias(round(increase(ptah_caddy_http_requests_count)), "http_requests_count"),
87+
alias(sum(increase(ptah_caddy_http_requests_duration_bucket)) by (le), "http_requests_duration"),
88+
)
89+
QUERY;
90+
91+
$metrics = Metrics::getMetricsRange($query, [$node->id]);
92+
93+
return Inertia::render('Nodes/Show', [
94+
'node' => $node,
95+
'metrics' => $metrics,
96+
]);
97+
}
98+
6199
/**
62100
* Display the specified resource.
63101
*/
64-
public function show(Node $node)
102+
public function settings(Node $node)
65103
{
66104
$initTaskGroup = $node->actualTaskGroup(NodeTaskGroupType::InitSwarm);
67105
if ($initTaskGroup?->is_completed) {
@@ -89,7 +127,7 @@ public function show(Node $node)
89127
$registryTaskGroup = null;
90128
}
91129

92-
return Inertia::render('Nodes/Show', [
130+
return Inertia::render('Nodes/Settings', [
93131
'node' => $node,
94132
'isLastNode' => $node->team->nodes->count() === 1,
95133
'initTaskGroup' => $initTaskGroup ?: $joinTaskGroup,

Diff for: package-lock.json

+114-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
"vue": "^3.3.13"
2828
},
2929
"dependencies": {
30+
"apexcharts": "^3.54.0",
3031
"dayjs": "^1.11.11",
3132
"handlebars": "^4.7.8",
3233
"lodash.set": "^4.3.2",
33-
"swrv": "^1.0.4"
34+
"swrv": "^1.0.4",
35+
"vue3-apexcharts": "^1.6.0"
3436
},
3537
"lint-staged": {
3638
"*.{js,vue,css,md,json}": "prettier --write",

Diff for: resources/js/Components/Card.vue

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
<script setup>
2+
import { defineProps } from "vue";
3+
4+
defineProps({
5+
title: {
6+
type: String,
7+
default: "",
8+
},
9+
});
10+
</script>
11+
112
<template>
213
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg p-6">
14+
<h2 class="text-lg font-bold mb-4">{{ title }}</h2>
15+
316
<slot></slot>
417
</div>
518
</template>

0 commit comments

Comments
 (0)