mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
change work dir
This commit is contained in:
parent
ce850f5e59
commit
08b54b5bbb
31 changed files with 260 additions and 259 deletions
|
@ -1,36 +0,0 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/disk"
|
||||
"github.com/shirou/gopsutil/v3/load"
|
||||
"github.com/shirou/gopsutil/v3/mem"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGoPsutil(t *testing.T) {
|
||||
fmt.Println("os:", runtime.GOOS)
|
||||
fmt.Println("threads:", runtime.GOMAXPROCS(0))
|
||||
|
||||
v, _ := mem.VirtualMemory()
|
||||
|
||||
loadAvg, _ := load.Avg()
|
||||
|
||||
fmt.Println("loadavg", loadAvg.String())
|
||||
|
||||
fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
|
||||
cpuTimesBefore, _ := cpu.Times(false)
|
||||
time.Sleep(1000*time.Millisecond)
|
||||
cpuTimesAfter, _ := cpu.Times(false)
|
||||
threadNum := runtime.GOMAXPROCS(0)
|
||||
fmt.Println(cpuTimesBefore[0].String(), "\n", cpuTimesAfter[0].String())
|
||||
cpuUserUsage := (cpuTimesAfter[0].User - cpuTimesBefore[0].User) / (float64(1000*threadNum) / 1000)
|
||||
cpuSystemUsage := (cpuTimesAfter[0].System - cpuTimesBefore[0].System) / (float64(1000*threadNum) / 1000)
|
||||
fmt.Printf("%.2f, %.2f\n", cpuUserUsage*100, cpuSystemUsage*100)
|
||||
|
||||
diskUsage, _ := disk.Usage(".")
|
||||
fmt.Println(diskUsage.String())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue