现在系统日志的发生时间列将以更直观、易识别的格式显示,提升了用户体验。

This commit is contained in:
Alex Yang
2025-12-05 00:10:42 +08:00
parent 52155cb77c
commit baeece18ef
4 changed files with 62 additions and 23 deletions

View File

@@ -363,7 +363,18 @@
<br>
<!-- 进程信息展示 -->
<div id="processInfoContainer" class="mt-8">
<h3 class="text-lg font-semibold text-gray-900 mb-4">进程信息</h3>
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold text-gray-900">进程信息</h3>
<div class="flex items-center gap-2">
<label for="processPageSize" class="text-sm text-gray-600">每页显示:</label>
<select id="processPageSize" class="px-2 py-1 border border-gray-300 rounded text-sm">
<option value="5">5条</option>
<option value="10">10条</option>
<option value="20">20条</option>
<option value="50">50条</option>
</select>
</div>
</div>
<div class="overflow-x-auto">
<table id="processTable" class="min-w-full bg-white rounded-lg overflow-hidden shadow-md">
<thead class="bg-gray-50">

View File

@@ -3090,6 +3090,16 @@ window.addEventListener('DOMContentLoaded', () => {
// 初始检查hash
handleHashChange();
// 为进程信息显示数量下拉框添加事件监听
const processPageSizeSelect = document.getElementById('processPageSize');
if (processPageSizeSelect) {
processPageSizeSelect.addEventListener('change', () => {
loadProcessInfo(1); // 重置为第一页
});
// 设置初始值
processPageSizeSelect.value = processPagination.itemsPerPage;
}
});
// 进程信息分页状态
@@ -3116,9 +3126,21 @@ let logPagination = {
async function loadProcessInfo(page = 1) {
const processTableBody = document.getElementById('processTableBody');
const processPaginationContainer = document.getElementById('processPaginationContainer');
const processPageSizeSelect = document.getElementById('processPageSize');
if (!processTableBody) return;
// 获取并设置每页显示数量
if (processPageSizeSelect) {
const selectedPageSize = parseInt(processPageSizeSelect.value, 10);
if (selectedPageSize !== processPagination.itemsPerPage) {
processPagination.itemsPerPage = selectedPageSize;
// 重置为第一页
page = 1;
processPagination.currentPage = 1;
}
}
try {
// 构建查询参数
const params = new URLSearchParams();
@@ -3476,6 +3498,33 @@ async function loadDiskDetails(page = 1) {
}
}
// 格式化时间为易识别的日期样式
function formatLogTime(timeString) {
if (!timeString) return new Date().toLocaleString('zh-CN');
try {
const date = new Date(timeString);
if (isNaN(date.getTime())) {
// 如果时间解析失败,返回原始字符串
return timeString;
}
// 格式化为2025-12-04 16:02:28
return date.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
});
} catch (error) {
console.error('Error formatting log time:', error);
return timeString;
}
}
// 加载系统日志
async function loadSystemLogs(page = 1) {
console.log('loadSystemLogs function called');
@@ -3553,7 +3602,7 @@ async function loadSystemLogs(page = 1) {
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${startIndex + index + 1}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 font-medium">${log.source || 'System'}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.time || new Date().toLocaleString()}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${formatLogTime(log.time)}</td>
<td class="px-6 py-4 whitespace-normal text-sm text-gray-500">${log.message || 'No message'}</td>
`;
logTableBody.appendChild(row);

View File

@@ -1,10 +0,0 @@
{
"server_url": "http://localhost:8080/api",
"id": "test-agent",
"name": "Test Agent",
"device_id": "test-device",
"token": "bb30bfaee01bf7b541bbefe422f72645",
"interval": "5s",
"debug": true,
"api_port": 8081
}

View File

@@ -1,11 +0,0 @@
#!/bin/bash
# 测试发送单个指标对象
echo "测试发送单个指标对象:"
curl -v -X POST -H "Content-Type: application/json" -H "X-Device-ID: test-device" -H "X-Agent-Name: test-agent" -H "X-Device-Token: test-token" -d '{"cpu": 50.5, "memory": 30.2, "disk": {":/": 45.6}, "network": {"eth0": {"bytes_sent": 1000, "bytes_received": 2000}}}' http://localhost:8080/api/metrics/
echo "\n---\n"
# 测试发送指标数组
echo "测试发送指标数组:"
curl -v -X POST -H "Content-Type: application/json" -H "X-Device-ID: test-device" -H "X-Agent-Name: test-agent" -H "X-Device-Token: test-token" -d '[{"cpu": 50.5, "memory": 30.2, "disk": {":/": 45.6}, "network": {"eth0": {"bytes_sent": 1000, "bytes_received": 2000}}}, {"cpu": 60.5, "memory": 40.2, "disk": {":/": 55.6}, "network": {"eth0": {"bytes_sent": 2000, "bytes_received": 3000}}}]' http://localhost:8080/api/metrics/