new - show cores, public ipv4 and ipv6

logical Processors
you can see them on first page
This commit is contained in:
MHSanaei 2023-05-25 03:11:09 +03:30
parent 76f70ce1e9
commit 896cc5386c
7 changed files with 135 additions and 40 deletions

View file

@ -5,7 +5,9 @@ const ONE_TB = ONE_GB * 1024;
const ONE_PB = ONE_TB * 1024; const ONE_PB = ONE_TB * 1024;
function sizeFormat(size) { function sizeFormat(size) {
if (size < ONE_KB) { if (size < 0) {
return "0 B";
} else if (size < ONE_KB) {
return size.toFixed(0) + " B"; return size.toFixed(0) + " B";
} else if (size < ONE_MB) { } else if (size < ONE_MB) {
return (size / ONE_KB).toFixed(2) + " KB"; return (size / ONE_KB).toFixed(2) + " KB";

View file

@ -34,7 +34,8 @@
:stroke-color="status.cpu.color" :stroke-color="status.cpu.color"
:class="themeSwitcher.darkCardClass" :class="themeSwitcher.darkCardClass"
:percent="status.cpu.percent"></a-progress> :percent="status.cpu.percent"></a-progress>
<div>CPU</div> <div>Cores: [[ status.cpuCores ]]</div>
<div>Logical Procs: [[ status.logicalProcessors ]]</div>
</a-col> </a-col>
<a-col :span="12" style="text-align: center"> <a-col :span="12" style="text-align: center">
<a-progress type="dashboard" status="normal" <a-progress type="dashboard" status="normal"
@ -84,14 +85,10 @@
</a-col> </a-col>
<a-col :sm="24" :md="12"> <a-col :sm="24" :md="12">
<a-card hoverable :class="themeSwitcher.darkCardClass"> <a-card hoverable :class="themeSwitcher.darkCardClass">
{{ i18n "pages.index.operationHours" }}: {{ i18n "menu.link" }}:
<a-tag color="green">[[ formatSecond(status.uptime) ]]</a-tag> <a-tag color="blue" style="cursor: pointer;" @click="openLogs(20)">{{ i18n "pages.index.logs" }}</a-tag>
<a-tooltip> <a-tag color="blue" style="cursor: pointer;" @click="openConfig">{{ i18n "pages.index.config" }}</a-tag>
<template slot="title"> <a-tag color="blue" style="cursor: pointer;" @click="openBackup">{{ i18n "pages.index.backup" }}</a-tag>
{{ i18n "pages.index.operationHoursDesc" }}
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</a-card> </a-card>
</a-col> </a-col>
<a-col :sm="24" :md="12"> <a-col :sm="24" :md="12">
@ -111,26 +108,69 @@
</a-col> </a-col>
<a-col :sm="24" :md="12"> <a-col :sm="24" :md="12">
<a-card hoverable :class="themeSwitcher.darkCardClass"> <a-card hoverable :class="themeSwitcher.darkCardClass">
{{ i18n "menu.link" }}: <a-row>
<a-tag color="blue" style="cursor: pointer;" @click="openLogs(20)">{{ i18n "pages.index.logs" }}</a-tag> <a-col :span="12">
<a-tag color="blue" style="cursor: pointer;" @click="openConfig">{{ i18n "pages.index.config" }}</a-tag> {{ i18n "pages.index.systemLoad" }}: [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
<a-tag color="blue" style="cursor: pointer;" @click="openBackup">{{ i18n "pages.index.backup" }}</a-tag> <a-tooltip>
<template slot="title">
{{ i18n "pages.index.systemLoadDesc" }}
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</a-col>
<a-col :span="12">
{{ i18n "pages.index.operationHours" }}:
<a-tag color="green">[[ formatSecond(status.uptime) ]]</a-tag>
</a-col>
</a-row>
</a-card> </a-card>
</a-col> </a-col>
<a-col :sm="24" :md="12"> <a-col :sm="24" :md="12">
<a-card hoverable :class="themeSwitcher.darkCardClass"> <a-card hoverable :class="themeSwitcher.darkCardClass">
{{ i18n "pages.index.systemLoad" }}: [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]] <a-row>
<a-col :span="12">
ipv4:
<a-tooltip>
<template slot="title">
[[ status.publicIP.ipv4 ]]
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</a-col>
<a-col :span="12">
ipv6:
<a-tooltip>
<template slot="title">
[[ status.publicIP.ipv6 ]]
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</a-col>
</a-row>
</a-card> </a-card>
</a-col> </a-col>
<a-col :sm="24" :md="12"> <a-col :sm="24" :md="12">
<a-card hoverable :class="themeSwitcher.darkCardClass"> <a-card hoverable :class="themeSwitcher.darkCardClass">
TCP / UDP {{ i18n "pages.index.connectionCount" }}: [[ status.tcpCount ]] / [[ status.udpCount ]] <a-row>
<a-tooltip> <a-col :span="12">
<template slot="title"> TCP: [[ status.tcpCount ]]
{{ i18n "pages.index.connectionCountDesc" }} <a-tooltip>
</template> <template slot="title">
<a-icon type="question-circle" theme="filled"></a-icon> {{ i18n "pages.index.connectionTcpCountDesc" }}
</a-tooltip> </template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</a-col>
<a-col :span="12">
UDP: [[ status.udpCount ]]
<a-tooltip>
<template slot="title">
{{ i18n "pages.index.connectionUdpCountDesc" }}
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</a-col>
</a-row>
</a-card> </a-card>
</a-col> </a-col>
<a-col :sm="24" :md="12"> <a-col :sm="24" :md="12">
@ -299,9 +339,12 @@
this.mem = new CurTotal(0, 0); this.mem = new CurTotal(0, 0);
this.netIO = { up: 0, down: 0 }; this.netIO = { up: 0, down: 0 };
this.netTraffic = { sent: 0, recv: 0 }; this.netTraffic = { sent: 0, recv: 0 };
this.publicIP = { ipv4: 0, ipv6: 0 };
this.swap = new CurTotal(0, 0); this.swap = new CurTotal(0, 0);
this.tcpCount = 0; this.tcpCount = 0;
this.udpCount = 0; this.udpCount = 0;
this.cpuCores = 0;
this.logicalProcessors = 0;
this.uptime = 0; this.uptime = 0;
this.xray = { state: State.Stop, errorMsg: "", version: "", color: "" }; this.xray = { state: State.Stop, errorMsg: "", version: "", color: "" };
@ -314,9 +357,12 @@
this.mem = new CurTotal(data.mem.current, data.mem.total); this.mem = new CurTotal(data.mem.current, data.mem.total);
this.netIO = data.netIO; this.netIO = data.netIO;
this.netTraffic = data.netTraffic; this.netTraffic = data.netTraffic;
this.publicIP = data.publicIP;
this.swap = new CurTotal(data.swap.current, data.swap.total); this.swap = new CurTotal(data.swap.current, data.swap.total);
this.tcpCount = data.tcpCount; this.tcpCount = data.tcpCount;
this.udpCount = data.udpCount; this.udpCount = data.udpCount;
this.cpuCores = data.cpuCores;
this.logicalProcessors = data.logicalProcessors;
this.uptime = data.uptime; this.uptime = data.uptime;
this.xray = data.xray; this.xray = data.xray;
switch (this.xray.state) { switch (this.xray.state) {

View file

@ -38,9 +38,11 @@ const (
) )
type Status struct { type Status struct {
T time.Time `json:"-"` T time.Time `json:"-"`
Cpu float64 `json:"cpu"` Cpu float64 `json:"cpu"`
Mem struct { CpuCores int `json:"cpuCores"`
LogicalProcessors int `json:"logicalProcessors"`
Mem struct {
Current uint64 `json:"current"` Current uint64 `json:"current"`
Total uint64 `json:"total"` Total uint64 `json:"total"`
} `json:"mem"` } `json:"mem"`
@ -69,6 +71,10 @@ type Status struct {
Sent uint64 `json:"sent"` Sent uint64 `json:"sent"`
Recv uint64 `json:"recv"` Recv uint64 `json:"recv"`
} `json:"netTraffic"` } `json:"netTraffic"`
PublicIP struct {
IPv4 string `json:"ipv4"`
IPv6 string `json:"ipv6"`
} `json:"publicIP"`
} }
type Release struct { type Release struct {
@ -80,6 +86,33 @@ type ServerService struct {
inboundService InboundService inboundService InboundService
} }
const DebugMode = false // Set to true during development
func getPublicIP(url string) string {
resp, err := http.Get(url)
if err != nil {
if DebugMode {
logger.Warning("get public IP failed:", err)
}
return "N/A"
}
defer resp.Body.Close()
ip, err := io.ReadAll(resp.Body)
if err != nil {
if DebugMode {
logger.Warning("read public IP failed:", err)
}
return "N/A"
}
if string(ip) == "" {
return "N/A" // default value
}
return string(ip)
}
func (s *ServerService) GetStatus(lastStatus *Status) *Status { func (s *ServerService) GetStatus(lastStatus *Status) *Status {
now := time.Now() now := time.Now()
status := &Status{ status := &Status{
@ -93,6 +126,13 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
status.Cpu = percents[0] status.Cpu = percents[0]
} }
status.CpuCores, err = cpu.Counts(false)
if err != nil {
logger.Warning("get cpu cores count failed:", err)
}
status.LogicalProcessors = runtime.NumCPU()
upTime, err := host.Uptime() upTime, err := host.Uptime()
if err != nil { if err != nil {
logger.Warning("get uptime failed:", err) logger.Warning("get uptime failed:", err)
@ -161,6 +201,9 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
logger.Warning("get udp connections failed:", err) logger.Warning("get udp connections failed:", err)
} }
status.PublicIP.IPv4 = getPublicIP("https://api.ipify.org")
status.PublicIP.IPv6 = getPublicIP("https://api6.ipify.org")
if s.xrayService.IsXrayRunning() { if s.xrayService.IsXrayRunning() {
status.Xray.State = Running status.Xray.State = Running
status.Xray.ErrorMsg = "" status.Xray.ErrorMsg = ""

View file

@ -75,14 +75,15 @@
"xrayStatus" = "Xray Status" "xrayStatus" = "Xray Status"
"stopXray" = "Stop" "stopXray" = "Stop"
"restartXray" = "Restart" "restartXray" = "Restart"
"xraySwitch" = "Switch Version" "xraySwitch" = "SwitchV"
"xraySwitchClick" = "Choose the version you want to switch to." "xraySwitchClick" = "Choose the version you want to switch to."
"xraySwitchClickDesk" = "Choose wisely, as older versions may not be compatible with current configurations." "xraySwitchClickDesk" = "Choose wisely, as older versions may not be compatible with current configurations."
"operationHours" = "Operation Hours" "operationHours" = "Uptime"
"operationHoursDesc" = "System uptime: time since startup."
"systemLoad" = "System Load" "systemLoad" = "System Load"
"systemLoadDesc" = "system load average for the past 1, 5, and 15 minutes"
"connectionTcpCountDesc" = "Total TCP connections across all network cards."
"connectionUdpCountDesc" = "Total UDP connections across all network cards."
"connectionCount" = "Number of Connections" "connectionCount" = "Number of Connections"
"connectionCountDesc" = "Total connections across all network cards."
"upSpeed" = "Total upload speed for all network cards." "upSpeed" = "Total upload speed for all network cards."
"downSpeed" = "Total download speed for all network cards." "downSpeed" = "Total download speed for all network cards."
"totalSent" = "Total upload traffic of all network cards since system startup." "totalSent" = "Total upload traffic of all network cards since system startup."

View file

@ -78,11 +78,12 @@
"xraySwitch" = "تغییر ورژن" "xraySwitch" = "تغییر ورژن"
"xraySwitchClick" = "ورژن مورد نظر را انتخاب کنید" "xraySwitchClick" = "ورژن مورد نظر را انتخاب کنید"
"xraySwitchClickDesk" = "لطفا با دقت انتخاب کنید ، در صورت انتخاب اشتباه امکان قطعی سیستم وجود دارد " "xraySwitchClickDesk" = "لطفا با دقت انتخاب کنید ، در صورت انتخاب اشتباه امکان قطعی سیستم وجود دارد "
"operationHours" = "مدت فعالیت" "operationHours" = "آپ تایم سیستم"
"operationHoursDesc" = "مدت فعالیت سیستم بعد از روشن شدن" "systemLoad" = "بار سیستم"
"systemLoad" = "بار روی سیستم" "systemLoadDesc" = "میانگین بار سیستم برای 1، 5 و 15 دقیقه گذشته"
"connectionTcpCountDesc" = "مجموع اتصالات TCP در تمام کارت های شبکه"
"connectionUdpCountDesc" = "مجموع اتصالات UDP در تمام کارت های شبکه"
"connectionCount" = "تعداد کانکشن ها" "connectionCount" = "تعداد کانکشن ها"
"connectionCountDesc" = "تعداد کانکشن ها برای کل شبکه"
"upSpeed" = "سرعت آپلود در حال حاضر سیستم" "upSpeed" = "سرعت آپلود در حال حاضر سیستم"
"downSpeed" = "سرعت دانلود در حال حاضر سیستم" "downSpeed" = "سرعت دانلود در حال حاضر سیستم"
"totalSent" = "جمع کل ترافیک آپلود مصرفی" "totalSent" = "جمع کل ترافیک آپلود مصرفی"

View file

@ -78,11 +78,12 @@
"xraySwitch" = "Переключить версию" "xraySwitch" = "Переключить версию"
"xraySwitchClick" = "Выберите желаемую версию" "xraySwitchClick" = "Выберите желаемую версию"
"xraySwitchClickDesk" = "Выбирайте внимательно, так как старые версии могут быть несовместимы с текущими конфигурациями" "xraySwitchClickDesk" = "Выбирайте внимательно, так как старые версии могут быть несовместимы с текущими конфигурациями"
"operationHours" = "Часы работы" "operationHours" = "Время работы системы"
"operationHoursDesc" = "Аптайм системы: время системы в сети"
"systemLoad" = "Системная нагрузка" "systemLoad" = "Системная нагрузка"
"systemLoadDesc" = "средняя загрузка системы за последние 1, 5 и 15 минут"
"connectionTcpCountDesc" = "Всего подключений TCP по всем сетевым картам."
"connectionUdpCountDesc" = "Общее количество подключений UDP по всем сетевым картам."
"connectionCount" = "Количество соединений" "connectionCount" = "Количество соединений"
"connectionCountDesc" = "Всего подключений по всем сетям"
"upSpeed" = "Общая скорость upload для всех сетей" "upSpeed" = "Общая скорость upload для всех сетей"
"downSpeed" = "Общая скорость download для всех сетей" "downSpeed" = "Общая скорость download для всех сетей"
"totalSent" = "Общий объем загруженных данных для всех сетей с момента запуска системы" "totalSent" = "Общий объем загруженных данных для всех сетей с момента запуска системы"

View file

@ -78,11 +78,12 @@
"xraySwitch" = "切换版本" "xraySwitch" = "切换版本"
"xraySwitchClick" = "点击你想切换的版本" "xraySwitchClick" = "点击你想切换的版本"
"xraySwitchClickDesk" = "请谨慎选择,旧版本可能配置不兼容" "xraySwitchClickDesk" = "请谨慎选择,旧版本可能配置不兼容"
"operationHours" = "运行时间" "operationHours" = "系统正常运行时间"
"operationHoursDesc" = "系统自启动以来的运行时间"
"systemLoad" = "系统负载" "systemLoad" = "系统负载"
"systemLoadDesc" = "过去 1、5 和 15 分钟的系统平均负载"
"connectionTcpCountDesc" = "所有网卡的总 TCP 连接数。"
"connectionUdpCountDesc" = "所有网卡的总 UDP 连接数。"
"connectionCount" = "连接数" "connectionCount" = "连接数"
"connectionCountDesc" = "所有网卡的总连接数"
"upSpeed" = "所有网卡的总上传速度" "upSpeed" = "所有网卡的总上传速度"
"downSpeed" = "所有网卡的总下载速度" "downSpeed" = "所有网卡的总下载速度"
"totalSent" = "系统启动以来所有网卡的总上传流量" "totalSent" = "系统启动以来所有网卡的总上传流量"