Skip to content

Commit abbe1cb

Browse files
committed
新增服务器参数工具文件,修改8000->8888,删除多余的依赖文件
1 parent bfda990 commit abbe1cb

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

server/core/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func RunWindowsServer() {
2929

3030
fmt.Printf(`欢迎使用 Gin-Vue-Admin
3131
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
32-
默认前端文件运行地址:http://127.0.0.1:8000
32+
默认前端文件运行地址:http://127.0.0.1:8080
3333
`, address)
3434
global.GVA_LOG.Error(s.ListenAndServe().Error())
3535
}

server/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ require (
3232
github.com/pkg/errors v0.9.1 // indirect
3333
github.com/qiniu/api.v7/v7 v7.4.1
3434
github.com/satori/go.uuid v1.2.0
35+
github.com/shirou/gopsutil v2.20.8+incompatible
3536
github.com/spf13/afero v1.2.2 // indirect
3637
github.com/spf13/cast v1.3.1 // indirect
3738
github.com/spf13/jwalterweatherman v1.1.0 // indirect
38-
github.com/spf13/pflag v1.0.5
3939
github.com/spf13/viper v1.6.2
4040
github.com/swaggo/gin-swagger v1.2.0
4141
github.com/swaggo/swag v1.6.7

server/utils/server.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package utils
2+
3+
import (
4+
"fmt"
5+
"github.com/shirou/gopsutil/cpu"
6+
"github.com/shirou/gopsutil/disk"
7+
"github.com/shirou/gopsutil/load"
8+
"github.com/shirou/gopsutil/mem"
9+
"runtime"
10+
"time"
11+
)
12+
const (
13+
B = 1
14+
KB = 1024 * B
15+
MB = 1024 * KB
16+
GB = 1024 * MB
17+
)
18+
19+
//服务器硬盘使用量
20+
func DiskCheck() {
21+
u, _ := disk.Usage("/")
22+
usedMB := int(u.Used) / MB
23+
usedGB := int(u.Used) / GB
24+
totalMB := int(u.Total) / MB
25+
totalGB := int(u.Total) / GB
26+
usedPercent := int(u.UsedPercent)
27+
fmt.Printf("Free space: %dMB (%dGB) / %dMB (%dGB) | Used: %d%%\n", usedMB, usedGB, totalMB, totalGB, usedPercent)
28+
}
29+
30+
//OS
31+
func OSCheck() {
32+
fmt.Printf("goOs:%s,compiler:%s,numCpu:%d,version:%s,numGoroutine:%d\n", runtime.GOOS, runtime.Compiler, runtime.NumCPU(), runtime.Version(), runtime.NumGoroutine())
33+
}
34+
35+
//CPU 使用量
36+
func CPUCheck() {
37+
cores, _ := cpu.Counts(false)
38+
39+
cpus, err := cpu.Percent(time.Duration(200)*time.Millisecond, true)
40+
if err == nil {
41+
for i, c := range cpus {
42+
fmt.Printf("cpu%d : %f%%\n", i, c)
43+
}
44+
}
45+
a, _ := load.Avg()
46+
l1 := a.Load1
47+
l5 := a.Load5
48+
l15 := a.Load15
49+
fmt.Println(l1)
50+
fmt.Println(l5)
51+
fmt.Println(l15)
52+
fmt.Println(cores)
53+
}
54+
55+
//内存使用量
56+
func RAMCheck() {
57+
u, _ := mem.VirtualMemory()
58+
usedMB := int(u.Used) / MB
59+
totalMB := int(u.Total) / MB
60+
usedPercent := int(u.UsedPercent)
61+
fmt.Printf("usedMB:%d,totalMB:%d,usedPercent:%d", usedMB, totalMB, usedPercent)
62+
}

0 commit comments

Comments
 (0)