Files
server-manager/views/servers/processes.php

107 lines
4.6 KiB
PHP

<?php
$server = $server ?? [];
$processList = $processList ?? [];
?>
<div class="page-header">
<div class="page-header-left">
<div class="back-link">
<a href="/servers/<?= $server['id'] ?>"><i class="fas fa-arrow-left"></i> Back to Server</a>
</div>
<h1 class="page-title">Processes</h1>
<p class="page-subtitle">
<?= htmlspecialchars($server['name']) ?>
&middot; <?= count($processList) ?> processes
</p>
</div>
<div class="page-header-right">
<button class="btn btn-secondary" onclick="location.reload()">
<i class="fas fa-sync-alt"></i> Refresh
</button>
</div>
</div>
<div class="card">
<div class="card-body">
<?php if (empty($processList)): ?>
<div class="empty-state">
<i class="fas fa-microchip empty-icon"></i>
<p>No process data available.</p>
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table table-hover table-sm" id="processTable">
<thead>
<tr>
<th>PID</th>
<th>User</th>
<th>CPU %</th>
<th>MEM %</th>
<th>RSS</th>
<th>STAT</th>
<th>Time</th>
<th>Command</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($processList as $p): ?>
<tr>
<td class="font-mono"><?= $p['pid'] ?></td>
<td><?= htmlspecialchars($p['user']) ?></td>
<td>
<span class="badge <?= $p['cpu'] > 50 ? 'badge-danger' : ($p['cpu'] > 10 ? 'badge-warning' : 'badge-info') ?>">
<?= number_format($p['cpu'], 1) ?>%
</span>
</td>
<td><?= number_format($p['mem'], 1) ?>%</td>
<td class="font-mono"><?= format_bytes($p['rss'] * 1024) ?></td>
<td><code><?= htmlspecialchars($p['stat']) ?></code></td>
<td class="font-mono"><?= htmlspecialchars($p['time']) ?></td>
<td class="cell-command" title="<?= htmlspecialchars($p['command']) ?>">
<code><?= htmlspecialchars(mb_substr($p['command'], 0, 60)) ?><?= mb_strlen($p['command']) > 60 ? '...' : '' ?></code>
</td>
<td>
<button class="btn btn-xs btn-danger" onclick="killProcess(<?= $p['pid'] ?>, this)"
title="Kill process <?= $p['pid'] ?>">
<i class="fas fa-times"></i> Kill
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
<div id="killModal" class="modal">
<div class="modal-dialog">
<div class="modal-header">
<h3><i class="fas fa-exclamation-triangle text-danger"></i> Kill Process</h3>
<button class="modal-close" onclick="closeKillModal()">&times;</button>
</div>
<div class="modal-body">
<p>Are you sure you want to terminate process <strong id="killPidDisplay"></strong>?</p>
<div class="form-group" style="margin-top: 1rem;">
<label class="checkbox-label">
<input type="checkbox" id="killForce">
<span>Force kill (SIGKILL -9) if process does not respond</span>
</label>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" onclick="closeKillModal()">Cancel</button>
<button class="btn btn-danger" id="confirmKillBtn" onclick="confirmKill()">
<i class="fas fa-times"></i> Terminate
</button>
</div>
</div>
</div>
<script>
const serverId = <?= $server['id'] ?>;
</script>
<script src="/assets/js/server-processes.js?v=<?= asset_version() ?>"></script>