mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
fix: resolved all vue-tsc errors
This commit is contained in:
parent
d325dd7493
commit
ab1adcfa3d
64 changed files with 675 additions and 451 deletions
|
@ -2,7 +2,7 @@ package analytic
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
analytic2 "github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/host"
|
||||
|
@ -17,22 +17,6 @@ import (
|
|||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type CPUStat struct {
|
||||
User float64 `json:"user"`
|
||||
System float64 `json:"system"`
|
||||
Idle float64 `json:"idle"`
|
||||
Total float64 `json:"total"`
|
||||
}
|
||||
|
||||
type Stat struct {
|
||||
Uptime uint64 `json:"uptime"`
|
||||
LoadAvg *load.AvgStat `json:"loadavg"`
|
||||
CPU CPUStat `json:"cpu"`
|
||||
Memory analytic2.MemStat `json:"memory"`
|
||||
Disk analytic2.DiskStat `json:"disk"`
|
||||
Network net.IOCountersStat `json:"network"`
|
||||
}
|
||||
|
||||
func Analytic(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
|
@ -51,7 +35,7 @@ func Analytic(c *gin.Context) {
|
|||
var stat Stat
|
||||
|
||||
for {
|
||||
stat.Memory, err = analytic2.GetMemoryStat()
|
||||
stat.Memory, err = analytic.GetMemoryStat()
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
|
@ -76,7 +60,7 @@ func Analytic(c *gin.Context) {
|
|||
|
||||
stat.LoadAvg, _ = load.Avg()
|
||||
|
||||
stat.Disk, err = analytic2.GetDiskStat()
|
||||
stat.Disk, err = analytic.GetDiskStat()
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
|
@ -103,20 +87,24 @@ func Analytic(c *gin.Context) {
|
|||
}
|
||||
|
||||
func GetAnalyticInit(c *gin.Context) {
|
||||
cpuInfo, _ := cpu.Info()
|
||||
network, _ := net.IOCounters(false)
|
||||
memory, err := analytic2.GetMemoryStat()
|
||||
|
||||
cpuInfo, err := cpu.Info()
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
diskStat, err := analytic2.GetDiskStat()
|
||||
|
||||
network, err := net.IOCounters(false)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
memory, err := analytic.GetMemoryStat()
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
diskStat, err := analytic.GetDiskStat()
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
var _net net.IOCountersStat
|
||||
|
@ -132,86 +120,30 @@ func GetAnalyticInit(c *gin.Context) {
|
|||
hostInfo.Platform = "CentOS"
|
||||
}
|
||||
|
||||
loadAvg, _ := load.Avg()
|
||||
loadAvg, err := load.Avg()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"host": hostInfo,
|
||||
"cpu": gin.H{
|
||||
"info": cpuInfo,
|
||||
"user": analytic2.CpuUserRecord,
|
||||
"total": analytic2.CpuTotalRecord,
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, InitResp{
|
||||
Host: hostInfo,
|
||||
CPU: CPURecords{
|
||||
Info: cpuInfo,
|
||||
User: analytic.CpuUserRecord,
|
||||
Total: analytic.CpuTotalRecord,
|
||||
},
|
||||
"network": gin.H{
|
||||
"init": _net,
|
||||
"bytesRecv": analytic2.NetRecvRecord,
|
||||
"bytesSent": analytic2.NetSentRecord,
|
||||
Network: NetworkRecords{
|
||||
Init: _net,
|
||||
BytesRecv: analytic.NetRecvRecord,
|
||||
BytesSent: analytic.NetSentRecord,
|
||||
},
|
||||
"disk_io": gin.H{
|
||||
"writes": analytic2.DiskWriteRecord,
|
||||
"reads": analytic2.DiskReadRecord,
|
||||
DiskIO: DiskIORecords{
|
||||
Writes: analytic.DiskWriteRecord,
|
||||
Reads: analytic.DiskReadRecord,
|
||||
},
|
||||
"memory": memory,
|
||||
"disk": diskStat,
|
||||
"loadavg": loadAvg,
|
||||
Memory: memory,
|
||||
Disk: diskStat,
|
||||
LoadAvg: loadAvg,
|
||||
})
|
||||
}
|
||||
|
||||
func GetNodeStat(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer ws.Close()
|
||||
|
||||
for {
|
||||
// write
|
||||
err = ws.WriteJSON(analytic2.GetNodeStat())
|
||||
if err != nil || websocket.IsUnexpectedCloseError(err,
|
||||
websocket.CloseGoingAway,
|
||||
websocket.CloseNoStatusReceived,
|
||||
websocket.CloseNormalClosure) {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func GetNodesAnalytic(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer ws.Close()
|
||||
|
||||
for {
|
||||
// write
|
||||
err = ws.WriteJSON(analytic2.NodeMap)
|
||||
if err != nil || websocket.IsUnexpectedCloseError(err,
|
||||
websocket.CloseGoingAway,
|
||||
websocket.CloseNoStatusReceived,
|
||||
websocket.CloseNormalClosure) {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
|
|
70
api/analytic/nodes.go
Normal file
70
api/analytic/nodes.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package analytic
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetNodeStat(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer ws.Close()
|
||||
|
||||
for {
|
||||
// write
|
||||
err = ws.WriteJSON(analytic.GetNodeStat())
|
||||
if err != nil || websocket.IsUnexpectedCloseError(err,
|
||||
websocket.CloseGoingAway,
|
||||
websocket.CloseNoStatusReceived,
|
||||
websocket.CloseNormalClosure) {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func GetNodesAnalytic(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer ws.Close()
|
||||
|
||||
for {
|
||||
// write
|
||||
err = ws.WriteJSON(analytic.NodeMap)
|
||||
if err != nil || websocket.IsUnexpectedCloseError(err,
|
||||
websocket.CloseGoingAway,
|
||||
websocket.CloseNoStatusReceived,
|
||||
websocket.CloseNormalClosure) {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
52
api/analytic/type.go
Normal file
52
api/analytic/type.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package analytic
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/host"
|
||||
"github.com/shirou/gopsutil/v3/load"
|
||||
"github.com/shirou/gopsutil/v3/net"
|
||||
)
|
||||
|
||||
type CPUStat struct {
|
||||
User float64 `json:"user"`
|
||||
System float64 `json:"system"`
|
||||
Idle float64 `json:"idle"`
|
||||
Total float64 `json:"total"`
|
||||
}
|
||||
|
||||
type Stat struct {
|
||||
Uptime uint64 `json:"uptime"`
|
||||
LoadAvg *load.AvgStat `json:"loadavg"`
|
||||
CPU CPUStat `json:"cpu"`
|
||||
Memory analytic.MemStat `json:"memory"`
|
||||
Disk analytic.DiskStat `json:"disk"`
|
||||
Network net.IOCountersStat `json:"network"`
|
||||
}
|
||||
|
||||
type CPURecords struct {
|
||||
Info []cpu.InfoStat `json:"info"`
|
||||
User []analytic.Usage[float64] `json:"user"`
|
||||
Total []analytic.Usage[float64] `json:"total"`
|
||||
}
|
||||
|
||||
type NetworkRecords struct {
|
||||
Init net.IOCountersStat `json:"init"`
|
||||
BytesRecv []analytic.Usage[uint64] `json:"bytesRecv"`
|
||||
BytesSent []analytic.Usage[uint64] `json:"bytesSent"`
|
||||
}
|
||||
|
||||
type DiskIORecords struct {
|
||||
Writes []analytic.Usage[uint64] `json:"writes"`
|
||||
Reads []analytic.Usage[uint64] `json:"reads"`
|
||||
}
|
||||
|
||||
type InitResp struct {
|
||||
Host *host.InfoStat `json:"host"`
|
||||
CPU CPURecords `json:"cpu"`
|
||||
Network NetworkRecords `json:"network"`
|
||||
DiskIO DiskIORecords `json:"disk_io"`
|
||||
Memory analytic.MemStat `json:"memory"`
|
||||
Disk analytic.DiskStat `json:"disk"`
|
||||
LoadAvg *load.AvgStat `json:"loadavg"`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue