Skip to content

Commit

Permalink
add panel usage to main page
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSanaei committed Aug 8, 2023
1 parent 05bc655 commit e00c3f1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 23 deletions.
43 changes: 28 additions & 15 deletions web/html/xui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -361,6 +370,8 @@ <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
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) {
Expand All @@ -379,6 +390,8 @@ <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
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:
Expand Down
3 changes: 1 addition & 2 deletions web/job/check_client_ip_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"x-ui/xray"
)

type CheckClientIpJob struct {}
type CheckClientIpJob struct{}

var job *CheckClientIpJob
var disAllowedIps []string
Expand All @@ -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++ {
Expand Down
15 changes: 15 additions & 0 deletions web/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
19 changes: 13 additions & 6 deletions xray/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"sync"
"syscall"
"time"

"x-ui/config"
"x-ui/logger"
Expand Down Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit e00c3f1

Please sign in to comment.