Skip to content

Commit c32d7af

Browse files
committed
Create process monitor page #1
1 parent 7a60612 commit c32d7af

File tree

8 files changed

+167
-41
lines changed

8 files changed

+167
-41
lines changed

app/Filament/Pages/Monitor.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace App\Filament\Pages;
4+
5+
use Filament\Pages\Page;
6+
use Illuminate\Contracts\View\View;
7+
use Livewire\Attributes\On;
8+
9+
class Monitor extends Page
10+
{
11+
protected static ?string $navigationIcon = 'heroicon-c-tv';
12+
13+
protected static string $view = 'filament.pages.monitor';
14+
15+
public array $psaux = [];
16+
17+
protected function getHeaderWidgets(): array
18+
{
19+
// $this->dispatch('page-monitor');
20+
return [];
21+
}
22+
23+
public function getHeaderWidgetsColumns(): int | array
24+
{
25+
return 2;
26+
}
27+
28+
private function convertTimeToSeconds($time)
29+
{
30+
$parts = explode(':', $time);
31+
$seconds = 0;
32+
if (count($parts) == 3) {
33+
$seconds = ($parts[0] * 3600) + ($parts[1] * 60) + $parts[2];
34+
} elseif (count($parts) == 2) {
35+
$seconds = ($parts[0] * 60) + $parts[1];
36+
}
37+
return $seconds;
38+
}
39+
40+
public function monitor()
41+
{
42+
// Executa o comando ps com os parâmetros para obter as informações desejadas
43+
$output = [];
44+
$command = "ps aux | grep -v grep";
45+
exec($command, $output);
46+
47+
// Processa a saída do comando para extrair as informações necessárias
48+
$processes = [];
49+
foreach ($output as $line) {
50+
$columns = preg_split('/\s+/', $line);
51+
52+
if (count($columns) >= 11) {
53+
$processes[] = (object)[
54+
'pid' => $columns[1],
55+
'user' => $columns[0],
56+
'cpu' => $columns[2],
57+
'mem' => $columns[3],
58+
'command' => array_reverse(explode('/', $columns[10]))[0],
59+
'time' => $this->convertTimeToSeconds($columns[9]),
60+
];
61+
}
62+
}
63+
64+
return collect($processes);
65+
}
66+
67+
#[On('load-monitor')]
68+
public function monitorProcessor()
69+
{
70+
$monitorContent = $this->monitor();
71+
$this->psaux = $monitorContent->values()->toArray();
72+
}
73+
74+
public function render(): View
75+
{
76+
$this->dispatch('load-monitor');
77+
return view(static::$view)
78+
->layout($this->getLayout(), [
79+
'livewire' => $this,
80+
'maxContentWidth' => $this->getMaxContentWidth(),
81+
...$this->getLayoutData(),
82+
]);
83+
}
84+
}

public/build/assets/theme-ByeJgAuq.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/build/assets/theme-Dr3m3iRM.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"isEntry": true
66
},
77
"resources/css/filament/manager/theme.css": {
8-
"file": "assets/theme-ByeJgAuq.css",
8+
"file": "assets/theme-Dr3m3iRM.css",
99
"src": "resources/css/filament/manager/theme.css",
1010
"isEntry": true
1111
},

public/js/core/core.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
document.addEventListener('livewire:init', () => {
99
console.log('core loaded');
1010
Livewire.on('page-process-details', (event) => {
11-
console.log(event);
1211
Livewire.dispatch('determine-command-type', {command: event.record.command});
1312
});
13+
14+
Livewire.on('page-monitor', (event) => {
15+
Livewire.dispatch('load-monitor');
16+
});
1417
});
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import preset from '../../../../vendor/filament/filament/tailwind.config.preset'
22

