Skip to content

Commit

Permalink
New - CPU Speed
Browse files Browse the repository at this point in the history
logical Processors  removed
  • Loading branch information
MHSanaei committed May 25, 2023
1 parent b3f7a65 commit 15211f8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
13 changes: 13 additions & 0 deletions web/assets/js/util/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ function sizeFormat(size) {
}
}

function cpuSpeedFormat(speed) {
const GHz = speed / 1000;
return GHz.toFixed(2) + " GHz";
}

function cpuCoreFormat(cores) {
if (cores === 1) {
return "1 Core";
} else {
return cores + " Cores";
}
}

function base64(str) {
return Base64.encode(str);
}
Expand Down
16 changes: 8 additions & 8 deletions web/html/xui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
:stroke-color="status.cpu.color"
:class="themeSwitcher.darkCardClass"
:percent="status.cpu.percent"></a-progress>
<div>Cores: [[ status.cpuCores ]]</div>
<div>Logical Procs: [[ status.logicalProcessors ]]</div>
<div>CPU: [[ cpuCoreFormat(status.cpuCores) ]]</div>
<div>Speed: [[ cpuSpeedFormat(status.cpuSpeedMhz) ]]</div>
</a-col>
<a-col :span="12" style="text-align: center">
<a-progress type="dashboard" status="normal"
Expand Down Expand Up @@ -178,7 +178,7 @@
<a-row>
<a-col :span="12">
<a-icon type="arrow-up"></a-icon>
[[ sizeFormat(status.netIO.up) ]] / S
[[ sizeFormat(status.netIO.up) ]]/S
<a-tooltip>
<template slot="title">
{{ i18n "pages.index.upSpeed" }}
Expand All @@ -188,7 +188,7 @@
</a-col>
<a-col :span="12">
<a-icon type="arrow-down"></a-icon>
[[ sizeFormat(status.netIO.down) ]] / S
[[ sizeFormat(status.netIO.down) ]]/S
<a-tooltip>
<template slot="title">
{{ i18n "pages.index.downSpeed" }}
Expand Down Expand Up @@ -334,6 +334,8 @@ <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
class Status {
constructor(data) {
this.cpu = new CurTotal(0, 0);
this.cpuCores = 0;
this.cpuSpeedMhz = 0;
this.disk = new CurTotal(0, 0);
this.loads = [0, 0, 0];
this.mem = new CurTotal(0, 0);
Expand All @@ -343,15 +345,15 @@ <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
this.swap = new CurTotal(0, 0);
this.tcpCount = 0;
this.udpCount = 0;
this.cpuCores = 0;
this.logicalProcessors = 0;
this.uptime = 0;
this.xray = { state: State.Stop, errorMsg: "", version: "", color: "" };

if (data == null) {
return;
}
this.cpu = new CurTotal(data.cpu, 100);
this.cpuCores = data.cpuCores;
this.cpuSpeedMhz = data.cpuSpeedMhz;
this.disk = new CurTotal(data.disk.current, data.disk.total);
this.loads = data.loads.map(load => toFixed(load, 2));
this.mem = new CurTotal(data.mem.current, data.mem.total);
Expand All @@ -361,8 +363,6 @@ <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
this.swap = new CurTotal(data.swap.current, data.swap.total);
this.tcpCount = data.tcpCount;
this.udpCount = data.udpCount;
this.cpuCores = data.cpuCores;
this.logicalProcessors = data.logicalProcessors;
this.uptime = data.uptime;
this.xray = data.xray;
switch (this.xray.state) {
Expand Down
20 changes: 14 additions & 6 deletions web/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ const (
)

type Status struct {
T time.Time `json:"-"`
Cpu float64 `json:"cpu"`
CpuCores int `json:"cpuCores"`
LogicalProcessors int `json:"logicalProcessors"`
Mem struct {
T time.Time `json:"-"`
Cpu float64 `json:"cpu"`
CpuCores int `json:"cpuCores"`
CpuSpeedMhz float64 `json:"cpuSpeedMhz"`
Mem struct {
Current uint64 `json:"current"`
Total uint64 `json:"total"`
} `json:"mem"`
Expand Down Expand Up @@ -131,7 +131,15 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
logger.Warning("get cpu cores count failed:", err)
}

status.LogicalProcessors = runtime.NumCPU()
cpuInfos, err := cpu.Info()
if err != nil {
logger.Warning("get cpu info failed:", err)
} else if len(cpuInfos) > 0 {
cpuInfo := cpuInfos[0]
status.CpuSpeedMhz = cpuInfo.Mhz // setting CPU speed in MHz
} else {
logger.Warning("could not find cpu info")
}

upTime, err := host.Uptime()
if err != nil {
Expand Down

0 comments on commit 15211f8

Please sign in to comment.