mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-10-13 19:49:12 +00:00
Compare commits
4 commits
b65ec83c39
...
a824875c4f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a824875c4f | ||
![]() |
cafcb250ec | ||
![]() |
e7cfee570b | ||
![]() |
90c3529301 |
5 changed files with 44 additions and 28 deletions
|
@ -53,7 +53,7 @@ install_base() {
|
||||||
arch | manjaro | parch)
|
arch | manjaro | parch)
|
||||||
pacman -Syu && pacman -Syu --noconfirm wget curl tar tzdata
|
pacman -Syu && pacman -Syu --noconfirm wget curl tar tzdata
|
||||||
;;
|
;;
|
||||||
opensuse-tumbleweed)
|
opensuse-tumbleweed | opensuse-leap)
|
||||||
zypper refresh && zypper -q install -y wget curl tar timezone
|
zypper refresh && zypper -q install -y wget curl tar timezone
|
||||||
;;
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
|
|
|
@ -76,7 +76,7 @@ install_base() {
|
||||||
ubuntu | debian | armbian)
|
ubuntu | debian | armbian)
|
||||||
apt-get update >/dev/null 2>&1 && apt-get install -y -q wget curl tar tzdata >/dev/null 2>&1
|
apt-get update >/dev/null 2>&1 && apt-get install -y -q wget curl tar tzdata >/dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
centos | almalinux | rocky | ol)
|
centos | rhel | almalinux | rocky | ol)
|
||||||
yum -y update >/dev/null 2>&1 && yum install -y -q wget curl tar tzdata >/dev/null 2>&1
|
yum -y update >/dev/null 2>&1 && yum install -y -q wget curl tar tzdata >/dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
fedora | amzn | virtuozzo)
|
fedora | amzn | virtuozzo)
|
||||||
|
@ -85,7 +85,7 @@ install_base() {
|
||||||
arch | manjaro | parch)
|
arch | manjaro | parch)
|
||||||
pacman -Syu >/dev/null 2>&1 && pacman -Syu --noconfirm wget curl tar tzdata >/dev/null 2>&1
|
pacman -Syu >/dev/null 2>&1 && pacman -Syu --noconfirm wget curl tar tzdata >/dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
opensuse-tumbleweed)
|
opensuse-tumbleweed | opensuse-leap)
|
||||||
zypper refresh >/dev/null 2>&1 && zypper -q install -y wget curl tar timezone >/dev/null 2>&1
|
zypper refresh >/dev/null 2>&1 && zypper -q install -y wget curl tar timezone >/dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
|
|
|
@ -37,13 +37,19 @@ func (j *PeriodicTrafficResetJob) Run() {
|
||||||
resetCount := 0
|
resetCount := 0
|
||||||
|
|
||||||
for _, inbound := range inbounds {
|
for _, inbound := range inbounds {
|
||||||
if err := j.inboundService.ResetAllClientTraffics(inbound.Id); err != nil {
|
resetInboundErr := j.inboundService.ResetAllTraffics()
|
||||||
logger.Warning("Failed to reset traffic for inbound", inbound.Id, ":", err)
|
if resetInboundErr != nil {
|
||||||
continue
|
logger.Warning("Failed to reset traffic for inbound", inbound.Id, ":", resetInboundErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetClientErr := j.inboundService.ResetAllClientTraffics(inbound.Id)
|
||||||
|
if resetClientErr != nil {
|
||||||
|
logger.Warning("Failed to reset traffic for all users of inbound", inbound.Id, ":", resetClientErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resetInboundErr == nil && resetClientErr == nil {
|
||||||
resetCount++
|
resetCount++
|
||||||
logger.Infof("Reset traffic for inbound %d (%s)", inbound.Id, inbound.Remark)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if resetCount > 0 {
|
if resetCount > 0 {
|
||||||
|
|
|
@ -110,6 +110,7 @@ type ServerService struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
lastCPUTimes cpu.TimesStat
|
lastCPUTimes cpu.TimesStat
|
||||||
hasLastCPUSample bool
|
hasLastCPUSample bool
|
||||||
|
hasNativeCPUSample bool
|
||||||
emaCPU float64
|
emaCPU float64
|
||||||
cpuHistory []CPUSample
|
cpuHistory []CPUSample
|
||||||
cachedCpuSpeedMhz float64
|
cachedCpuSpeedMhz float64
|
||||||
|
@ -432,10 +433,15 @@ func (s *ServerService) AppendCpuSample(t time.Time, v float64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerService) sampleCPUUtilization() (float64, error) {
|
func (s *ServerService) sampleCPUUtilization() (float64, error) {
|
||||||
// Prefer native Windows API to avoid external deps for CPU percent
|
// Try native platform-specific CPU implementation first (Windows, Linux, macOS)
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
if pct, err := sys.CPUPercentRaw(); err == nil {
|
if pct, err := sys.CPUPercentRaw(); err == nil {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
|
// First call to native method returns 0 (initializes baseline)
|
||||||
|
if !s.hasNativeCPUSample {
|
||||||
|
s.hasNativeCPUSample = true
|
||||||
|
s.mu.Unlock()
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
// Smooth with EMA
|
// Smooth with EMA
|
||||||
const alpha = 0.3
|
const alpha = 0.3
|
||||||
if s.emaCPU == 0 {
|
if s.emaCPU == 0 {
|
||||||
|
@ -448,7 +454,6 @@ func (s *ServerService) sampleCPUUtilization() (float64, error) {
|
||||||
return val, nil
|
return val, nil
|
||||||
}
|
}
|
||||||
// If native call fails, fall back to gopsutil times
|
// If native call fails, fall back to gopsutil times
|
||||||
}
|
|
||||||
// Read aggregate CPU times (all CPUs combined)
|
// Read aggregate CPU times (all CPUs combined)
|
||||||
times, err := cpu.Times(false)
|
times, err := cpu.Times(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -471,17 +476,16 @@ func (s *ServerService) sampleCPUUtilization() (float64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute busy and total deltas
|
// Compute busy and total deltas
|
||||||
|
// Note: Guest and GuestNice times are already included in User and Nice respectively,
|
||||||
|
// so we exclude them to avoid double-counting (Linux kernel accounting)
|
||||||
idleDelta := cur.Idle - s.lastCPUTimes.Idle
|
idleDelta := cur.Idle - s.lastCPUTimes.Idle
|
||||||
// Sum of busy deltas (exclude Idle)
|
|
||||||
busyDelta := (cur.User - s.lastCPUTimes.User) +
|
busyDelta := (cur.User - s.lastCPUTimes.User) +
|
||||||
(cur.System - s.lastCPUTimes.System) +
|
(cur.System - s.lastCPUTimes.System) +
|
||||||
(cur.Nice - s.lastCPUTimes.Nice) +
|
(cur.Nice - s.lastCPUTimes.Nice) +
|
||||||
(cur.Iowait - s.lastCPUTimes.Iowait) +
|
(cur.Iowait - s.lastCPUTimes.Iowait) +
|
||||||
(cur.Irq - s.lastCPUTimes.Irq) +
|
(cur.Irq - s.lastCPUTimes.Irq) +
|
||||||
(cur.Softirq - s.lastCPUTimes.Softirq) +
|
(cur.Softirq - s.lastCPUTimes.Softirq) +
|
||||||
(cur.Steal - s.lastCPUTimes.Steal) +
|
(cur.Steal - s.lastCPUTimes.Steal)
|
||||||
(cur.Guest - s.lastCPUTimes.Guest) +
|
|
||||||
(cur.GuestNice - s.lastCPUTimes.GuestNice)
|
|
||||||
|
|
||||||
totalDelta := busyDelta + idleDelta
|
totalDelta := busyDelta + idleDelta
|
||||||
|
|
||||||
|
|
10
x-ui.sh
10
x-ui.sh
|
@ -189,9 +189,9 @@ reset_user() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -rp "Please set the login username [default is a random username]: " config_account
|
read -rp "Please set the login username [default is a random username]: " config_account
|
||||||
[[ -z $config_account ]] && config_account=$(date +%s%N | md5sum | cut -c 1-8)
|
[[ -z $config_account ]] && config_account=$(gen_random_string 10)
|
||||||
read -rp "Please set the login password [default is a random password]: " config_password
|
read -rp "Please set the login password [default is a random password]: " config_password
|
||||||
[[ -z $config_password ]] && config_password=$(date +%s%N | md5sum | cut -c 1-8)
|
[[ -z $config_password ]] && config_password=$(gen_random_string 18)
|
||||||
|
|
||||||
read -rp "Do you want to disable currently configured two-factor authentication? (y/n): " twoFactorConfirm
|
read -rp "Do you want to disable currently configured two-factor authentication? (y/n): " twoFactorConfirm
|
||||||
if [[ $twoFactorConfirm != "y" && $twoFactorConfirm != "Y" ]]; then
|
if [[ $twoFactorConfirm != "y" && $twoFactorConfirm != "Y" ]]; then
|
||||||
|
@ -518,6 +518,9 @@ enable_bbr() {
|
||||||
arch | manjaro | parch)
|
arch | manjaro | parch)
|
||||||
pacman -Sy --noconfirm ca-certificates
|
pacman -Sy --noconfirm ca-certificates
|
||||||
;;
|
;;
|
||||||
|
opensuse-tumbleweed | opensuse-leap)
|
||||||
|
zypper refresh && zypper -q install -y ca-certificates
|
||||||
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
apk add ca-certificates
|
apk add ca-certificates
|
||||||
;;
|
;;
|
||||||
|
@ -1073,6 +1076,9 @@ ssl_cert_issue() {
|
||||||
arch | manjaro | parch)
|
arch | manjaro | parch)
|
||||||
pacman -Sy --noconfirm socat
|
pacman -Sy --noconfirm socat
|
||||||
;;
|
;;
|
||||||
|
opensuse-tumbleweed | opensuse-leap)
|
||||||
|
zypper refresh && zypper -q install -y socat
|
||||||
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
apk add socat
|
apk add socat
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue