-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: monitor middleware reporting of CPU usage #2984
Conversation
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Monitor
participant Process
participant System
User->>Monitor: Initialize monitor.New()
Monitor->>Process: Retrieve process data
Process->>Monitor: Provide process data
Monitor->>System: Retrieve number of CPUs
System-->>Monitor: Provide numcpu
Monitor->>Monitor: Call updateStatistics(p, numcpu)
Monitor->>User: Display dynamic CPU usage
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
thanks for the customization we will then port your customizations over |
@ReneWerner87 This can probably be merged, pending a new release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- middleware/monitor/monitor.go (3 hunks)
Additional comments not posted (2)
middleware/monitor/monitor.go (2)
63-64
: Optimization of CPU usage computation by using dynamic CPU countThe introduction of
numcpu
to calculate CPU usage dynamically is a sound change that aligns with the PR's objective to reflect real-time CPU usage more accurately. This adjustment ensures that the CPU usage is computed relative to the available CPU cores, which is a more accurate representation in multi-core environments.Also applies to: 70-70
106-108
: Refactor to improve clarity and reduce redundancyThe current implementation of the CPU usage calculation could be refactored to improve clarity and reduce redundancy. Specifically, the division by
numcpu
could be moved to a separate line to make it clear that it's a normalization step.
[REFACTOR_SUGGESTion]- pidCPU, err := p.Percent(0) - if err == nil { - monitPIDCPU.Store(pidCPU / float64(numcpu)) + pidCPU, err := p.Percent(0) + if err == nil { + normalizedCPU := pidCPU / float64(numcpu) + monitPIDCPU.Store(normalizedCPU) }
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
monitPIDCPU should be transient, not persistent. Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Description
The monitPIDCPU should be consistent with the monitOSCPU and should be changed instantaneously rather than using the cumulative value since program startup
The value should be calculated based on the actual number of CPU cores, rather than a fixed value of 10.
Fixes #2978
Type of change
Please delete options that are not relevant.
Checklist
Before you submit your pull request, please make sure you meet these requirements:
/docs/
directory for Fiber's documentation.Commit formatting
Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md