[PR #3603] [MERGED] fix: handle CPU threshold error to prevent false notifications #5477

Closed
opened 2026-10-31 20:47:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/3603
Author: @kotopheiop
Created: 12/12/2025
Status: ✅ Merged
Merged: 12/12/2025
Merged by: @MHSanaei

Base: main ← Head: fix/cpu-threshold-error-handling


📝 Commits (1)

  • f40278e fix: handle CPU threshold error to prevent false notifications

📊 Changes

1 file changed (+5 additions, -1 deletions)

View changed files

📝 web/job/check_cpu_usage.go (+5 -1)

📄 Description

This PR fixes a bug in the CPU monitoring job where Telegram notifications were being sent with incorrect threshold values (showing 0% instead of the configured threshold).

Previously, when GetTgCpu() failed, the error was ignored and threshold defaulted to 0, causing notifications to be sent for any CPU usage.

Now the job properly checks for errors and skips notifications if:

  • The threshold cannot be retrieved (error)
  • The threshold is not set or is 0

This ensures notifications are only sent when CPU usage exceeds the configured threshold value from settings.

Which part of the application is affected by the change?

  • Frontend
  • Backend

Type of Changes

  • Bug fix
  • New feature
  • Refactoring
  • Other

Screenshots

image image

Additional Notes

Problem:
Users were receiving Telegram notifications showing "CPU load exceeds threshold value 0%" even though they had configured a different threshold value (e.g., 85%) in the settings.

Root Cause:
In CheckCpuJob.Run(), the error from GetTgCpu() was ignored using threshold, _ := .... When an error occurred, the threshold defaulted to 0, causing the condition percent[0] > float64(threshold) to be true for any positive CPU usage.

Solution:

  • Added proper error handling for GetTgCpu() call
  • Added validation to skip notifications if threshold is 0 or cannot be retrieved
  • Notifications are now only sent when CPU usage actually exceeds the configured threshold

Testing:

  • Code compiles successfully
  • The fix prevents false notifications with 0% threshold
  • Notifications will only be sent when CPU usage exceeds the configured value from settings

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/3603 **Author:** [@kotopheiop](https://github.com/kotopheiop) **Created:** 12/12/2025 **Status:** ✅ Merged **Merged:** 12/12/2025 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/cpu-threshold-error-handling` --- ### 📝 Commits (1) - [`f40278e`](https://github.com/MHSanaei/3x-ui/commit/f40278e7e40a43a88580795f8230ed86e92bf9a7) fix: handle CPU threshold error to prevent false notifications ### 📊 Changes **1 file changed** (+5 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `web/job/check_cpu_usage.go` (+5 -1) </details> ### 📄 Description This PR fixes a bug in the CPU monitoring job where Telegram notifications were being sent with incorrect threshold values (showing 0% instead of the configured threshold). Previously, when `GetTgCpu()` failed, the error was ignored and threshold defaulted to 0, causing notifications to be sent for any CPU usage. Now the job properly checks for errors and skips notifications if: - The threshold cannot be retrieved (error) - The threshold is not set or is 0 This ensures notifications are only sent when CPU usage exceeds the configured threshold value from settings. ## Which part of the application is affected by the change? - [ ] Frontend - [x] Backend ## Type of Changes - [x] Bug fix - [ ] New feature - [ ] Refactoring - [ ] Other ## Screenshots <img width="495" height="227" alt="image" src="https://github.com/user-attachments/assets/9780d9a4-2664-4433-b1ae-74562539f74a" /> <img width="505" height="123" alt="image" src="https://github.com/user-attachments/assets/98abdcda-08cf-448d-adb8-dd3b8516719f" /> ## Additional Notes **Problem:** Users were receiving Telegram notifications showing "CPU load exceeds threshold value 0%" even though they had configured a different threshold value (e.g., 85%) in the settings. **Root Cause:** In `CheckCpuJob.Run()`, the error from `GetTgCpu()` was ignored using `threshold, _ := ...`. When an error occurred, the threshold defaulted to 0, causing the condition `percent[0] > float64(threshold)` to be true for any positive CPU usage. **Solution:** - Added proper error handling for `GetTgCpu()` call - Added validation to skip notifications if threshold is 0 or cannot be retrieved - Notifications are now only sent when CPU usage actually exceeds the configured threshold **Testing:** - Code compiles successfully - The fix prevents false notifications with 0% threshold - Notifications will only be sent when CPU usage exceeds the configured value from settings --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:47:14 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5477
No description provided.