You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/resources/views/venix/admin/cloud/system_logs.tpl

56 lines
10 KiB
Smarty

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{assign var=admin_title value='系统日志'}
{assign var=admin_active value='system-logs'}
{include file='admin/static_header.tpl'}
<link rel="stylesheet" href="/cloud/admin-system-logs.css?v={$venix_asset_version}">
{if !$system_logs_page}
{assign var=system_logs_page value=['items'=>[],'units'=>[],'summary'=>['total'=>0,'error_count'=>0,'warning_count'=>0,'latest_at'=>''],'filters'=>['unit'=>'','priority'=>'','query'=>'','since'=>'','until'=>'','limit'=>100],'pagination'=>['next_cursor'=>'','has_more'=>false]]}
{/if}
{assign var=system_logs_filters value=$system_logs_page.filters|default:[]}
{assign var=system_logs_limit value=$system_logs_filters.limit|default:100}
<main data-admin-system-logs data-timezone="{$system_logs_timezone|default:'UTC'|escape}">
<div class="py-3 d-flex align-items-sm-center flex-sm-row flex-column gap-3">
<div class="flex-grow-1">
<p class="admin-eyebrow mb-1">Runtime observability</p>
<h1 class="fs-20 fw-semibold mb-1">系统日志</h1>
<p class="text-muted mb-0">读取面板所在主机的 Virt Cloud 和 libvirt journal 日志,支持按服务、级别、时间和关键词定位错误。查看日志不会执行宿主机操作。</p>
</div>
<div class="admin-checkout-actions">
<span class="admin-config-status {if $system_logs_error|default:''}is-error{else}is-success{/if}" id="system-logs-notice" role="status" aria-live="polite">{if $system_logs_error|default:''}{$system_logs_error|escape}{else}等待读取日志{/if}</span>
<button class="btn btn-light" id="system-logs-cancel" type="button" hidden>停止读取</button>
<button class="btn btn-light" id="system-logs-refresh" type="button"><i class="mdi mdi-refresh me-1" aria-hidden="true"></i>刷新</button>
</div>
</div>
<section class="row g-3 mb-3" aria-label="日志摘要">
<div class="col-6 col-xl-3"><article class="card admin-stat-card h-100"><div class="card-body"><div><h2 class="text-muted fs-14 fw-normal mb-1">当前日志</h2><strong class="admin-stat-value" id="system-logs-total">{$system_logs_page.summary.total|default:0|escape}</strong></div><span class="admin-stat-icon text-primary"><i class="mdi mdi-format-list-bulleted" aria-hidden="true"></i></span></div></article></div>
<div class="col-6 col-xl-3"><article class="card admin-stat-card h-100"><div class="card-body"><div><h2 class="text-muted fs-14 fw-normal mb-1">错误</h2><strong class="admin-stat-value text-danger" id="system-logs-errors">{$system_logs_page.summary.error_count|default:0|escape}</strong></div><span class="admin-stat-icon text-danger"><i class="mdi mdi-alert-circle-outline" aria-hidden="true"></i></span></div></article></div>
<div class="col-6 col-xl-3"><article class="card admin-stat-card h-100"><div class="card-body"><div><h2 class="text-muted fs-14 fw-normal mb-1">警告</h2><strong class="admin-stat-value text-warning" id="system-logs-warnings">{$system_logs_page.summary.warning_count|default:0|escape}</strong></div><span class="admin-stat-icon text-warning"><i class="mdi mdi-alert-outline" aria-hidden="true"></i></span></div></article></div>
<div class="col-6 col-xl-3"><article class="card admin-stat-card h-100"><div class="card-body"><div><h2 class="text-muted fs-14 fw-normal mb-1">最新时间</h2><strong class="admin-stat-value fs-14" id="system-logs-latest">{if $system_logs_page.summary.latest_at}{$system_logs_page.summary.latest_at|escape}{else}尚无记录{/if}</strong></div><span class="admin-stat-icon text-success"><i class="mdi mdi-clock-check-outline" aria-hidden="true"></i></span></div></article></div>
</section>
<section class="card mb-3" aria-labelledby="system-logs-filter-title">
<div class="card-header"><h2 class="h5 card-title mb-1" id="system-logs-filter-title">筛选日志</h2><p class="text-muted fs-13 mb-0">优先级遵循 journald:错误包含 emerg、alert、crit、err;日志内容来自受限的服务读取接口。</p></div>
<div class="card-body">
<form class="row g-2 align-items-end" id="system-logs-filter" method="get" action="/admin/system-logs">
<label class="col-xl-3 col-lg-4 col-md-6" for="system-logs-unit"><span class="form-label d-block">服务</span><select class="form-select" id="system-logs-unit" name="unit"><option value="">全部服务</option>{foreach $system_logs_page.units|default:[] as $unit}<option value="{$unit|escape}"{if $system_logs_filters.unit|default:'' == $unit} selected{/if}>{$unit|escape}</option>{/foreach}</select></label>
<label class="col-xl-2 col-lg-3 col-md-6" for="system-logs-priority"><span class="form-label d-block">级别</span><select class="form-select" id="system-logs-priority" name="priority"><option value="">全部级别</option><option value="error"{if $system_logs_filters.priority|default:'' == 'error'} selected{/if}>错误</option><option value="warning"{if $system_logs_filters.priority|default:'' == 'warning'} selected{/if}>警告</option><option value="notice"{if $system_logs_filters.priority|default:'' == 'notice'} selected{/if}>通知</option><option value="info"{if $system_logs_filters.priority|default:'' == 'info'} selected{/if}>信息</option><option value="debug"{if $system_logs_filters.priority|default:'' == 'debug'} selected{/if}>调试</option></select></label>
<label class="col-xl-3 col-lg-5 col-md-8" for="system-logs-query"><span class="form-label d-block">关键词</span><input class="form-control" id="system-logs-query" name="query" type="search" maxlength="120" value="{$system_logs_filters.query|default:''|escape}" placeholder="尝试编号、服务名、错误码或消息"></label>
<label class="col-xl-2 col-lg-3 col-md-4" for="system-logs-limit"><span class="form-label d-block">每次读取</span><select class="form-select" id="system-logs-limit" name="limit"><option value="50">50 条</option><option value="100"{if $system_logs_limit == 100} selected{/if}>100 条</option><option value="200"{if $system_logs_limit == 200} selected{/if}>200 条</option></select></label>
<div class="col-xl-2 col-lg-12 col-md-12 d-flex gap-2"><button class="btn btn-primary flex-grow-1" type="submit">应用筛选</button><a class="btn btn-light" href="/admin/system-logs">清除</a></div>
<div class="col-12"><details class="system-logs-advanced"><summary>时间范围</summary><div class="row g-2 mt-1"><label class="col-md-3" for="system-logs-since"><span class="form-label d-block">开始时间</span><input class="form-control" id="system-logs-since" name="since" type="datetime-local" value="{$system_logs_filters.since|default:''|escape}"></label><label class="col-md-3" for="system-logs-until"><span class="form-label d-block">结束时间</span><input class="form-control" id="system-logs-until" name="until" type="datetime-local" value="{$system_logs_filters.until|default:''|escape}"></label><span class="col-md-6 text-muted fs-13 system-logs-help">时间按 {$system_logs_timezone|default:'UTC'|escape} 解释;留空读取服务当前保留窗口。</span></div></details></div>
</form>
</div>
</section>
<section class="card" aria-labelledby="system-logs-list-title">
<div class="card-header d-flex justify-content-between align-items-center gap-2 flex-wrap"><div><h2 class="h5 card-title mb-1" id="system-logs-list-title">运行日志</h2><p class="text-muted fs-13 mb-0" id="system-logs-list-description">日志按最新时间倒序显示;点击一行或聚焦后按 Enter/空格可查看完整消息。</p></div><span class="badge text-bg-light" id="system-logs-count">共 {$system_logs_page.summary.total|default:0|escape} 条</span></div>
<div class="card-body"><div class="table-responsive system-logs-table-wrap"><table class="table table-hover align-middle mb-0 system-logs-table"><caption class="visually-hidden">系统 journal 运行日志</caption><thead><tr><th scope="col">时间</th><th scope="col">服务</th><th scope="col">级别</th><th scope="col">消息</th></tr></thead><tbody id="system-logs-body">{if !$system_logs_page.items}<tr><td colspan="4" class="text-center text-muted py-4">没有符合条件的日志</td></tr>{else}{foreach $system_logs_page.items as $item}<tr><td data-label="时间">{$item.timestamp|default:'时间未记录'|escape}</td><td data-label="服务">{$item.unit|default:'系统'|escape}</td><td data-label="级别">{$item.level|default:'信息'|escape}</td><td data-label="消息"><span class="system-logs-message">{$item.message|default:'消息未记录'|escape}</span></td></tr>{/foreach}{/if}</tbody></table></div><div class="system-logs-pagination"><button class="btn btn-light" id="system-logs-newer" type="button" disabled>更新日志</button><span id="system-logs-page-label">当前窗口</span><button class="btn btn-light" id="system-logs-older" type="button" disabled>加载更早日志</button></div></div>
</section>
<noscript><p class="alert alert-info mt-3">此页面需要启用 JavaScript 才能读取当前主机的 system journal;日志不会在无脚本模式下加载。</p></noscript>
</main>
<dialog data-admin-instance-drawer id="system-logs-detail" aria-labelledby="system-logs-detail-title"><header class="admin-instance-drawer-header"><div><p class="text-muted fs-13 mb-1">日志详情</p><h2 class="h4 fw-semibold mb-0" id="system-logs-detail-title">运行日志</h2></div><button class="admin-modal-close position-static flex-shrink-0" id="system-logs-detail-close" type="button" aria-label="关闭日志详情" autofocus><i class="mdi mdi-close" aria-hidden="true"></i></button></header><div class="admin-instance-drawer-body"><div id="system-logs-detail-state" class="alert alert-info mb-3" role="status" aria-live="polite" hidden></div><dl class="admin-instance-details" id="system-logs-detail-meta"></dl><h3 class="h6 mt-4 mb-2">Journal 字段</h3><dl class="admin-instance-details" id="system-logs-detail-fields"></dl><pre class="system-logs-detail-message" id="system-logs-detail-message"></pre></div></dialog>
<script id="admin-system-logs-bootstrap" type="application/json">{$system_logs_bootstrap_json|default:'null' nofilter}</script>
<script>window.__VENIX_SYSTEM_LOGS__ = { apiUrl: '/api/v1/admin/system-logs', timezone: '{$system_logs_timezone|default:'UTC'|escape:"javascript"}' };</script>
<script type="module" src="/cloud/admin-system-logs.js?v={$venix_asset_version}"></script>
{include file='admin/static_footer.tpl'}