diff --git a/docs/content/docs/en/operations/meta.json b/docs/content/docs/en/operations/meta.json index c3b7c348a..230047510 100644 --- a/docs/content/docs/en/operations/meta.json +++ b/docs/content/docs/en/operations/meta.json @@ -3,6 +3,7 @@ "icon": "ServerCog", "pages": [ "reverse-proxy", + "system-monitoring", "multi-node", "outbounds-routing", "backup-restore", diff --git a/docs/content/docs/en/operations/system-monitoring.mdx b/docs/content/docs/en/operations/system-monitoring.mdx new file mode 100644 index 000000000..d80b2791f --- /dev/null +++ b/docs/content/docs/en/operations/system-monitoring.mdx @@ -0,0 +1,47 @@ +--- +title: System monitoring +description: Read the overview charts, choose a time window, and understand how 3x-ui stores system history. +icon: ChartNoAxesCombined +--- + +The overview page combines a current server snapshot with short time-series charts. It shows CPU, memory, swap, storage, network throughput, and open TCP/UDP connections. Open **System history** for additional metrics such as packets, disk I/O, load averages, and Xray online clients. + +## Choose a chart window + +Each overview chart has the same time-range selector in its upper-right corner. The default is **2m**. The choices are **2m**, **5m**, **30m**, **1h**, **6h**, and **12h**. Changing any selector changes the window on every overview chart. + +The number of chart points stays capped at 60. Short windows use finer samples; longer windows use averages. At **2m** the charts are live: every status poll, once every 2 seconds, adds a point. A longer window is read from the server's stored history and refreshed once per point, at most once a minute. + +The **System history** dialog has per-metric tabs and longer windows: **2m**, **1h**, **3h**, **6h**, **12h**, **24h**, **2d**, and **7d**. It refreshes only the active metric, and slows its polling as the selected window grows. + +## Metrics and scope + +The overview charts show: + +- CPU use, memory use, swap use, and disk use as percentages. +- Network upload and download throughput in bytes per second. +- Current TCP and UDP connection counts. + +System history adds packet rates, disk read/write rates, Xray online clients, and the 1, 5, and 15 minute load averages. CPU and swap follow the panel's resource scope when it runs inside a container; unavailable scoped metrics are left empty instead of being filled with host values. + +Chart summaries show the average and peak inside the selected window. For Persian labels, the text and numeric value are isolated separately so right-to-left text direction does not reorder the number or percent sign. + +## Collection and retention + +The panel samples server status every **2 seconds**. Each metric is written into three fixed-size rollup tiers: + +| Resolution | Retained window | Use | +| --- | --- | --- | +| 2 seconds | 1 hour | Recent charts | +| 1 minute | 48 hours | Medium windows | +| 10 minutes | 7 days | Long history | + +Samples are averaged as they move through each tier. A series retains about 5,700 points (roughly 90 KiB before serialization), regardless of uptime. The overview endpoint returns up to 60 points per metric in one response, avoiding a request for each individual chart. + +System history is saved to `system_metrics.gob` in the panel's database directory once a minute and again during shutdown. It is restored at startup. A new installation begins collecting history when the panel starts; it cannot reconstruct metrics from before collection was enabled. + +## API + +For a window longer than **2m** the overview requests `GET /panel/api/server/overviewHistory/{bucket}`. `bucket` is the number of seconds one point covers: `5`, `30`, `60`, `360` and `720` give the 5 minute through 12 hour windows. The response contains up to 60 `{ "t": unixSeconds, "v": value }` points for each overview metric. + +The system history dialog requests `GET /panel/api/server/history/{metric}/{bucket}` for the active metric. It uses the same `{t, v}` point format and supports the longer bucket values documented in the [Server API reference](/docs/reference/api/server). diff --git a/docs/content/docs/en/reference/api/server.mdx b/docs/content/docs/en/reference/api/server.mdx index 0ac548f28..9738ba947 100644 --- a/docs/content/docs/en/reference/api/server.mdx +++ b/docs/content/docs/en/reference/api/server.mdx @@ -33,18 +33,24 @@ _openapi: data with a uniform {t, v} shape.' url: '#legacy-aggregated-cpu-history-use-historycpubucket-instead--same-data-with-a-uniform-t-v-shape' - depth: 2 - title: Aggregated time-series for one metric. Returns an array of {t, v} samples - covering the last ~6 hours. - url: '#aggregated-time-series-for-one-metric-returns-an-array-of-t-v-samples-covering-the-last-6-hours' + title: Aggregated time-series for one system metric. Returns up to 60 {t, v} + samples; supported bucket sizes cover windows from 2 minutes up to 7 + days. + url: '#aggregated-time-series-for-one-system-metric-returns-up-to-60-t-v-samples-supported-bucket-sizes-cover-windows-from-2-minutes-up-to-7-days' + - depth: 2 + title: 'Aggregated history for all overview charts in one response: up to 60 {t, + v} samples for each of cpu, mem, swap, diskUsage, netUp, netDown, + tcpCount and udpCount.' + url: '#aggregated-history-for-all-overview-charts-in-one-response-up-to-60-t-v-samples-for-each-of-cpu-mem-swap-diskusage-netup-netdown-tcpcount-and-udpcount' - depth: 2 title: Xray runtime metrics state — whether the xray config has a `metrics` block, which expvar keys are flowing, and the current snapshot values for each. Returns an empty state when metrics are not configured. url: '#xray-runtime-metrics-state--whether-the-xray-config-has-a-metrics-block-which-expvar-keys-are-flowing-and-the-current-snapshot-values-for-each-returns-an-empty-state-when-metrics-are-not-configured' - depth: 2 - title: Time-series history for one Xray runtime metric over the last ~6 hours. - Same {t, v} shape as /history/:metric/:bucket. - url: '#time-series-history-for-one-xray-runtime-metric-over-the-last-6-hours-same-t-v-shape-as-historymetricbucket' + title: Aggregated history for one Xray runtime metric. Returns up to 60 {t, v} + samples for bucket windows up to 7 days. + url: '#aggregated-history-for-one-xray-runtime-metric-returns-up-to-60-t-v-samples-for-bucket-windows-up-to-7-days' - depth: 2 title: Latest snapshot from the Xray observatory — per-outbound latency, health status, and last-probe time. Only populated when the Xray config has an @@ -207,16 +213,21 @@ _openapi: - content: 'Legacy: aggregated CPU history. Use /history/cpu/:bucket instead — same data with a uniform {t, v} shape.' id: legacy-aggregated-cpu-history-use-historycpubucket-instead--same-data-with-a-uniform-t-v-shape - - content: Aggregated time-series for one metric. Returns an array of {t, v} - samples covering the last ~6 hours. - id: aggregated-time-series-for-one-metric-returns-an-array-of-t-v-samples-covering-the-last-6-hours + - content: Aggregated time-series for one system metric. Returns up to 60 {t, v} + samples; supported bucket sizes cover windows from 2 minutes up to 7 + days. + id: aggregated-time-series-for-one-system-metric-returns-up-to-60-t-v-samples-supported-bucket-sizes-cover-windows-from-2-minutes-up-to-7-days + - content: 'Aggregated history for all overview charts in one response: up to 60 + {t, v} samples for each of cpu, mem, swap, diskUsage, netUp, netDown, + tcpCount and udpCount.' + id: aggregated-history-for-all-overview-charts-in-one-response-up-to-60-t-v-samples-for-each-of-cpu-mem-swap-diskusage-netup-netdown-tcpcount-and-udpcount - content: Xray runtime metrics state — whether the xray config has a `metrics` block, which expvar keys are flowing, and the current snapshot values for each. Returns an empty state when metrics are not configured. id: xray-runtime-metrics-state--whether-the-xray-config-has-a-metrics-block-which-expvar-keys-are-flowing-and-the-current-snapshot-values-for-each-returns-an-empty-state-when-metrics-are-not-configured - - content: Time-series history for one Xray runtime metric over the last ~6 hours. - Same {t, v} shape as /history/:metric/:bucket. - id: time-series-history-for-one-xray-runtime-metric-over-the-last-6-hours-same-t-v-shape-as-historymetricbucket + - content: Aggregated history for one Xray runtime metric. Returns up to 60 {t, v} + samples for bucket windows up to 7 days. + id: aggregated-history-for-one-xray-runtime-metric-returns-up-to-60-t-v-samples-for-bucket-windows-up-to-7-days - content: Latest snapshot from the Xray observatory — per-outbound latency, health status, and last-probe time. Only populated when the Xray config has an observatory configured. @@ -334,7 +345,7 @@ export default function Layout(props) { return ( <> {props.children} - + ); } \ No newline at end of file diff --git a/docs/content/docs/fa/operations/meta.json b/docs/content/docs/fa/operations/meta.json index 000badb34..e1becfb6b 100644 --- a/docs/content/docs/fa/operations/meta.json +++ b/docs/content/docs/fa/operations/meta.json @@ -3,6 +3,7 @@ "icon": "ServerCog", "pages": [ "reverse-proxy", + "system-monitoring", "multi-node", "outbounds-routing", "backup-restore", diff --git a/docs/content/docs/fa/operations/system-monitoring.mdx b/docs/content/docs/fa/operations/system-monitoring.mdx new file mode 100644 index 000000000..2082e9c59 --- /dev/null +++ b/docs/content/docs/fa/operations/system-monitoring.mdx @@ -0,0 +1,47 @@ +--- +title: پایش سیستم +description: نمودارهای نمای کلی، انتخاب بازهٔ زمانی و نحوهٔ نگهداری تاریخچهٔ سیستم در 3x-ui. +icon: ChartNoAxesCombined +--- + +صفحهٔ نمای کلی، وضعیت فعلی سرور را همراه نمودارهای زمانی نشان می‌دهد: پردازنده، حافظه، سوآپ، فضای ذخیره‌سازی، نرخ ترافیک شبکه و اتصال‌های TCP/UDP. برای شاخص‌های بیشتر مثل نرخ بسته‌ها، ورودی/خروجی دیسک، میانگین بار سیستم و کلاینت‌های آنلاین Xray، پنجرهٔ **تاریخچهٔ سیستم** را باز کنید. + +## انتخاب بازهٔ نمودار + +هر نمودار نمای کلی یک سلکت بازهٔ زمانی در گوشهٔ بالای سمت راست دارد. مقدار پیش‌فرض **2m** است. گزینه‌ها **2m**، **5m**، **30m**، **1h**، **6h** و **12h** هستند. تغییر بازه در هر نمودار، بازهٔ همهٔ نمودارهای نمای کلی را تغییر می‌دهد. + +تعداد نقطه‌های نمودار حداکثر ۶۰ نقطه است. بازه‌های کوتاه‌تر از نمونه‌های دقیق‌تر و بازه‌های بلندتر از میانگین نمونه‌ها استفاده می‌کنند. در بازهٔ **2m** نمودارها زنده‌اند: هر بار دریافت وضعیت، یعنی هر ۲ ثانیه، یک نقطه اضافه می‌کند. بازه‌های بلندتر از تاریخچهٔ ذخیره‌شده در سرور خوانده می‌شوند و به‌ازای هر نقطه یک بار، و حداکثر دقیقه‌ای یک بار، به‌روزرسانی می‌شوند. + +پنجرهٔ **تاریخچهٔ سیستم** برای هر شاخص زبانه‌ای جدا دارد و بازه‌های بلندتر **2m**، **1h**، **3h**، **6h**، **12h**، **24h**، **2d** و **7d** را ارائه می‌کند. فقط شاخص فعال به‌روزرسانی می‌شود و با بزرگ‌تر شدن بازه، فاصلهٔ دریافت اطلاعات بیشتر می‌شود. + +## شاخص‌ها و محدودهٔ منابع + +نمودارهای نمای کلی این موارد را نشان می‌دهند: + +- مصرف پردازنده، حافظه، سوآپ و دیسک به‌صورت درصد. +- نرخ ارسال و دریافت شبکه به بایت بر ثانیه. +- تعداد فعلی اتصال‌های TCP و UDP. + +تاریخچهٔ سیستم نرخ بسته‌ها، نرخ خواندن/نوشتن دیسک، کلاینت‌های آنلاین Xray و میانگین بار ۱، ۵ و ۱۵ دقیقه را هم دارد. وقتی پنل داخل کانتینر اجرا می‌شود، مصرف پردازنده و سوآپ از محدودهٔ منابع همان کانتینر گرفته می‌شوند. اگر این شاخص‌ها در دسترس نباشند، نمودار خالی می‌ماند و از دادهٔ میزبان به‌جای آن‌ها استفاده نمی‌شود. + +خلاصهٔ هر نمودار، میانگین و بیشینهٔ مقدار را در بازهٔ انتخاب‌شده نشان می‌دهد. برچسب و مقدار عددی فارسی جدا از هم نمایش داده می‌شوند تا جهت راست‌به‌چپ، ترتیب رقم‌ها و علامت درصد را جابه‌جا نکند. + +## جمع‌آوری و نگهداری داده + +پنل هر **۲ ثانیه** یک نمونه از وضعیت سرور می‌گیرد. هر شاخص در سه سطح تجمیع با اندازهٔ ثابت نگهداری می‌شود: + +| دقت داده | مدت نگهداری | کاربرد | +| --- | --- | --- | +| ۲ ثانیه | ۱ ساعت | نمودارهای نزدیک به زمان حال | +| ۱ دقیقه | ۴۸ ساعت | بازه‌های میان‌مدت | +| ۱۰ دقیقه | ۷ روز | تاریخچهٔ بلندمدت | + +هنگام انتقال داده به سطح بعدی، نمونه‌ها با هم میانگین‌گیری می‌شوند. هر شاخص حدود ۵٬۷۰۰ نقطه (نزدیک به ۹۰ کیلوبایت پیش از سریال‌سازی) نگه می‌دارد؛ بنابراین مصرف حافظه با زمان کارکرد سرور رشد نامحدود ندارد. یک درخواست، حداکثر ۶۰ نقطه از همهٔ شاخص‌های نمای کلی را می‌گیرد تا برای هر نمودار درخواست جداگانه ارسال نشود. + +تاریخچهٔ سیستم هر دقیقه در فایل `system_metrics.gob` کنار داده‌های پایگاه‌دادهٔ پنل ذخیره می‌شود و هنگام خاموش شدن پنل نیز ذخیرهٔ نهایی انجام می‌شود. داده‌ها هنگام راه‌اندازی بعدی بازیابی می‌شوند. نصب تازه از زمان شروع پنل داده جمع می‌کند و نمی‌تواند شاخص‌های پیش از فعال شدن این جمع‌آوری را بازسازی کند. + +## API + +نمای کلی برای بازه‌های بلندتر از **2m** از `GET /panel/api/server/overviewHistory/{bucket}` استفاده می‌کند. مقدار `bucket` تعداد ثانیه‌هایی است که هر نقطه پوشش می‌دهد: مقادیر `5`، `30`، `60`، `360` و `720` بازه‌های ۵ دقیقه تا ۱۲ ساعت را می‌دهند. پاسخ برای هر شاخص نمای کلی حداکثر ۶۰ نقطه با قالب `{ "t": unixSeconds, "v": value }` دارد. + +پنجرهٔ تاریخچهٔ سیستم برای شاخص فعال، `GET /panel/api/server/history/{metric}/{bucket}` را فراخوانی می‌کند. قالب هر نقطه همان `{t, v}` است؛ مقدارهای بزرگ‌تر `bucket` در [مرجع API سرور](/docs/reference/api/server) آمده‌اند. diff --git a/docs/public/openapi.json b/docs/public/openapi.json index 733b1e2b4..d65258604 100644 --- a/docs/public/openapi.json +++ b/docs/public/openapi.json @@ -7255,7 +7255,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } @@ -7289,14 +7289,14 @@ "tags": [ "Server" ], - "summary": "Aggregated time-series for one metric. Returns an array of {t, v} samples covering the last ~6 hours.", + "summary": "Aggregated time-series for one system metric. Returns up to 60 {t, v} samples; supported bucket sizes cover windows from 2 minutes up to 7 days.", "operationId": "get_panel_api_server_history_metric_bucket", "parameters": [ { "name": "metric", "in": "path", "required": true, - "description": "cpu | mem | netUp | netDown | online | load1 | load5 | load15.", + "description": "cpu | mem | swap | netUp | netDown | pktUp | pktDown | diskRead | diskWrite | diskUsage | tcpCount | udpCount | online | load1 | load5 | load15.", "schema": { "type": "string" } @@ -7305,7 +7305,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } @@ -7347,6 +7347,47 @@ } } }, + "/panel/api/server/overviewHistory/{bucket}": { + "get": { + "tags": [ + "Server" + ], + "summary": "Aggregated history for all overview charts in one response: up to 60 {t, v} samples for each of cpu, mem, swap, diskUsage, netUp, netDown, tcpCount and udpCount.", + "operationId": "get_panel_api_server_overviewHistory_bucket", + "parameters": [ + { + "name": "bucket", + "in": "path", + "required": true, + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": {} + } + } + } + } + } + } + } + }, "/panel/api/server/xrayMetricsState": { "get": { "tags": [ @@ -7382,7 +7423,7 @@ "tags": [ "Server" ], - "summary": "Time-series history for one Xray runtime metric over the last ~6 hours. Same {t, v} shape as /history/:metric/:bucket.", + "summary": "Aggregated history for one Xray runtime metric. Returns up to 60 {t, v} samples for bucket windows up to 7 days.", "operationId": "get_panel_api_server_xrayMetricsHistory_metric_bucket", "parameters": [ { @@ -7398,7 +7439,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } @@ -7478,7 +7519,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } @@ -13669,7 +13710,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } diff --git a/frontend/public/openapi.json b/frontend/public/openapi.json index 733b1e2b4..d65258604 100644 --- a/frontend/public/openapi.json +++ b/frontend/public/openapi.json @@ -7255,7 +7255,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } @@ -7289,14 +7289,14 @@ "tags": [ "Server" ], - "summary": "Aggregated time-series for one metric. Returns an array of {t, v} samples covering the last ~6 hours.", + "summary": "Aggregated time-series for one system metric. Returns up to 60 {t, v} samples; supported bucket sizes cover windows from 2 minutes up to 7 days.", "operationId": "get_panel_api_server_history_metric_bucket", "parameters": [ { "name": "metric", "in": "path", "required": true, - "description": "cpu | mem | netUp | netDown | online | load1 | load5 | load15.", + "description": "cpu | mem | swap | netUp | netDown | pktUp | pktDown | diskRead | diskWrite | diskUsage | tcpCount | udpCount | online | load1 | load5 | load15.", "schema": { "type": "string" } @@ -7305,7 +7305,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } @@ -7347,6 +7347,47 @@ } } }, + "/panel/api/server/overviewHistory/{bucket}": { + "get": { + "tags": [ + "Server" + ], + "summary": "Aggregated history for all overview charts in one response: up to 60 {t, v} samples for each of cpu, mem, swap, diskUsage, netUp, netDown, tcpCount and udpCount.", + "operationId": "get_panel_api_server_overviewHistory_bucket", + "parameters": [ + { + "name": "bucket", + "in": "path", + "required": true, + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": {} + } + } + } + } + } + } + } + }, "/panel/api/server/xrayMetricsState": { "get": { "tags": [ @@ -7382,7 +7423,7 @@ "tags": [ "Server" ], - "summary": "Time-series history for one Xray runtime metric over the last ~6 hours. Same {t, v} shape as /history/:metric/:bucket.", + "summary": "Aggregated history for one Xray runtime metric. Returns up to 60 {t, v} samples for bucket windows up to 7 days.", "operationId": "get_panel_api_server_xrayMetricsHistory_metric_bucket", "parameters": [ { @@ -7398,7 +7439,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } @@ -7478,7 +7519,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } @@ -13669,7 +13710,7 @@ "name": "bucket", "in": "path", "required": true, - "description": "Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.", + "description": "Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.", "schema": { "type": "integer" } diff --git a/frontend/src/pages/api-docs/endpoints.ts b/frontend/src/pages/api-docs/endpoints.ts index 9b0f943b3..e23b82b13 100644 --- a/frontend/src/pages/api-docs/endpoints.ts +++ b/frontend/src/pages/api-docs/endpoints.ts @@ -482,7 +482,7 @@ export const sections: readonly Section[] = [ name: 'bucket', in: 'path', type: 'number', - desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.', + desc: 'Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.', }, ], }, @@ -490,24 +490,38 @@ export const sections: readonly Section[] = [ method: 'GET', path: '/panel/api/server/history/:metric/:bucket', summary: - 'Aggregated time-series for one metric. Returns an array of {t, v} samples covering the last ~6 hours.', + 'Aggregated time-series for one system metric. Returns up to 60 {t, v} samples; supported bucket sizes cover windows from 2 minutes up to 7 days.', params: [ { name: 'metric', in: 'path', type: 'string', - desc: 'cpu | mem | netUp | netDown | online | load1 | load5 | load15.', + desc: 'cpu | mem | swap | netUp | netDown | pktUp | pktDown | diskRead | diskWrite | diskUsage | tcpCount | udpCount | online | load1 | load5 | load15.', }, { name: 'bucket', in: 'path', type: 'number', - desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.', + desc: 'Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.', }, ], response: '{\n "success": true,\n "obj": [\n { "t": 1700000000, "v": 12.5 },\n { "t": 1700000002, "v": 13.1 }\n ]\n}', }, + { + method: 'GET', + path: '/panel/api/server/overviewHistory/:bucket', + summary: + 'Aggregated history for all overview charts in one response: up to 60 {t, v} samples for each of cpu, mem, swap, diskUsage, netUp, netDown, tcpCount and udpCount.', + params: [ + { + name: 'bucket', + in: 'path', + type: 'number', + desc: 'Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.', + }, + ], + }, { method: 'GET', path: '/panel/api/server/xrayMetricsState', @@ -518,7 +532,7 @@ export const sections: readonly Section[] = [ method: 'GET', path: '/panel/api/server/xrayMetricsHistory/:metric/:bucket', summary: - 'Time-series history for one Xray runtime metric over the last ~6 hours. Same {t, v} shape as /history/:metric/:bucket.', + 'Aggregated history for one Xray runtime metric. Returns up to 60 {t, v} samples for bucket windows up to 7 days.', params: [ { name: 'metric', @@ -530,7 +544,7 @@ export const sections: readonly Section[] = [ name: 'bucket', in: 'path', type: 'number', - desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.', + desc: 'Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.', }, ], }, @@ -556,7 +570,7 @@ export const sections: readonly Section[] = [ name: 'bucket', in: 'path', type: 'number', - desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.', + desc: 'Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.', }, ], }, @@ -2040,7 +2054,7 @@ export const sections: readonly Section[] = [ name: 'bucket', in: 'path', type: 'number', - desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.', + desc: 'Bucket size in seconds. Allowed: 2, 5, 30, 60, 180, 360, 720, 1440, 2880, 10080.', }, ], }, diff --git a/frontend/src/pages/index/ConnectionsCard.tsx b/frontend/src/pages/index/ConnectionsCard.tsx index a127fb2f6..128e9b4ab 100644 --- a/frontend/src/pages/index/ConnectionsCard.tsx +++ b/frontend/src/pages/index/ConnectionsCard.tsx @@ -4,6 +4,8 @@ import { Card, theme } from 'antd'; import { Sparkline } from '@/components/viz'; import type { Status } from '@/models/status'; +import OverviewRangeSelect from './OverviewRangeSelect'; +import type { OverviewRange } from './OverviewRangeSelect'; interface ConnectionsCardProps { status: Status; @@ -11,6 +13,8 @@ interface ConnectionsCardProps { udp: number[]; labels: string[]; isMobile: boolean; + range: OverviewRange; + onRangeChange: (range: OverviewRange) => void; } export default function ConnectionsCard({ @@ -19,6 +23,8 @@ export default function ConnectionsCard({ udp, labels, isMobile, + range, + onRangeChange, }: ConnectionsCardProps) { const { t } = useTranslation(); const { token } = theme.useToken(); @@ -34,7 +40,7 @@ export default function ConnectionsCard({ ); return ( - +
{t('pages.index.connectionCount')}
@@ -43,6 +49,9 @@ export default function ConnectionsCard({
+
+ +
diff --git a/frontend/src/pages/index/IndexPage.css b/frontend/src/pages/index/IndexPage.css index 8eb56ebcc..22f689698 100644 --- a/frontend/src/pages/index/IndexPage.css +++ b/frontend/src/pages/index/IndexPage.css @@ -213,14 +213,19 @@ } .ov-tile { + position: relative; overflow: hidden; } +.ov-wide-card { + position: relative; +} + .ov-tile-head { display: flex; align-items: center; gap: 8px; - padding: 14px var(--ov-pad) 0; + padding: 14px calc(var(--ov-pad) + 82px + 12px) 0 var(--ov-pad); color: var(--ov-accent); } @@ -267,10 +272,30 @@ color: var(--ov-faint); } +.ov-tile-foot > span { + display: inline-flex; + align-items: baseline; + gap: 4px; + white-space: nowrap; + unicode-bidi: plaintext; +} + .ov-tile-chart { margin-top: 6px; } +.ov-range-toolbar { + position: absolute; + z-index: 1; + top: 14px; + right: var(--ov-pad); + display: flex; +} + +.ov-range-select { + width: 82px; +} + /* — throughput + connections — */ .ov-mid { @@ -290,7 +315,7 @@ align-items: flex-start; flex-wrap: wrap; gap: 16px; - padding: var(--ov-pad) var(--ov-pad) 0; + padding: var(--ov-pad) calc(var(--ov-pad) + 82px + 12px) 0 var(--ov-pad); } .ov-wide-head-stack { diff --git a/frontend/src/pages/index/IndexPage.tsx b/frontend/src/pages/index/IndexPage.tsx index 01cee6f64..63fda3f39 100644 --- a/frontend/src/pages/index/IndexPage.tsx +++ b/frontend/src/pages/index/IndexPage.tsx @@ -30,6 +30,7 @@ import ThroughputCard from './ThroughputCard'; import ConnectionsCard from './ConnectionsCard'; import SystemStrip from './SystemStrip'; import { mean, peak, useOverviewHistory } from './useOverviewHistory'; +import type { OverviewRange } from './OverviewRangeSelect'; import type { PanelUpdateInfo } from './PanelUpdateModal'; const JsonEditor = lazy(() => import('@/components/form/JsonEditor')); const PanelUpdateModal = lazy(() => import('./PanelUpdateModal')); @@ -42,6 +43,15 @@ const AmneziaWGLogModal = lazy(() => import('./AmneziaWGLogModal')); const VersionModal = lazy(() => import('./VersionModal')); import './IndexPage.css'; +function metricFoot(label: string, value: string) { + return ( + <> + {label} + {value} + + ); +} + export default function IndexPage() { const { t } = useTranslation(); const { isDark, isUltra, antdThemeConfig } = useTheme(); @@ -76,7 +86,8 @@ export default function IndexPage() { const [loading, setLoading] = useState(false); const [loadingTip, setLoadingTip] = useState(t('loading')); - const history = useOverviewHistory(status, fetched && !fetchError); + const [historyRange, setHistoryRange] = useState(2); + const history = useOverviewHistory(status, fetched && !fetchError, historyRange); useEffect(() => { HttpUtil.post<{ accessLogEnable?: boolean; devChannelEnable?: boolean }>( @@ -238,10 +249,18 @@ export default function IndexPage() { ? `${status.logicalPro} vCPU` : `${CPUFormatter.cpuCoreFormat(status.cpuCores)} / ${status.logicalPro}T · ${CPUFormatter.cpuSpeedFormat(status.cpuSpeedMhz)}` } - footLeft={`${t('pages.index.avg')} ${mean(history.series.cpu).toFixed(0)}%`} - footRight={`${t('pages.index.peak')} ${peak(history.series.cpu).toFixed(0)}%`} + footLeft={metricFoot( + t('pages.index.avg'), + `${mean(history.series.cpu).toFixed(0)}%`, + )} + footRight={metricFoot( + t('pages.index.peak'), + `${peak(history.series.cpu).toFixed(0)}%`, + )} data={history.series.cpu} isMobile={isMobile} + range={historyRange} + onRangeChange={setHistoryRange} /> } @@ -249,10 +268,18 @@ export default function IndexPage() { percent={status.mem.percent} statusColor={status.mem.color} detail={`${SizeFormatter.sizeFormat(status.mem.current)} / ${SizeFormatter.sizeFormat(status.mem.total)}`} - footLeft={`${t('pages.index.avg')} ${mean(history.series.mem).toFixed(0)}%`} - footRight={`${t('pages.index.peak')} ${peak(history.series.mem).toFixed(0)}%`} + footLeft={metricFoot( + t('pages.index.avg'), + `${mean(history.series.mem).toFixed(0)}%`, + )} + footRight={metricFoot( + t('pages.index.peak'), + `${peak(history.series.mem).toFixed(0)}%`, + )} data={history.series.mem} isMobile={isMobile} + range={historyRange} + onRangeChange={setHistoryRange} /> } @@ -261,10 +288,18 @@ export default function IndexPage() { percent={status.swap.percent} statusColor={status.swap.color} detail={`${SizeFormatter.sizeFormat(status.swap.current)} / ${SizeFormatter.sizeFormat(status.swap.total)}`} - footLeft={`${t('pages.index.avg')} ${mean(history.series.swap).toFixed(1)}%`} - footRight={`${t('pages.index.peak')} ${peak(history.series.swap).toFixed(0)}%`} + footLeft={metricFoot( + t('pages.index.avg'), + `${mean(history.series.swap).toFixed(1)}%`, + )} + footRight={metricFoot( + t('pages.index.peak'), + `${peak(history.series.swap).toFixed(0)}%`, + )} data={history.series.swap} isMobile={isMobile} + range={historyRange} + onRangeChange={setHistoryRange} /> } @@ -272,10 +307,18 @@ export default function IndexPage() { percent={status.disk.percent} statusColor={status.disk.color} detail={`${SizeFormatter.sizeFormat(status.disk.current)} / ${SizeFormatter.sizeFormat(totalDisk)}`} - footLeft={`${t('pages.index.free')} ${SizeFormatter.sizeFormat(freeDisk)}`} - footRight={`${t('pages.index.avg')} ${mean(history.series.diskUsage).toFixed(1)}%`} + footLeft={metricFoot( + t('pages.index.free'), + SizeFormatter.sizeFormat(freeDisk), + )} + footRight={metricFoot( + t('pages.index.avg'), + `${mean(history.series.diskUsage).toFixed(1)}%`, + )} data={history.series.diskUsage} isMobile={isMobile} + range={historyRange} + onRangeChange={setHistoryRange} />
@@ -286,6 +329,8 @@ export default function IndexPage() { down={history.series.netDown} labels={history.labels} isMobile={isMobile} + range={historyRange} + onRangeChange={setHistoryRange} />
diff --git a/frontend/src/pages/index/OverviewRangeSelect.tsx b/frontend/src/pages/index/OverviewRangeSelect.tsx new file mode 100644 index 000000000..a9878cee2 --- /dev/null +++ b/frontend/src/pages/index/OverviewRangeSelect.tsx @@ -0,0 +1,34 @@ +import { Select } from 'antd'; +import { useTranslation } from 'react-i18next'; + +export const OVERVIEW_RANGES = [2, 5, 30, 60, 360, 720] as const; +export type OverviewRange = (typeof OVERVIEW_RANGES)[number]; + +interface OverviewRangeSelectProps { + value: OverviewRange; + onChange: (value: OverviewRange) => void; +} + +const OPTIONS = [ + { value: 2, label: '2m' }, + { value: 5, label: '5m' }, + { value: 30, label: '30m' }, + { value: 60, label: '1h' }, + { value: 360, label: '6h' }, + { value: 720, label: '12h' }, +]; + +export default function OverviewRangeSelect({ value, onChange }: OverviewRangeSelectProps) { + const { t } = useTranslation(); + + return ( +