Skip to content

Commit

Permalink
enhance: node analytic init
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed May 18, 2023
1 parent 21cd91b commit ca3d19a
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 246 deletions.
2 changes: 2 additions & 0 deletions frontend/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-1.22.19.cjs
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"vite-plugin-html": "^3.2.0",
"vite-svg-loader": "^4.0.0",
"vue-tsc": "^1.6.1"
}
},
"packageManager": "yarn@1.22.19"
}
2 changes: 1 addition & 1 deletion frontend/src/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.9.9","build_id":127,"total_build":197}
{"version":"1.9.9","build_id":129,"total_build":199}
2 changes: 1 addition & 1 deletion frontend/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.9.9","build_id":127,"total_build":197}
{"version":"1.9.9","build_id":129,"total_build":199}
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"github.com/0xJacky/Nginx-UI/server"
"github.com/0xJacky/Nginx-UI/server/service"
"github.com/0xJacky/Nginx-UI/server/settings"
"github.com/gin-gonic/gin"
"github.com/jpillora/overseer"
Expand All @@ -21,7 +20,7 @@ func main() {

gin.SetMode(settings.ServerSettings.RunMode)

r, err := service.GetRuntimeInfo()
r, err := server.GetRuntimeInfo()

if err != nil {
log.Fatalln(err)
Expand Down
4 changes: 2 additions & 2 deletions server/api/analytic.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ func GetIntroAnalytic(c *gin.Context) {

for {
// write
err = ws.WriteJSON(analytic.GetNodeAnalyticIntro())
err = ws.WriteJSON(analytic.GetNodeStat())
if err != nil {
logger.Error(err)
break
}

time.Sleep(5 * time.Second)
time.Sleep(10 * time.Second)
}
}

Expand Down
4 changes: 2 additions & 2 deletions server/api/environment.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package api

import (
"github.com/0xJacky/Nginx-UI/server/internal/environment"
"github.com/0xJacky/Nginx-UI/server/model"
"github.com/0xJacky/Nginx-UI/server/query"
"github.com/0xJacky/Nginx-UI/server/service"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"net/http"
Expand All @@ -24,7 +24,7 @@ func GetEnvironment(c *gin.Context) {
}

func GetEnvironmentList(c *gin.Context) {
data, err := service.RetrieveEnvironmentList()
data, err := environment.RetrieveEnvironmentList()
if err != nil {
ErrHandler(c, err)
return
Expand Down
30 changes: 15 additions & 15 deletions server/api/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"github.com/0xJacky/Nginx-UI/server/internal/analytic"
"github.com/0xJacky/Nginx-UI/server/service"
"github.com/0xJacky/Nginx-UI/server/internal/upgrader"
"github.com/dustin/go-humanize"
"github.com/gin-gonic/gin"
"github.com/shirou/gopsutil/v3/cpu"
Expand All @@ -18,28 +18,28 @@ func GetCurrentNode(c *gin.Context) {
return
}

runtimeInfo, err := service.GetRuntimeInfo()
runtimeInfo, err := upgrader.GetRuntimeInfo()
if err != nil {
ErrHandler(c, err)
return
}

cpuInfo, _ := cpu.Info()
memory, _ := getMemoryStat()
ver, _ := service.GetCurrentVersion()
ver, _ := upgrader.GetCurrentVersion()
diskUsage, _ := disk.Usage(".")

intro := analytic.GetNodeAnalyticIntro()

nodeInfo := service.NodeInfo{
RequestNodeSecret: c.MustGet("NodeSecret").(string),
NodeRuntimeInfo: runtimeInfo,
CPUNum: len(cpuInfo),
MemoryTotal: memory.Total,
DiskTotal: humanize.Bytes(diskUsage.Total),
Version: ver.Version,
Node: intro,
nodeInfo := analytic.NodeInfo{
NodeRuntimeInfo: runtimeInfo,
CPUNum: len(cpuInfo),
MemoryTotal: memory.Total,
DiskTotal: humanize.Bytes(diskUsage.Total),
Version: ver.Version,
}

c.JSON(http.StatusOK, nodeInfo)
stat := analytic.GetNodeStat()

c.JSON(http.StatusOK, analytic.Node{
NodeInfo: nodeInfo,
NodeStat: stat,
})
}
16 changes: 8 additions & 8 deletions server/api/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"github.com/0xJacky/Nginx-UI/server/internal/nginx"
"github.com/0xJacky/Nginx-UI/server/service"
"github.com/0xJacky/Nginx-UI/server/internal/template"
"github.com/gin-gonic/gin"
"net/http"
)
Expand Down Expand Up @@ -45,7 +45,7 @@ func GetTemplate(c *gin.Context) {
}

func GetTemplateConfList(c *gin.Context) {
configList, err := service.GetTemplateList("conf")
configList, err := template.GetTemplateList("conf")

if err != nil {
ErrHandler(c, err)
Expand All @@ -58,7 +58,7 @@ func GetTemplateConfList(c *gin.Context) {
}

func GetTemplateBlockList(c *gin.Context) {
configList, err := service.GetTemplateList("block")
configList, err := template.GetTemplateList("block")

if err != nil {
ErrHandler(c, err)
Expand All @@ -72,18 +72,18 @@ func GetTemplateBlockList(c *gin.Context) {

func GetTemplateBlock(c *gin.Context) {
type resp struct {
service.ConfigInfoItem
service.ConfigDetail
template.ConfigInfoItem
template.ConfigDetail
}
var bindData map[string]service.TVariable
var bindData map[string]template.TVariable
_ = c.ShouldBindJSON(&bindData)
info := service.GetTemplateInfo("block", c.Param("name"))
info := template.GetTemplateInfo("block", c.Param("name"))

if bindData == nil {
bindData = info.Variables
}

detail, err := service.ParseTemplate("block", c.Param("name"), bindData)
detail, err := template.ParseTemplate("block", c.Param("name"), bindData)
if err != nil {
ErrHandler(c, err)
return
Expand Down
14 changes: 7 additions & 7 deletions server/api/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ package api

import (
"github.com/0xJacky/Nginx-UI/server/internal/logger"
"github.com/0xJacky/Nginx-UI/server/service"
"github.com/0xJacky/Nginx-UI/server/internal/upgrader"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"net/http"
"os"
)

func GetRelease(c *gin.Context) {
data, err := service.GetRelease(c.Query("channel"))
data, err := upgrader.GetRelease(c.Query("channel"))
if err != nil {
ErrHandler(c, err)
return
}
runtimeInfo, err := service.GetRuntimeInfo()
runtimeInfo, err := upgrader.GetRuntimeInfo()
if err != nil {
ErrHandler(c, err)
return
}
type resp struct {
service.TRelease
service.RuntimeInfo
upgrader.TRelease
upgrader.RuntimeInfo
}
c.JSON(http.StatusOK, resp{
data, runtimeInfo,
})
}

func GetCurrentVersion(c *gin.Context) {
curVer, err := service.GetCurrentVersion()
curVer, err := upgrader.GetCurrentVersion()
if err != nil {
ErrHandler(c, err)
return
Expand Down Expand Up @@ -70,7 +70,7 @@ func PerformCoreUpgrade(c *gin.Context) {
"message": "Initialing core upgrader",
})

u, err := service.NewUpgrader(control.Channel)
u, err := upgrader.NewUpgrader(control.Channel)

if err != nil {
_ = ws.WriteJSON(gin.H{
Expand Down
Loading

0 comments on commit ca3d19a

Please sign in to comment.