File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package monitor
2
2
3
3
import (
4
4
"os"
5
+ "runtime"
5
6
"sync"
6
7
"sync/atomic"
7
8
"time"
@@ -59,14 +60,14 @@ func New(config ...Config) fiber.Handler {
59
60
// Start routine to update statistics
60
61
once .Do (func () {
61
62
p , _ := process .NewProcess (int32 (os .Getpid ())) //nolint:errcheck // TODO: Handle error
62
-
63
- updateStatistics (p )
63
+ numcpu := runtime . NumCPU ()
64
+ updateStatistics (p , numcpu )
64
65
65
66
go func () {
66
67
for {
67
68
time .Sleep (cfg .Refresh )
68
69
69
- updateStatistics (p )
70
+ updateStatistics (p , numcpu )
70
71
}
71
72
}()
72
73
})
@@ -101,10 +102,10 @@ func New(config ...Config) fiber.Handler {
101
102
}
102
103
}
103
104
104
- func updateStatistics (p * process.Process ) {
105
- pidCPU , err := p .CPUPercent ( )
105
+ func updateStatistics (p * process.Process , numcpu int ) {
106
+ pidCPU , err := p .Percent ( 0 )
106
107
if err == nil {
107
- monitPIDCPU .Store (pidCPU / 10 )
108
+ monitPIDCPU .Store (pidCPU / float64 ( numcpu ) )
108
109
}
109
110
110
111
if osCPU , err := cpu .Percent (0 , false ); err == nil && len (osCPU ) > 0 {
You can’t perform that action at this time.
0 commit comments