feat(dashboard): choose the time range of the overview charts (#7139)

Every overview chart gets the same range selector: 2m, 5m, 30m, 1h, 6h and 12h. The 2m default is the live trend the page already drew, one point per status poll, so nothing changes until a longer range is picked. A longer range is read from the server's stored rollups through the new GET /panel/api/server/overviewHistory/:bucket, which returns all eight overview series in one response, and is refreshed once per point, at most once a minute.

A metric the host cannot report stays empty in a ranged window instead of drawing zeros, a range change clears the chart rather than showing the old range under the new label, and avg/peak labels keep their number order in RTL locales.
This commit is contained in:
Mr Cortex
2026-11-25 01:04:29 +03:30
committed by GitHub
parent 142a1ab28e
commit 05e8f17268
23 changed files with 720 additions and 55 deletions
@@ -3,6 +3,7 @@
"icon": "ServerCog",
"pages": [
"reverse-proxy",
"system-monitoring",
"multi-node",
"outbounds-routing",
"backup-restore",
@@ -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).
+24 -13
View File
@@ -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}
<OpenAPIPage document="./public/openapi.json" webhooks={[]} operations={[{"path":"/panel/api/openapi.json","method":"get"},{"path":"/panel/api/server/status","method":"get"},{"path":"/panel/api/server/fail2banStatus","method":"get"},{"path":"/panel/api/server/networkInterfaces","method":"get"},{"path":"/panel/api/server/cpuHistory/{bucket}","method":"get"},{"path":"/panel/api/server/history/{metric}/{bucket}","method":"get"},{"path":"/panel/api/server/xrayMetricsState","method":"get"},{"path":"/panel/api/server/xrayMetricsHistory/{metric}/{bucket}","method":"get"},{"path":"/panel/api/server/xrayObservatory","method":"get"},{"path":"/panel/api/server/xrayObservatoryHistory/{tag}/{bucket}","method":"get"},{"path":"/panel/api/server/getXrayVersion","method":"get"},{"path":"/panel/api/server/getPanelUpdateInfo","method":"get"},{"path":"/panel/api/server/getUpdateStatus","method":"get"},{"path":"/panel/api/server/getConfigJson","method":"get"},{"path":"/panel/api/server/getDb","method":"get"},{"path":"/panel/api/server/getMigration","method":"get"},{"path":"/panel/api/server/getNewUUID","method":"get"},{"path":"/panel/api/server/getWebCertFiles","method":"get"},{"path":"/panel/api/server/descendants","method":"get"},{"path":"/panel/api/server/getNewX25519Cert","method":"get"},{"path":"/panel/api/server/getNewmldsa65","method":"get"},{"path":"/panel/api/server/getNewmlkem768","method":"get"},{"path":"/panel/api/server/getNewVlessEnc","method":"get"},{"path":"/panel/api/server/stopXrayService","method":"post"},{"path":"/panel/api/server/restartXrayService","method":"post"},{"path":"/panel/api/server/installXray/{version}","method":"post"},{"path":"/panel/api/server/updatePanel","method":"post"},{"path":"/panel/api/server/setUpdateChannel","method":"post"},{"path":"/panel/api/server/updateGeofile","method":"post"},{"path":"/panel/api/server/updateGeofile/{fileName}","method":"post"},{"path":"/panel/api/server/logs/{count}","method":"post"},{"path":"/panel/api/server/xraylogs/{count}","method":"post"},{"path":"/panel/api/server/amneziawglogs/{count}","method":"post"},{"path":"/panel/api/server/importDB","method":"post"},{"path":"/panel/api/server/getNewEchCert","method":"post"},{"path":"/panel/api/server/getCertHash","method":"post"},{"path":"/panel/api/server/getRemoteCertHash","method":"post"},{"path":"/panel/api/server/scanRealityTarget","method":"post"},{"path":"/panel/api/server/scanRealityTargets","method":"post"},{"path":"/panel/api/server/clientIps","method":"get"},{"path":"/panel/api/server/clientIps","method":"post"}]} showTitle />
<OpenAPIPage document="./public/openapi.json" webhooks={[]} operations={[{"path":"/panel/api/openapi.json","method":"get"},{"path":"/panel/api/server/status","method":"get"},{"path":"/panel/api/server/fail2banStatus","method":"get"},{"path":"/panel/api/server/networkInterfaces","method":"get"},{"path":"/panel/api/server/cpuHistory/{bucket}","method":"get"},{"path":"/panel/api/server/history/{metric}/{bucket}","method":"get"},{"path":"/panel/api/server/overviewHistory/{bucket}","method":"get"},{"path":"/panel/api/server/xrayMetricsState","method":"get"},{"path":"/panel/api/server/xrayMetricsHistory/{metric}/{bucket}","method":"get"},{"path":"/panel/api/server/xrayObservatory","method":"get"},{"path":"/panel/api/server/xrayObservatoryHistory/{tag}/{bucket}","method":"get"},{"path":"/panel/api/server/getXrayVersion","method":"get"},{"path":"/panel/api/server/getPanelUpdateInfo","method":"get"},{"path":"/panel/api/server/getUpdateStatus","method":"get"},{"path":"/panel/api/server/getConfigJson","method":"get"},{"path":"/panel/api/server/getDb","method":"get"},{"path":"/panel/api/server/getMigration","method":"get"},{"path":"/panel/api/server/getNewUUID","method":"get"},{"path":"/panel/api/server/getWebCertFiles","method":"get"},{"path":"/panel/api/server/descendants","method":"get"},{"path":"/panel/api/server/getNewX25519Cert","method":"get"},{"path":"/panel/api/server/getNewmldsa65","method":"get"},{"path":"/panel/api/server/getNewmlkem768","method":"get"},{"path":"/panel/api/server/getNewVlessEnc","method":"get"},{"path":"/panel/api/server/stopXrayService","method":"post"},{"path":"/panel/api/server/restartXrayService","method":"post"},{"path":"/panel/api/server/installXray/{version}","method":"post"},{"path":"/panel/api/server/updatePanel","method":"post"},{"path":"/panel/api/server/setUpdateChannel","method":"post"},{"path":"/panel/api/server/updateGeofile","method":"post"},{"path":"/panel/api/server/updateGeofile/{fileName}","method":"post"},{"path":"/panel/api/server/logs/{count}","method":"post"},{"path":"/panel/api/server/xraylogs/{count}","method":"post"},{"path":"/panel/api/server/amneziawglogs/{count}","method":"post"},{"path":"/panel/api/server/importDB","method":"post"},{"path":"/panel/api/server/getNewEchCert","method":"post"},{"path":"/panel/api/server/getCertHash","method":"post"},{"path":"/panel/api/server/getRemoteCertHash","method":"post"},{"path":"/panel/api/server/scanRealityTarget","method":"post"},{"path":"/panel/api/server/scanRealityTargets","method":"post"},{"path":"/panel/api/server/clientIps","method":"get"},{"path":"/panel/api/server/clientIps","method":"post"}]} showTitle />
</>
);
}
@@ -3,6 +3,7 @@
"icon": "ServerCog",
"pages": [
"reverse-proxy",
"system-monitoring",
"multi-node",
"outbounds-routing",
"backup-restore",
@@ -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) آمده‌اند.
+49 -8
View File
@@ -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"
}