feat: add server metrics fetching and update translations

- Implemented `fetchServerMetrics` function in `nezha-api.ts` to retrieve server metrics based on metric type and period.
- Added new metric types and periods to `nezha-api.ts` type definitions.
- Updated English and Chinese translations to include new terms for metrics and periods.
- Commented out `ServerDetailSummary` component in `ServerDetail.tsx` for future use.
This commit is contained in:
hamster1963
2026-01-30 09:14:41 +08:00
parent 1aa66f98ed
commit 65b32ec81e
6 changed files with 951 additions and 365 deletions
+19
View File
@@ -1,7 +1,10 @@
import type {
LoginUserResponse,
MetricPeriod,
MetricType,
MonitorResponse,
ServerGroupResponse,
ServerMetricsResponse,
ServiceResponse,
SettingResponse,
} from "@/types/nezha-api";
@@ -69,3 +72,19 @@ export const fetchSetting = async (): Promise<SettingResponse> => {
}
return data;
};
export const fetchServerMetrics = async (
server_id: number,
metric: MetricType,
period?: MetricPeriod,
): Promise<ServerMetricsResponse> => {
const query = period
? `?metric=${metric}&period=${period}`
: `?metric=${metric}`;
const response = await fetch(`/api/v1/server/${server_id}/metrics${query}`);
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
return data;
};