Browse Source

add panel usage to main page

MHSanaei 1 year ago
parent
commit
e00c3f1823
4 changed files with 57 additions and 23 deletions
  1. 28 15
      web/html/xui/index.html
  2. 1 2
      web/job/check_client_ip_job.go
  3. 15 0
      web/service/server.go
  4. 13 6
      xray/process.go

+ 28 - 15
web/html/xui/index.html

@@ -108,21 +108,30 @@
                     </a-col>
                     <a-col :sm="24" :md="12">
                         <a-card hoverable :class="themeSwitcher.darkCardClass">
-                            <a-row>
-                                <a-col :span="12">
-                                    {{ i18n "pages.index.systemLoad" }}: [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
-                                    <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>
+                            {{ i18n "pages.index.operationHours" }}:
+                            Xray:
+                            <a-tag color="green">[[ formatSecond(status.appStats.uptime) ]]</a-tag>
+                            OS:
+                            <a-tag color="green">[[ formatSecond(status.uptime) ]]</a-tag>
+                        </a-card>
+                    </a-col>
+                    <a-col :sm="24" :md="12">
+                        <a-card hoverable :class="themeSwitcher.darkCardClass">
+                            {{ i18n "pages.index.systemLoad" }}: [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
+                            <a-tooltip>
+                                <template slot="title">
+                                    {{ i18n "pages.index.systemLoadDesc" }}
+                                </template>
+                                <a-icon type="question-circle" theme="filled"></a-icon>
+                            </a-tooltip>
+                        </a-card>
+                    </a-col>
+                    <a-col :sm="24" :md="12">
+                        <a-card hoverable :class="themeSwitcher.darkCardClass">
+                            {{ i18n "usage"}}:
+                            Memory [[ sizeFormat(status.appStats.mem) ]] -
+                            Threads [[ status.appStats.threads ]]
+                            </a-tooltip>
                         </a-card>
                     </a-col>
                     <a-col :sm="24" :md="12">
@@ -361,6 +370,8 @@
             this.tcpCount = 0;
             this.udpCount = 0;
             this.uptime = 0;
+            this.appUptime = 0;
+            this.appStats = {threads: 0, mem: 0, uptime: 0};
             this.xray = { state: State.Stop, errorMsg: "", version: "", color: "" };
 
             if (data == null) {
@@ -379,6 +390,8 @@
             this.tcpCount = data.tcpCount;
             this.udpCount = data.udpCount;
             this.uptime = data.uptime;
+            this.appUptime = data.appUptime;
+            this.appStats = data.appStats;
             this.xray = data.xray;
             switch (this.xray.state) {
                 case State.Running:

+ 1 - 2
web/job/check_client_ip_job.go

@@ -15,7 +15,7 @@ import (
 	"x-ui/xray"
 )
 
-type CheckClientIpJob struct {}
+type CheckClientIpJob struct{}
 
 var job *CheckClientIpJob
 var disAllowedIps []string
@@ -31,7 +31,6 @@ func NewCheckClientIpJob() *CheckClientIpJob {
 }
 
 func (j *CheckClientIpJob) Run() {
-	logger.Debug("Check Client IP Job...")
 
 	// create files required for iplimit if not exists
 	for i := 0; i < len(ipFiles); i++ {

+ 15 - 0
web/service/server.go

@@ -77,6 +77,11 @@ type Status struct {
 		IPv4 string `json:"ipv4"`
 		IPv6 string `json:"ipv6"`
 	} `json:"publicIP"`
+	AppStats struct {
+		Threads uint32 `json:"threads"`
+		Mem     uint64 `json:"mem"`
+		Uptime  uint64 `json:"uptime"`
+	} `json:"appStats"`
 }
 
 type Release struct {
@@ -220,6 +225,16 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
 		status.Xray.ErrorMsg = s.xrayService.GetXrayResult()
 	}
 	status.Xray.Version = s.xrayService.GetXrayVersion()
+	var rtm runtime.MemStats
+	runtime.ReadMemStats(&rtm)
+
+	status.AppStats.Mem = rtm.Sys
+	status.AppStats.Threads = uint32(runtime.NumGoroutine())
+	if p.IsRunning() {
+		status.AppStats.Uptime = p.GetUptime()
+	} else {
+		status.AppStats.Uptime = 0
+	}
 
 	return status
 }

+ 13 - 6
xray/process.go

@@ -13,6 +13,7 @@ import (
 	"strings"
 	"sync"
 	"syscall"
+	"time"
 
 	"x-ui/config"
 	"x-ui/logger"
@@ -101,16 +102,18 @@ type process struct {
 	version string
 	apiPort int
 
-	config  *Config
-	lines   *queue.Queue
-	exitErr error
+	config    *Config
+	lines     *queue.Queue
+	exitErr   error
+	startTime time.Time
 }
 
 func newProcess(config *Config) *process {
 	return &process{
-		version: "Unknown",
-		config:  config,
-		lines:   queue.New(100),
+		version:   "Unknown",
+		config:    config,
+		lines:     queue.New(100),
+		startTime: time.Now(),
 	}
 }
 
@@ -154,6 +157,10 @@ func (p *Process) GetConfig() *Config {
 	return p.config
 }
 
+func (p *Process) GetUptime() uint64 {
+	return uint64(time.Since(p.startTime).Seconds())
+}
+
 func (p *process) refreshAPIPort() {
 	for _, inbound := range p.config.InboundConfigs {
 		if inbound.Tag == "api" {