db status data for first page
This commit is contained in:
+33
-11
@@ -9,6 +9,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/alireza0/s-ui/config"
|
||||
"github.com/alireza0/s-ui/database"
|
||||
"github.com/alireza0/s-ui/database/model"
|
||||
"github.com/alireza0/s-ui/logger"
|
||||
|
||||
"github.com/sagernet/sing-box/common/tls"
|
||||
@@ -40,10 +42,11 @@ func (s *ServerService) GetStatus(request string) *map[string]interface{} {
|
||||
case "net":
|
||||
status["net"] = s.GetNetInfo()
|
||||
case "sys":
|
||||
status["uptime"] = s.GetUptime()
|
||||
status["sys"] = s.GetSystemInfo()
|
||||
case "sbd":
|
||||
status["sbd"] = s.GetSingboxInfo()
|
||||
case "db":
|
||||
status["db"] = s.GetDatabaseInfo()
|
||||
}
|
||||
}
|
||||
return &status
|
||||
@@ -59,16 +62,6 @@ func (s *ServerService) GetCpuPercent() float64 {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerService) GetUptime() uint64 {
|
||||
upTime, err := host.Uptime()
|
||||
if err != nil {
|
||||
logger.Warning("get uptime failed:", err)
|
||||
return 0
|
||||
} else {
|
||||
return upTime
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerService) GetMemInfo() map[string]interface{} {
|
||||
info := make(map[string]interface{}, 0)
|
||||
memInfo, err := mem.VirtualMemory()
|
||||
@@ -192,6 +185,7 @@ func (s *ServerService) GetSystemInfo() map[string]interface{} {
|
||||
}
|
||||
info["ipv4"] = ipv4
|
||||
info["ipv6"] = ipv6
|
||||
info["bootTime"], _ = host.BootTime()
|
||||
|
||||
return info
|
||||
}
|
||||
@@ -259,3 +253,31 @@ func (s *ServerService) generateWireGuardKey(pk string) []string {
|
||||
}
|
||||
return []string{"PrivateKey: " + wgKeys.String(), "PublicKey: " + wgKeys.PublicKey().String()}
|
||||
}
|
||||
|
||||
func (s *ServerService) GetDatabaseInfo() map[string]int64 {
|
||||
info := make(map[string]int64, 0)
|
||||
db := database.GetDB()
|
||||
if db == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var clientsCount, inboundsCount, outboundsCount, servicesCount, endpointsCount, clientUp, clientDown int64
|
||||
|
||||
db.Model(&model.Client{}).Count(&clientsCount)
|
||||
db.Model(&model.Inbound{}).Count(&inboundsCount)
|
||||
db.Model(&model.Outbound{}).Count(&outboundsCount)
|
||||
db.Model(&model.Service{}).Count(&servicesCount)
|
||||
db.Model(&model.Endpoint{}).Count(&endpointsCount)
|
||||
db.Model(&model.Client{}).Select("COALESCE(SUM(up),0)").Scan(&clientUp)
|
||||
db.Model(&model.Client{}).Select("COALESCE(SUM(down),0)").Scan(&clientDown)
|
||||
|
||||
info["clients"] = clientsCount
|
||||
info["inbounds"] = inboundsCount
|
||||
info["outbounds"] = outboundsCount
|
||||
info["services"] = servicesCount
|
||||
info["endpoints"] = endpointsCount
|
||||
info["clientUp"] = clientUp
|
||||
info["clientDown"] = clientDown
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user