Detailed improvements on Server Health page in CP

This commit is contained in:
Pinga 2025-01-28 12:47:35 +02:00
parent a4d7a9064e
commit bb050b170e
2 changed files with 167 additions and 18 deletions

View file

@ -111,6 +111,37 @@ class ReportsController extends Controller
$csrfTokenName = $this->container->get('csrf')->getTokenName();
$csrfTokenValue = $this->container->get('csrf')->getTokenValue();
// Helper function to check service status
$checkServiceStatus = function ($serviceName) {
$output = @shell_exec("service $serviceName status");
return ($output && strpos($output, 'active (running)') !== false) ? 'Running' : 'Stopped';
};
// Helper function to read the last 50 lines of a log file and convert to string
$getLogLines = function ($logPrefix) {
$currentDate = date('Y-m-d');
$logFile = "/var/log/namingo/{$logPrefix}-$currentDate.log";
if (file_exists($logFile)) {
$output = @shell_exec("tail -n 50 " . escapeshellarg($logFile));
return $output ? $output : "Log file is empty.";
}
return "Log file not found: $logFile";
};
// Check statuses
$eppStatus = $checkServiceStatus('epp');
$whoisStatus = $checkServiceStatus('whois');
$rdapStatus = $checkServiceStatus('rdap');
$dasStatus = $checkServiceStatus('das');
// Get log lines as strings
$eppLogs = $getLogLines('epp');
$whoisLogs = $getLogLines('whois');
$rdapLogs = $getLogLines('rdap');
$dasLogs = $getLogLines('das');
$system = new System();
$serverHealth = [
@ -167,6 +198,14 @@ class ReportsController extends Controller
'csrfTokenName' => $csrfTokenName,
'csrfTokenValue' => $csrfTokenValue,
'backupLog' => nl2br(htmlspecialchars($backupSummary)),
'eppStatus' => $eppStatus,
'whoisStatus' => $whoisStatus,
'rdapStatus' => $rdapStatus,
'dasStatus' => $dasStatus,
'eppLogs' => $eppLogs,
'whoisLogs' => $whoisLogs,
'rdapLogs' => $rdapLogs,
'dasLogs' => $dasLogs,
]);
}

View file

@ -36,13 +36,12 @@
<!-- Page body -->
<div class="page-body">
<div class="container-xl">
<div class="col-12">
<div class="row">
<!-- CPU and Memory Card -->
<div class="col-md-6">
<div class="row row-cards">
<!-- CPU Card -->
<div class="col-md-4">
<div class="card">
<div class="card-header">
<h3 class="card-title">{{ __('CPU and Memory') }}</h3>
<h3 class="card-title">{{ __('CPU Usage') }}</h3>
</div>
<div class="card-body">
<div class="d-flex align-items-center mb-3">
@ -59,10 +58,18 @@
{{ serverHealth.getCPUUsage }}%
</div>
</div>
</div>
</div>
</div>
<hr>
<div class="d-flex align-items-center">
<!-- Memory Card -->
<div class="col-md-4">
<div class="card">
<div class="card-header">
<h3 class="card-title">{{ __('Memory Usage') }}</h3>
</div>
<div class="card-body">
<div class="d-flex align-items-center mb-3">
<div>
<h4 class="m-0">{{ __('Memory') }}</h4>
<div class="text-muted">{{ serverHealth.getMemoryFree }} {{ __('MB free of') }} {{ serverHealth.getMemoryTotal }} MB</div>
@ -80,16 +87,16 @@
</div>
</div>
<!-- Disk and Network Card -->
<div class="col-md-6 mt-md-0 mt-2">
<!-- Disk Card -->
<div class="col-md-4">
<div class="card">
<div class="card-header">
<h3 class="card-title">{{ __('Disk and Network') }}</h3>
<h3 class="card-title">{{ __('Disk Usage') }}</h3>
</div>
<div class="card-body">
<div class="d-flex align-items-center mb-3">
<div>
<h4 class="m-0">{{ __('Disk Usage') }}</h4>
<h4 class="m-0">{{ __('Disk') }}</h4>
<div class="text-muted">{{ serverHealth.getDiskFree }} {{ __('GB free of') }} {{ serverHealth.getDiskTotal }} GB</div>
</div>
<div class="ms-auto">
@ -104,17 +111,120 @@
</div>
</div>
</div>
<!-- EPP Card -->
<div class="col-md-3">
<div class="card">
<div class="card-body">
<div class="d-flex align-items-center">
<div class="subheader me-2">{{ __('EPP Server') }}:</div>
<span class="status {{ eppStatus == 'Running' ? 'status-green' : 'status-red' }}">
<span class="status-dot status-dot-animated"></span>
{{ eppStatus == 'Running' ? __('Running') : __('Stopped') }}
</span>
</div>
</div>
</div>
</div>
<!-- RDAP Card -->
<div class="col-md-3">
<div class="card">
<div class="card-body">
<div class="d-flex align-items-center">
<div class="subheader me-2">{{ __('RDAP Server') }}:</div>
<span class="status {{ rdapStatus == 'Running' ? 'status-green' : 'status-red' }}">
<span class="status-dot status-dot-animated"></span>
{{ rdapStatus == 'Running' ? __('Running') : __('Stopped') }}
</span>
</div>
</div>
</div>
</div>
<!-- WHOIS Card -->
<div class="col-md-3">
<div class="card">
<div class="card-body">
<div class="d-flex align-items-center">
<div class="subheader me-2">{{ __('WHOIS Server') }}:</div>
<span class="status {{ whoisStatus == 'Running' ? 'status-green' : 'status-red' }}">
<span class="status-dot status-dot-animated"></span>
{{ whoisStatus == 'Running' ? __('Running') : __('Stopped') }}
</span>
</div>
</div>
</div>
</div>
<!-- DAS Card -->
<div class="col-md-3">
<div class="card">
<div class="card-body">
<div class="d-flex align-items-center">
<div class="subheader me-2">{{ __('DAS Server') }}:</div>
<span class="status {{ dasStatus == 'Running' ? 'status-green' : 'status-red' }}">
<span class="status-dot status-dot-animated"></span>
{{ dasStatus == 'Running' ? __('Running') : __('Stopped') }}
</span>
</div>
</div>
</div>
</div>
<div class="row mt-2">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<p>
{{ __('If you encounter an issue with a specific service, log in via SSH and run the appropriate command to reload it:') }} <code>service epp restart</code>, <code>service whois restart</code>, <code>service rdap restart</code>, <code>service das restart</code>
</p>
<p class="text-muted">
{{ __('If you need assistance, please contact support.') }}
</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3 class="card-title">{{ __('EPP Log') }}</h3>
</div>
<div class="card-body">
<pre style="white-space: pre-wrap;">{{ eppLogs|raw }}</pre>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3 class="card-title">{{ __('WHOIS Log') }}</h3>
</div>
<div class="card-body">
<pre style="white-space: pre-wrap;">{{ whoisLogs|raw }}</pre>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3 class="card-title">{{ __('RDAP Log') }}</h3>
</div>
<div class="card-body">
<pre style="white-space: pre-wrap;">{{ rdapLogs|raw }}</pre>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3 class="card-title">{{ __('Backup Log') }}</h3>
</div>
<div class="card-body">
<pre>{{ backupLog|raw }}</pre>
</div>
<pre style="white-space: pre-wrap;">{{ backupLog|raw }}</pre>
</div>
</div>
</div>