perf: remove uptime for optimism sql query
This commit is contained in:
1 parent
dcc84683a8
commit
98cf0753b5
9 files changed
+4
-33
No files matched your search
@@ -37,7 +37,6 @@ CREATE TABLE IF NOT EXISTS monitors (
|
||||
created_by INTEGER NOT NULL,
|
||||
active BOOLEAN NOT NULL DEFAULT 1,
|
||||
status TEXT DEFAULT 'pending',
|
||||
uptime REAL DEFAULT 100.0,
|
||||
response_time INTEGER DEFAULT 0,
|
||||
last_checked TIMESTAMP,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function createTables(env: Bindings): Promise<void> {
|
||||
|
||||
console.log("创建监控表...");
|
||||
await env.DB.exec(
|
||||
"CREATE TABLE IF NOT EXISTS monitors (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, url TEXT NOT NULL, method TEXT NOT NULL, interval INTEGER NOT NULL, timeout INTEGER NOT NULL, expected_status INTEGER NOT NULL, headers TEXT NOT NULL, body TEXT, created_by INTEGER NOT NULL, active BOOLEAN NOT NULL, status TEXT DEFAULT 'pending', uptime REAL DEFAULT 100.0, response_time INTEGER DEFAULT 0, last_checked TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, FOREIGN KEY (created_by) REFERENCES users(id))"
|
||||
"CREATE TABLE IF NOT EXISTS monitors (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, url TEXT NOT NULL, method TEXT NOT NULL, interval INTEGER NOT NULL, timeout INTEGER NOT NULL, expected_status INTEGER NOT NULL, headers TEXT NOT NULL, body TEXT, created_by INTEGER NOT NULL, active BOOLEAN NOT NULL, status TEXT DEFAULT 'pending', response_time INTEGER DEFAULT 0, last_checked TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, FOREIGN KEY (created_by) REFERENCES users(id))"
|
||||
);
|
||||
|
||||
console.log("创建24小时监控状态历史表(热表)...");
|
||||
|
||||
@@ -12,7 +12,6 @@ export interface Monitor {
|
||||
created_by: number;
|
||||
active: boolean;
|
||||
status: string;
|
||||
uptime: number;
|
||||
response_time: number;
|
||||
last_checked: string;
|
||||
created_at: string;
|
||||
|
||||
@@ -142,16 +142,9 @@ export async function updateMonitorStatus(
|
||||
SET status = ?,
|
||||
last_checked = ?,
|
||||
response_time = ?,
|
||||
uptime = (
|
||||
SELECT ROUND((COUNT(CASE WHEN status = 'up' THEN 1 ELSE NULL END) * 100.0 / COUNT(*)), 2)
|
||||
FROM monitor_status_history_24h
|
||||
WHERE monitor_id = ?
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 100
|
||||
)
|
||||
WHERE id = ?`
|
||||
)
|
||||
.bind(status, now, responseTime, monitorId, monitorId)
|
||||
.bind(status, now, responseTime, monitorId)
|
||||
.run();
|
||||
}
|
||||
|
||||
@@ -173,8 +166,8 @@ export async function createMonitor(
|
||||
const result = await db
|
||||
.prepare(
|
||||
`INSERT INTO monitors
|
||||
(name, url, method, interval, timeout, expected_status, headers, body, created_by, active, status, uptime, response_time, last_checked, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
(name, url, method, interval, timeout, expected_status, headers, body, created_by, active, status, response_time, last_checked, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.bind(
|
||||
name,
|
||||
@@ -188,7 +181,6 @@ export async function createMonitor(
|
||||
userId,
|
||||
1, // active
|
||||
"pending",
|
||||
100.0,
|
||||
0,
|
||||
null,
|
||||
now,
|
||||
|
||||
@@ -252,7 +252,6 @@ export async function updateMonitor(db: Bindings["DB"], id: number, data: any) {
|
||||
if (data.body !== undefined) updateData.body = data.body;
|
||||
if (data.active !== undefined) updateData.active = data.active;
|
||||
if (data.status !== undefined) updateData.status = data.status;
|
||||
if (data.uptime !== undefined) updateData.uptime = data.uptime;
|
||||
if (data.responseTime !== undefined)
|
||||
updateData.response_time = data.responseTime;
|
||||
if (data.lastChecked !== undefined)
|
||||
|
||||
@@ -110,7 +110,6 @@ const enUS = {
|
||||
"dashboard.summary": "Overview",
|
||||
"dashboard.totalMonitors": "Total Monitors",
|
||||
"dashboard.activeMonitors": "Active Monitors",
|
||||
"dashboard.uptime": "Uptime",
|
||||
"dashboard.refresh": "Refresh",
|
||||
|
||||
// Monitor list
|
||||
|
||||
@@ -110,8 +110,6 @@ const zhCN = {
|
||||
"dashboard.summary": "概览",
|
||||
"dashboard.totalMonitors": "监控总数",
|
||||
"dashboard.activeMonitors": "活动监控",
|
||||
"dashboard.uptime": "正常运行时间",
|
||||
"dashboard.refresh": "刷新",
|
||||
|
||||
// 监控列表
|
||||
"monitors.title": "监控列表",
|
||||
@@ -142,7 +140,6 @@ const zhCN = {
|
||||
"monitor.edit": "编辑监控",
|
||||
"monitor.delete": "删除监控",
|
||||
"monitor.history": "历史记录",
|
||||
"monitor.uptime": "正常运行时间",
|
||||
"monitor.responseTime": "响应时间",
|
||||
"monitor.oneDayHistory": "24小时记录",
|
||||
"monitor.MonthsHistory": "30天记录",
|
||||
|
||||
@@ -245,9 +245,6 @@ const MonitorsList = () => {
|
||||
<Table.ColumnHeaderCell>
|
||||
{t("monitors.table.responseTime")}
|
||||
</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>
|
||||
{t("monitors.table.uptime")}
|
||||
</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>
|
||||
{t("monitors.table.actions")}
|
||||
</Table.ColumnHeaderCell>
|
||||
@@ -284,15 +281,6 @@ const MonitorsList = () => {
|
||||
: "-"}
|
||||
</Text>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Text>
|
||||
{Math.min(
|
||||
monitor.uptime || monitor.uptime_percentage || 0,
|
||||
100
|
||||
).toFixed(2)}
|
||||
%
|
||||
</Text>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Flex gap="2">
|
||||
<IconButton
|
||||
|
||||
@@ -14,8 +14,6 @@ export interface Monitor {
|
||||
timeout: number;
|
||||
status: "up" | "down" | "pending" | "unknown";
|
||||
last_checked?: string;
|
||||
uptime_percentage?: number;
|
||||
uptime?: number;
|
||||
response_time?: number;
|
||||
user_id: number;
|
||||
created_by?: number;
|
||||
|
||||
Reference in new issue
Block a user