33
export default {
4-
presets: [preset],
4+
presets: [
5+
preset,
6+
require(__dirname + "/../../../../vendor/wireui/wireui/tailwind.config.js"),
7+
],
58
content: [
69
'./app/Filament/**/*.php',
710
'./resources/views/filament/**/*.blade.php',
811
'./vendor/filament/**/*.blade.php',
12+
"./vendor/wireui/wireui/src/*.php",
13+
"./vendor/wireui/wireui/ts/**/*.ts",
14+
"./vendor/wireui/wireui/src/WireUi/**/*.php",
15+
"./vendor/wireui/wireui/src/Components/**/*.php",
916
],
1017
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<x-filament-panels::page>
2+
<x-card title="PS AUX | 5s uptime" style="overflow: auto; width: 100%;">
3+
<div style="display: flex; width: 100%; position: relative; flex-wrap: wrap;">
4+
@foreach ($psaux as $item)
5+
<div
6+
style="display: flex; justify-content: space-between; width: 100%; border: dashed 2px; height: 40px; padding: 5px; border-radius: 5px; font-size: 20px; margin-bottom: 5px; position: relative;">
7+
<span style="diplay: flex; justify-conntent: start;">
8+
{{ $item->pid }}
9+
</span>
10+
<span style="diplay: flex; justify-conntent: start;">
11+
{{ $item->user }}
12+
</span>
13+
<span style="diplay: flex; justify-conntent: start;">
14+
{{ $item->cpu }}
15+
</span>
16+
<span style="diplay: flex; justify-conntent: start;">
17+
{{ $item->mem }}
18+
</span>
19+
<span style="diplay: flex; justify-conntent: start;">
20+
{{ $item->command }}
21+
</span>
22+
<span style="diplay: flex; justify-conntent: start;">
23+
{{ $item->time }}
24+
</span>
25+
</div>
26+
@endforeach
27+
</div>
28+
</x-card>
29+
</x-filament-panels::page>

resources/views/filament/resources/service-proccess-resource/pages/service-details.blade.php

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -77,44 +77,47 @@
7777
</div>
7878
</div>
7979
@if ($record->logs()->count() > 0)
80-
<table class="fi-ta-table w-full table-auto divide-y divide-gray-200 text-start dark:divide-white/5 "
81-
style="border-radius: 5px;">
82-
<thead class="divide-y divide-gray-200 dark:divide-white/5">
83-
<tr class="bg-gray-50 dark:bg-white/5">
84-
<th scope="col"
85-
class="fi-ta-header-cell px-3 py-3.5 sm:first-of-type:ps-6 sm:last-of-type:pe-6 fi-table-header-cell-command">
86-
Date/time</th>
87-
<th scope="col"
88-
class="fi-ta-header-cell px-3 py-3.5 sm:first-of-type:ps-6 sm:last-of-type:pe-6 fi-table-header-cell-command">
89-
output</th>
90-
<th scope="col"
91-
class="fi-ta-header-cell px-3 py-3.5 sm:first-of-type:ps-6 sm:last-of-type:pe-6 fi-table-header-cell-command">
92-
service</th>
93-
</tr>
94-
</thead>
95-
<tbody class="divide-y divide-gray-200 whitespace-nowrap dark:divide-white/5">
96-
@foreach ($record->logs()->get() as $item)
97-
<tr
98-
class="fi-ta-row [@media(hover:hover)]:transition [@media(hover:hover)]:duration-75 hover:bg-gray-50 dark:hover:bg-white/5">
99-
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-id"
100-
style="text-align: center;">
101-
{{ date('d/m/Y', strtotime($item->created_at)) }}
102-
</td>
103-
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-id"
104-
style="text-align: center;">
105-
@if (strlen($item->output) > 30)
106-
{{ substr($item->output, 0, 29) }}...
107-
@else
108-
{{ item->output }}
109-
@endif
110-
</td>
111-
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-id" style="text-align: center;">
112-
{{ $item->command }}
113-
</td>
80+
<div style="overflow: auto;">
81+
<table class="fi-ta-table w-full table-auto divide-y divide-gray-200 text-start dark:divide-white/5 "
82+
style="border-radius: 5px;">
83+
<thead class="divide-y divide-gray-200 dark:divide-white/5">
84+
<tr class="bg-gray-50 dark:bg-white/5">
85+
<th scope="col"
86+
class="fi-ta-header-cell px-3 py-3.5 sm:first-of-type:ps-6 sm:last-of-type:pe-6 fi-table-header-cell-command">
87+
Date/time</th>
88+
<th scope="col"
89+
class="fi-ta-header-cell px-3 py-3.5 sm:first-of-type:ps-6 sm:last-of-type:pe-6 fi-table-header-cell-command">
90+
output</th>
91+
<th scope="col"
92+
class="fi-ta-header-cell px-3 py-3.5 sm:first-of-type:ps-6 sm:last-of-type:pe-6 fi-table-header-cell-command">
93+
service</th>
11494
</tr>
115-
@endforeach
116-
</tbody>
117-
</table>
95+
</thead>
96+
<tbody class="divide-y divide-gray-200 whitespace-nowrap dark:divide-white/5">
97+
@foreach ($record->logs()->get() as $item)
98+
<tr
99+
class="fi-ta-row [@media(hover:hover)]:transition [@media(hover:hover)]:duration-75 hover:bg-gray-50 dark:hover:bg-white/5">
100+
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-id"
101+
style="text-align: center;">
102+
{{ date('d/m/Y', strtotime($item->created_at)) }}
103+
</td>
104+
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-id"
105+
style="text-align: center;">
106+
@if (strlen($item->output) > 100)
107+
{{ substr($item->output, 0, 99) }}...
108+
@else
109+
{{ item->output }}
110+
@endif
111+
</td>
112+
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-id"
113+
style="text-align: center;">
114+
{{ $item->command }}
115+
</td>
116+
</tr>
117+
@endforeach
118+
</tbody>
119+
</table>
120+
</div>
118121
@else
119122
<h1 style="margin: auto; font-size: 30px; display: flex;">
120123
<x-heroicon-s-information-circle style="width: 30px; margin-right: 10px;" /> No logs for this command

0 commit comments

Comments
 (0)