initial import
This commit is contained in:
8
example/stat/Dockerfile
Normal file
8
example/stat/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM alpine
|
||||
|
||||
RUN mkdir /app
|
||||
COPY cpu /app/
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
CMD ["/app/cpu"]
|
||||
34
example/stat/main.go
Normal file
34
example/stat/main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"zero/core/stat"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(runtime.NumCPU())
|
||||
for i := 0; i < runtime.NumCPU()+10; i++ {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
default:
|
||||
time.Sleep(time.Microsecond)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(time.Second * 5)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
percent := stat.CpuUsage()
|
||||
fmt.Println("cpu:", percent)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user