Introduce application uptime monitoring to improve observability and reliability. • Add UptimeService to track process start time and expose uptime in seconds • Create /health/uptime endpoint returning the current uptime in JSON format • Integrate uptime metric into existing health-check middleware • Update README with instructions for consuming the new endpoint • Add unit tests covering UptimeService and new health route This change enables operations teams and dashboards to programmatically determine how long the service has been running, facilitating automated alerts and trend analysis.
79 lines
2.1 KiB
JavaScript
79 lines
2.1 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import { Card, Spin } from '@douyinfe/semi-ui';
|
|
import { API, showError } from '../../helpers';
|
|
import SettingsAPIInfo from '../../pages/Setting/Dashboard/SettingsAPIInfo.js';
|
|
import SettingsAnnouncements from '../../pages/Setting/Dashboard/SettingsAnnouncements.js';
|
|
import SettingsFAQ from '../../pages/Setting/Dashboard/SettingsFAQ.js';
|
|
import SettingsUptimeKuma from '../../pages/Setting/Dashboard/SettingsUptimeKuma.js';
|
|
|
|
const DashboardSetting = () => {
|
|
let [inputs, setInputs] = useState({
|
|
ApiInfo: '',
|
|
Announcements: '',
|
|
FAQ: '',
|
|
UptimeKumaUrl: '',
|
|
UptimeKumaSlug: '',
|
|
});
|
|
|
|
let [loading, setLoading] = useState(false);
|
|
|
|
const getOptions = async () => {
|
|
const res = await API.get('/api/option/');
|
|
const { success, message, data } = res.data;
|
|
if (success) {
|
|
let newInputs = {};
|
|
data.forEach((item) => {
|
|
if (item.key in inputs) {
|
|
newInputs[item.key] = item.value;
|
|
}
|
|
});
|
|
setInputs(newInputs);
|
|
} else {
|
|
showError(message);
|
|
}
|
|
};
|
|
|
|
async function onRefresh() {
|
|
try {
|
|
setLoading(true);
|
|
await getOptions();
|
|
} catch (error) {
|
|
showError('刷新失败');
|
|
console.error(error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
onRefresh();
|
|
}, []);
|
|
|
|
return (
|
|
<>
|
|
<Spin spinning={loading} size='large'>
|
|
{/* API信息管理 */}
|
|
<Card style={{ marginTop: '10px' }}>
|
|
<SettingsAPIInfo options={inputs} refresh={onRefresh} />
|
|
</Card>
|
|
|
|
{/* 系统公告管理 */}
|
|
<Card style={{ marginTop: '10px' }}>
|
|
<SettingsAnnouncements options={inputs} refresh={onRefresh} />
|
|
</Card>
|
|
|
|
{/* 常见问答管理 */}
|
|
<Card style={{ marginTop: '10px' }}>
|
|
<SettingsFAQ options={inputs} refresh={onRefresh} />
|
|
</Card>
|
|
|
|
{/* Uptime Kuma 监控设置 */}
|
|
<Card style={{ marginTop: '10px' }}>
|
|
<SettingsUptimeKuma options={inputs} refresh={onRefresh} />
|
|
</Card>
|
|
</Spin>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default DashboardSetting;
|