8
8
use App \Models \Node ;
9
9
use App \Models \NodeTaskGroupType ;
10
10
use App \Models \Service ;
11
+ use App \Services \Metrics ;
11
12
use Illuminate \Http \Request ;
12
13
use Illuminate \Support \Facades \DB ;
13
14
use Inertia \Inertia ;
@@ -21,9 +22,23 @@ public function index()
21
22
{
22
23
$ nodes = Node::all ();
23
24
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
+
24
38
return Inertia::render ('Nodes/Index ' , [
25
39
'nodes ' => $ nodes ,
26
40
'nodesLimitReached ' => auth ()->user ()->currentTeam ->quotas ()->nodes ->quotaReached (),
41
+ 'metrics ' => $ metrics ,
27
42
]);
28
43
}
29
44
@@ -58,10 +73,33 @@ public function store(StoreNodeRequest $request)
58
73
return to_route ('nodes.show ' , ['node ' => $ node ->id ]);
59
74
}
60
75
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
+
61
99
/**
62
100
* Display the specified resource.
63
101
*/
64
- public function show (Node $ node )
102
+ public function settings (Node $ node )
65
103
{
66
104
$ initTaskGroup = $ node ->actualTaskGroup (NodeTaskGroupType::InitSwarm);
67
105
if ($ initTaskGroup ?->is_completed) {
@@ -89,7 +127,7 @@ public function show(Node $node)
89
127
$ registryTaskGroup = null ;
90
128
}
91
129
92
- return Inertia::render ('Nodes/Show ' , [
130
+ return Inertia::render ('Nodes/Settings ' , [
93
131
'node ' => $ node ,
94
132
'isLastNode ' => $ node ->team ->nodes ->count () === 1 ,
95
133
'initTaskGroup ' => $ initTaskGroup ?: $ joinTaskGroup ,
0 commit comments