Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
是阿延啊
gin-vue-admin
提交
960c209d
G
gin-vue-admin
项目概览
是阿延啊
/
gin-vue-admin
与 Fork 源项目一致
Fork自
FLIPPED-AURORA / gin-vue-admin
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
960c209d
编写于
10月 05, 2020
作者:
Sliver_Horn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成获取服务器信息的功能接口
上级
a8fffc8f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
129 addition
and
43 deletion
+129
-43
server/api/v1/sys_system.go
server/api/v1/sys_system.go
+16
-0
server/gva/init_data/init_data.go
server/gva/init_data/init_data.go
+2
-0
server/router/sys_system.go
server/router/sys_system.go
+4
-3
server/service/sys_system.go
server/service/sys_system.go
+28
-0
server/utils/server.go
server/utils/server.go
+78
-39
web/src/view/example/simpleUploader/simpleUploader.vue
web/src/view/example/simpleUploader/simpleUploader.vue
+1
-1
未找到文件。
server/api/v1/sys_system.go
浏览文件 @
960c209d
...
...
@@ -60,3 +60,19 @@ func ReloadSystem(c *gin.Context) {
response
.
OkWithMessage
(
"设置成功"
,
c
)
}
}
// @Tags system
// @Summary 获取服务器信息
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getServerInfo [post]
func
GetServerInfo
(
c
*
gin
.
Context
)
{
server
,
err
:=
service
.
GetServerInfo
()
if
err
!=
nil
{
response
.
FailWithMessage
(
fmt
.
Sprintf
(
"获取失败,%v"
,
err
),
c
)
return
}
response
.
OkDetailed
(
gin
.
H
{
"server"
:
server
},
"获取成功"
,
c
)
}
\ No newline at end of file
server/gva/init_data/init_data.go
浏览文件 @
960c209d
...
...
@@ -87,6 +87,7 @@ func InitSysApi() (err error) {
{
gorm
.
Model
{
ID
:
63
,
CreatedAt
:
time
.
Now
(),
UpdatedAt
:
time
.
Now
()},
"/simpleUploader/checkFileMd5"
,
"文件完整度验证"
,
"simpleUploader"
,
"GET"
},
{
gorm
.
Model
{
ID
:
64
,
CreatedAt
:
time
.
Now
(),
UpdatedAt
:
time
.
Now
()},
"/simpleUploader/mergeFileMd5"
,
"上传完成合并文件"
,
"simpleUploader"
,
"GET"
},
{
gorm
.
Model
{
ID
:
65
,
CreatedAt
:
time
.
Now
(),
UpdatedAt
:
time
.
Now
()},
"/user/setUserInfo"
,
"设置用户信息"
,
"user"
,
"PUT"
},
{
gorm
.
Model
{
ID
:
66
,
CreatedAt
:
time
.
Now
(),
UpdatedAt
:
time
.
Now
()},
"/system/getServerInfo"
,
"获取服务器信息"
,
"system"
,
"POST"
},
}
if
tx
.
Create
(
&
insert
)
.
Error
!=
nil
{
// 遇到错误时回滚事务
tx
.
Rollback
()
...
...
@@ -161,6 +162,7 @@ func InitCasbinModel() (err error) {
{
"p"
,
"888"
,
"/jwt/jsonInBlacklist"
,
"POST"
},
{
"p"
,
"888"
,
"/system/getSystemConfig"
,
"POST"
},
{
"p"
,
"888"
,
"/system/setSystemConfig"
,
"POST"
},
{
"p"
,
"888"
,
"/system/getServerInfo"
,
"POST"
},
{
"p"
,
"888"
,
"/customer/customer"
,
"POST"
},
{
"p"
,
"888"
,
"/customer/customer"
,
"PUT"
},
{
"p"
,
"888"
,
"/customer/customer"
,
"DELETE"
},
...
...
server/router/sys_system.go
浏览文件 @
960c209d
...
...
@@ -7,9 +7,10 @@ import (
)
func
InitSystemRouter
(
Router
*
gin
.
RouterGroup
)
{
User
Router
:=
Router
.
Group
(
"system"
)
.
Use
(
middleware
.
JWTAuth
())
.
Use
(
middleware
.
CasbinHandler
())
System
Router
:=
Router
.
Group
(
"system"
)
.
Use
(
middleware
.
JWTAuth
())
.
Use
(
middleware
.
CasbinHandler
())
{
UserRouter
.
POST
(
"getSystemConfig"
,
v1
.
GetSystemConfig
)
// 获取配置文件内容
UserRouter
.
POST
(
"setSystemConfig"
,
v1
.
SetSystemConfig
)
// 设置配置文件内容
SystemRouter
.
POST
(
"getSystemConfig"
,
v1
.
GetSystemConfig
)
// 获取配置文件内容
SystemRouter
.
POST
(
"setSystemConfig"
,
v1
.
SetSystemConfig
)
// 设置配置文件内容
SystemRouter
.
POST
(
"getServerInfo"
,
v1
.
GetServerInfo
)
// 获取服务器信息
}
}
server/service/sys_system.go
浏览文件 @
960c209d
...
...
@@ -5,6 +5,7 @@ import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/utils"
"go.uber.org/zap"
)
// @title GetSystemConfig
...
...
@@ -31,3 +32,30 @@ func SetSystemConfig(system model.System) (err error) {
err
=
global
.
GVA_VP
.
WriteConfig
()
return
err
}
// @title GetServerInfo
// @description get server info , 获取服务器信息
// @auth (2020/04/05 20:22)
// @return server *utils.Server
// @return err error
func
GetServerInfo
()
(
server
*
utils
.
Server
,
err
error
)
{
var
s
utils
.
Server
s
.
Os
=
utils
.
InitOS
()
if
s
.
Cpu
,
err
=
utils
.
InitCPU
();
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"func utils.InitCPU() Failed!"
,
zap
.
String
(
"err"
,
err
.
Error
()))
return
&
s
,
err
}
if
s
.
Rrm
,
err
=
utils
.
InitRAM
();
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"func utils.InitRAM() Failed!"
,
zap
.
String
(
"err"
,
err
.
Error
()))
return
&
s
,
err
}
if
s
.
Disk
,
err
=
utils
.
InitDisk
();
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"func utils.InitDisk() Failed!"
,
zap
.
String
(
"err"
,
err
.
Error
()))
return
&
s
,
err
}
return
&
s
,
nil
}
server/utils/server.go
浏览文件 @
960c209d
package
utils
import
(
"fmt"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/load"
"github.com/shirou/gopsutil/mem"
"runtime"
"time"
)
const
(
B
=
1
KB
=
1024
*
B
...
...
@@ -16,47 +15,87 @@ const (
GB
=
1024
*
MB
)
//服务器硬盘使用量
func
DiskCheck
()
{
u
,
_
:=
disk
.
Usage
(
"/"
)
usedMB
:=
int
(
u
.
Used
)
/
MB
usedGB
:=
int
(
u
.
Used
)
/
GB
totalMB
:=
int
(
u
.
Total
)
/
MB
totalGB
:=
int
(
u
.
Total
)
/
GB
usedPercent
:=
int
(
u
.
UsedPercent
)
fmt
.
Printf
(
"Free space: %dMB (%dGB) / %dMB (%dGB) | Used: %d%%
\n
"
,
usedMB
,
usedGB
,
totalMB
,
totalGB
,
usedPercent
)
type
Server
struct
{
Os
Os
`json:"os"`
Cpu
Cpu
`json:"cpu"`
Rrm
Rrm
`json:"ram"`
Disk
Disk
`json:"disk"`
}
type
Os
struct
{
GOOS
string
`json:"goos"`
NumCPU
int
`json:"numCpu"`
Compiler
string
`json:"compiler"`
GoVersion
string
`json:"goVersion"`
NumGoroutine
int
`json:"numGoroutine"`
}
type
Cpu
struct
{
Cpus
[]
float64
`json:"cpus"`
Cores
int
`json:"cores"`
}
type
Rrm
struct
{
UsedMB
int
`json:"usedMb"`
TotalMB
int
`json:"totalMb"`
UsedPercent
int
`json:"usedPercent"`
}
//OS
func
OSCheck
()
{
fmt
.
Printf
(
"goOs:%s,compiler:%s,numCpu:%d,version:%s,numGoroutine:%d
\n
"
,
runtime
.
GOOS
,
runtime
.
Compiler
,
runtime
.
NumCPU
(),
runtime
.
Version
(),
runtime
.
NumGoroutine
())
type
Disk
struct
{
UsedMB
int
`json:"usedMb"`
UsedGB
int
`json:"usedGb"`
TotalMB
int
`json:"totalMb"`
TotalGB
int
`json:"totalGb"`
UsedPercent
int
`json:"usedPercent"`
}
//CPU 使用量
func
CPUCheck
()
{
cores
,
_
:=
cpu
.
Counts
(
false
)
// InitOS OS信息
func
InitOS
()
(
o
Os
)
{
o
.
GOOS
=
runtime
.
GOOS
o
.
NumCPU
=
runtime
.
NumCPU
()
o
.
GoVersion
=
runtime
.
Version
()
o
.
NumGoroutine
=
runtime
.
NumGoroutine
()
return
o
}
// InitCPU CPU信息
func
InitCPU
()
(
c
Cpu
,
err
error
)
{
if
cores
,
err
:=
cpu
.
Counts
(
false
);
err
!=
nil
{
return
c
,
err
}
else
{
c
.
Cores
=
cores
}
if
cpus
,
err
:=
cpu
.
Percent
(
time
.
Duration
(
200
)
*
time
.
Millisecond
,
true
);
err
!=
nil
{
return
c
,
err
}
else
{
c
.
Cpus
=
cpus
}
return
c
,
nil
}
// InitRAM ARM信息
func
InitRAM
()
(
r
Rrm
,
err
error
)
{
if
u
,
err
:=
mem
.
VirtualMemory
();
err
!=
nil
{
return
r
,
err
}
else
{
r
.
UsedMB
=
int
(
u
.
Used
)
/
MB
r
.
TotalMB
=
int
(
u
.
Total
)
/
MB
r
.
UsedPercent
=
int
(
u
.
UsedPercent
)
}
return
r
,
nil
}
cpus
,
err
:=
cpu
.
Percent
(
time
.
Duration
(
200
)
*
time
.
Millisecond
,
true
)
if
err
==
nil
{
for
i
,
c
:=
range
cpus
{
fmt
.
Printf
(
"cpu%d : %f%%
\n
"
,
i
,
c
)
}
// InitDisk 硬盘信息
func
InitDisk
()
(
d
Disk
,
err
error
)
{
if
u
,
err
:=
disk
.
Usage
(
"/"
);
err
!=
nil
{
return
d
,
err
}
else
{
d
.
UsedMB
=
int
(
u
.
Used
)
/
MB
d
.
UsedGB
=
int
(
u
.
Used
)
/
GB
d
.
TotalMB
=
int
(
u
.
Total
)
/
MB
d
.
TotalGB
=
int
(
u
.
Total
)
/
GB
d
.
UsedPercent
=
int
(
u
.
UsedPercent
)
}
a
,
_
:=
load
.
Avg
()
l1
:=
a
.
Load1
l5
:=
a
.
Load5
l15
:=
a
.
Load15
fmt
.
Println
(
l1
)
fmt
.
Println
(
l5
)
fmt
.
Println
(
l15
)
fmt
.
Println
(
cores
)
}
//内存使用量
func
RAMCheck
()
{
u
,
_
:=
mem
.
VirtualMemory
()
usedMB
:=
int
(
u
.
Used
)
/
MB
totalMB
:=
int
(
u
.
Total
)
/
MB
usedPercent
:=
int
(
u
.
UsedPercent
)
fmt
.
Printf
(
"usedMB:%d,totalMB:%d,usedPercent:%d"
,
usedMB
,
totalMB
,
usedPercent
)
return
d
,
nil
}
\ No newline at end of file
web/src/view/example/simpleUploader/simpleUploader.vue
浏览文件 @
960c209d
...
...
@@ -94,7 +94,7 @@ export default {
return
false
;
}
md5
=
SparkMD5
.
ArrayBuffer
.
hash
(
e
.
target
.
result
,
false
);
file
.
uniqueIdentifier
=
md5
;
if
(
md5
!=
""
)
{
const
res
=
await
checkFileMd5
({
md5
:
md5
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录