mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-12-18 05:04:40 +03:00
new - show cores, public ipv4 and ipv6
logical Processors you can see them on first page
This commit is contained in:
@@ -38,9 +38,11 @@ const (
|
||||
)
|
||||
|
||||
type Status struct {
|
||||
T time.Time `json:"-"`
|
||||
Cpu float64 `json:"cpu"`
|
||||
Mem struct {
|
||||
T time.Time `json:"-"`
|
||||
Cpu float64 `json:"cpu"`
|
||||
CpuCores int `json:"cpuCores"`
|
||||
LogicalProcessors int `json:"logicalProcessors"`
|
||||
Mem struct {
|
||||
Current uint64 `json:"current"`
|
||||
Total uint64 `json:"total"`
|
||||
} `json:"mem"`
|
||||
@@ -69,6 +71,10 @@ type Status struct {
|
||||
Sent uint64 `json:"sent"`
|
||||
Recv uint64 `json:"recv"`
|
||||
} `json:"netTraffic"`
|
||||
PublicIP struct {
|
||||
IPv4 string `json:"ipv4"`
|
||||
IPv6 string `json:"ipv6"`
|
||||
} `json:"publicIP"`
|
||||
}
|
||||
|
||||
type Release struct {
|
||||
@@ -80,6 +86,33 @@ type ServerService struct {
|
||||
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 {
|
||||
now := time.Now()
|
||||
status := &Status{
|
||||
@@ -93,6 +126,13 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
|
||||
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()
|
||||
if err != nil {
|
||||
logger.Warning("get uptime failed:", err)
|
||||
@@ -161,6 +201,9 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
|
||||
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() {
|
||||
status.Xray.State = Running
|
||||
status.Xray.ErrorMsg = ""
|
||||
|
||||
Reference in New Issue
Block a user