diff --git a/backend/app/api/v1/monitor.go b/backend/app/api/v1/monitor.go index 14be057b0..72351f1c5 100644 --- a/backend/app/api/v1/monitor.go +++ b/backend/app/api/v1/monitor.go @@ -15,6 +15,13 @@ import ( "github.com/shirou/gopsutil/v3/net" ) +// @Tags Monitor +// @Summary Load monitor datas +// @Description 获取监控数据 +// @Param request body dto.MonitorSearch true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Router /hosts/monitor/search [post] func (b *BaseApi) LoadMonitor(c *gin.Context) { var req dto.MonitorSearch if err := helper.CheckBindAndValidate(&req, c); err != nil { @@ -80,6 +87,30 @@ func (b *BaseApi) LoadMonitor(c *gin.Context) { helper.SuccessWithData(c, backdatas) } +// @Tags Monitor +// @Summary Clean monitor datas +// @Description 清空监控数据 +// @Success 200 +// @Security ApiKeyAuth +// @Router /hosts/monitor/clean [post] +// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清空监控数据","formatEN":"clean monitor datas"} +func (b *BaseApi) CleanMonitor(c *gin.Context) { + if err := global.DB.Exec("DELETE FROM monitor_bases").Error; err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + if err := global.DB.Exec("DELETE FROM monitor_ios").Error; err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + if err := global.DB.Exec("DELETE FROM monitor_networks").Error; err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + + helper.SuccessWithData(c, nil) +} + func (b *BaseApi) GetNetworkOptions(c *gin.Context) { netStat, _ := net.IOCounters(true) var options []string diff --git a/backend/app/api/v1/setting.go b/backend/app/api/v1/setting.go index f697aad4e..d09f7b8ec 100644 --- a/backend/app/api/v1/setting.go +++ b/backend/app/api/v1/setting.go @@ -60,6 +60,28 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) { helper.SuccessWithData(c, nil) } +// @Tags System Setting +// @Summary Update system setting +// @Description 更新系统菜单配置 +// @Accept json +// @Param request body dto.SettingUpdate true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Router /settings/menu/update [post] +// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"修改系统高级功能菜单隐藏设置","formatEN":"modify system advanced function menu hidden settings."} +func (b *BaseApi) UpdateMenu(c *gin.Context) { + var req dto.SettingUpdate + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + + if err := settingService.Update(req.Key, req.Value); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} + // @Tags System Setting // @Summary Update system password // @Description 更新系统登录密码 @@ -227,30 +249,6 @@ func (b *BaseApi) LoadBaseDir(c *gin.Context) { helper.SuccessWithData(c, global.CONF.System.DataDir) } -// @Tags System Setting -// @Summary Clean monitor datas -// @Description 清空监控数据 -// @Success 200 -// @Security ApiKeyAuth -// @Router /settings/monitor/clean [post] -// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清空监控数据","formatEN":"clean monitor datas"} -func (b *BaseApi) CleanMonitor(c *gin.Context) { - if err := global.DB.Exec("DELETE FROM monitor_bases").Error; err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - if err := global.DB.Exec("DELETE FROM monitor_ios").Error; err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - if err := global.DB.Exec("DELETE FROM monitor_networks").Error; err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - - helper.SuccessWithData(c, nil) -} - // @Tags System Setting // @Summary Load mfa info // @Description 获取 mfa 信息 diff --git a/backend/router/common.go b/backend/router/common.go index 8330fa849..245598738 100644 --- a/backend/router/common.go +++ b/backend/router/common.go @@ -6,7 +6,6 @@ func commonGroups() []CommonRouter { &DashboardRouter{}, &HostRouter{}, &ContainerRouter{}, - &MonitorRouter{}, &LogRouter{}, &FileRouter{}, &ToolboxRouter{}, diff --git a/backend/router/ro_host.go b/backend/router/ro_host.go index c3e9e6a09..6b0159620 100644 --- a/backend/router/ro_host.go +++ b/backend/router/ro_host.go @@ -35,6 +35,11 @@ func (s *HostRouter) InitRouter(Router *gin.RouterGroup) { hostRouter.POST("/firewall/update/addr", baseApi.UpdateAddrRule) hostRouter.POST("/firewall/update/description", baseApi.UpdateFirewallDescription) + hostRouter.POST("/monitor/search", baseApi.LoadMonitor) + hostRouter.POST("/monitor/clean", baseApi.CleanMonitor) + hostRouter.GET("/monitor/netoptions", baseApi.GetNetworkOptions) + hostRouter.GET("/monitor/iooptions", baseApi.GetIOOptions) + hostRouter.GET("/ssh/conf", baseApi.LoadSSHConf) hostRouter.POST("/ssh/search", baseApi.GetSSHInfo) hostRouter.POST("/ssh/update", baseApi.UpdateSSH) diff --git a/backend/router/ro_monitor.go b/backend/router/ro_monitor.go deleted file mode 100644 index d091b90f6..000000000 --- a/backend/router/ro_monitor.go +++ /dev/null @@ -1,23 +0,0 @@ -package router - -import ( - v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1" - "github.com/1Panel-dev/1Panel/backend/middleware" - - "github.com/gin-gonic/gin" -) - -type MonitorRouter struct{} - -func (s *MonitorRouter) InitRouter(Router *gin.RouterGroup) { - monitorRouter := Router.Group("monitors"). - Use(middleware.JwtAuth()). - Use(middleware.SessionAuth()). - Use(middleware.PasswordExpired()) - baseApi := v1.ApiGroupApp.BaseApi - { - monitorRouter.POST("/search", baseApi.LoadMonitor) - monitorRouter.GET("/netoptions", baseApi.GetNetworkOptions) - monitorRouter.GET("/iooptions", baseApi.GetIOOptions) - } -} diff --git a/backend/router/ro_setting.go b/backend/router/ro_setting.go index 3ade938dc..b689d2437 100644 --- a/backend/router/ro_setting.go +++ b/backend/router/ro_setting.go @@ -23,13 +23,13 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) { settingRouter.GET("/search/available", baseApi.GetSystemAvailable) settingRouter.POST("/update", baseApi.UpdateSetting) settingRouter.GET("/interface", baseApi.LoadInterfaceAddr) + settingRouter.POST("/menu/update", baseApi.UpdateMenu) settingRouter.POST("/bind/update", baseApi.UpdateBindInfo) settingRouter.POST("/port/update", baseApi.UpdatePort) settingRouter.POST("/ssl/update", baseApi.UpdateSSL) settingRouter.GET("/ssl/info", baseApi.LoadFromCert) settingRouter.POST("/ssl/download", baseApi.DownloadSSL) settingRouter.POST("/password/update", baseApi.UpdatePassword) - settingRouter.POST("/monitor/clean", baseApi.CleanMonitor) settingRouter.POST("/mfa", baseApi.LoadMFA) settingRouter.POST("/mfa/bind", baseApi.MFABind) diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 4207e9884..b2456f1d0 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -1,5 +1,5 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag +// Code generated by swaggo/swag. DO NOT EDIT. + package docs import "github.com/swaggo/swag" @@ -8097,6 +8097,62 @@ const docTemplate = `{ } } }, + "/hosts/monitor/clean": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "清空监控数据", + "tags": [ + "Monitor" + ], + "summary": "Clean monitor datas", + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [], + "bodyKeys": [], + "formatEN": "clean monitor datas", + "formatZH": "清空监控数据", + "paramKeys": [] + } + } + }, + "/hosts/monitor/search": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "获取监控数据", + "tags": [ + "Monitor" + ], + "summary": "Load monitor datas", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.MonitorSearch" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/hosts/search": { "post": { "security": [ @@ -9923,6 +9979,46 @@ const docTemplate = `{ } } }, + "/settings/menu/update": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "更新系统菜单配置", + "consumes": [ + "application/json" + ], + "tags": [ + "System Setting" + ], + "summary": "Update system setting", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.SettingUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [], + "bodyKeys": [], + "formatEN": "modify system advanced function menu hidden settings.", + "formatZH": "修改系统高级功能菜单隐藏设置", + "paramKeys": [] + } + } + }, "/settings/mfa": { "post": { "security": [ @@ -9999,32 +10095,6 @@ const docTemplate = `{ } } }, - "/settings/monitor/clean": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "清空监控数据", - "tags": [ - "System Setting" - ], - "summary": "Clean monitor datas", - "responses": { - "200": { - "description": "OK" - } - }, - "x-panel-log": { - "BeforeFunctions": [], - "bodyKeys": [], - "formatEN": "clean monitor datas", - "formatZH": "清空监控数据", - "paramKeys": [] - } - } - }, "/settings/password/update": { "post": { "security": [ @@ -14814,6 +14884,9 @@ const docTemplate = `{ "backupAccounts": { "type": "string" }, + "command": { + "type": "string" + }, "containerName": { "type": "string" }, @@ -14885,6 +14958,9 @@ const docTemplate = `{ "backupAccounts": { "type": "string" }, + "command": { + "type": "string" + }, "containerName": { "type": "string" }, @@ -16208,6 +16284,34 @@ const docTemplate = `{ } } }, + "dto.MonitorSearch": { + "type": "object", + "required": [ + "param" + ], + "properties": { + "endTime": { + "type": "string" + }, + "info": { + "type": "string" + }, + "param": { + "type": "string", + "enum": [ + "all", + "cpu", + "memory", + "load", + "io", + "network" + ] + }, + "startTime": { + "type": "string" + } + } + }, "dto.MysqlDBCreate": { "type": "object", "required": [ @@ -17728,6 +17832,9 @@ const docTemplate = `{ }, "weChatVars": { "type": "string" + }, + "xpackHideMenu": { + "type": "string" } } }, @@ -17974,6 +18081,9 @@ const docTemplate = `{ }, "sourceDir": { "type": "string" + }, + "type": { + "type": "string" } } }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 58fd04027..646c17d02 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -8090,6 +8090,62 @@ } } }, + "/hosts/monitor/clean": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "清空监控数据", + "tags": [ + "Monitor" + ], + "summary": "Clean monitor datas", + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [], + "bodyKeys": [], + "formatEN": "clean monitor datas", + "formatZH": "清空监控数据", + "paramKeys": [] + } + } + }, + "/hosts/monitor/search": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "获取监控数据", + "tags": [ + "Monitor" + ], + "summary": "Load monitor datas", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.MonitorSearch" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/hosts/search": { "post": { "security": [ @@ -9916,6 +9972,46 @@ } } }, + "/settings/menu/update": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "更新系统菜单配置", + "consumes": [ + "application/json" + ], + "tags": [ + "System Setting" + ], + "summary": "Update system setting", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.SettingUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [], + "bodyKeys": [], + "formatEN": "modify system advanced function menu hidden settings.", + "formatZH": "修改系统高级功能菜单隐藏设置", + "paramKeys": [] + } + } + }, "/settings/mfa": { "post": { "security": [ @@ -9992,32 +10088,6 @@ } } }, - "/settings/monitor/clean": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "清空监控数据", - "tags": [ - "System Setting" - ], - "summary": "Clean monitor datas", - "responses": { - "200": { - "description": "OK" - } - }, - "x-panel-log": { - "BeforeFunctions": [], - "bodyKeys": [], - "formatEN": "clean monitor datas", - "formatZH": "清空监控数据", - "paramKeys": [] - } - } - }, "/settings/password/update": { "post": { "security": [ @@ -14807,6 +14877,9 @@ "backupAccounts": { "type": "string" }, + "command": { + "type": "string" + }, "containerName": { "type": "string" }, @@ -14878,6 +14951,9 @@ "backupAccounts": { "type": "string" }, + "command": { + "type": "string" + }, "containerName": { "type": "string" }, @@ -16201,6 +16277,34 @@ } } }, + "dto.MonitorSearch": { + "type": "object", + "required": [ + "param" + ], + "properties": { + "endTime": { + "type": "string" + }, + "info": { + "type": "string" + }, + "param": { + "type": "string", + "enum": [ + "all", + "cpu", + "memory", + "load", + "io", + "network" + ] + }, + "startTime": { + "type": "string" + } + } + }, "dto.MysqlDBCreate": { "type": "object", "required": [ @@ -17721,6 +17825,9 @@ }, "weChatVars": { "type": "string" + }, + "xpackHideMenu": { + "type": "string" } } }, @@ -17967,6 +18074,9 @@ }, "sourceDir": { "type": "string" + }, + "type": { + "type": "string" } } }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 5236f1f0c..9092b3491 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -584,6 +584,8 @@ definitions: type: string backupAccounts: type: string + command: + type: string containerName: type: string dbName: @@ -632,6 +634,8 @@ definitions: type: string backupAccounts: type: string + command: + type: string containerName: type: string dbName: @@ -1528,6 +1532,26 @@ definitions: - interval - secret type: object + dto.MonitorSearch: + properties: + endTime: + type: string + info: + type: string + param: + enum: + - all + - cpu + - memory + - load + - io + - network + type: string + startTime: + type: string + required: + - param + type: object dto.MysqlDBCreate: properties: database: @@ -2556,6 +2580,8 @@ definitions: type: string weChatVars: type: string + xpackHideMenu: + type: string type: object dto.SettingUpdate: properties: @@ -2717,6 +2743,8 @@ definitions: type: string sourceDir: type: string + type: + type: string type: object files.FileInfo: properties: @@ -10098,6 +10126,41 @@ paths: summary: Create group tags: - Firewall + /hosts/monitor/clean: + post: + description: 清空监控数据 + responses: + "200": + description: OK + security: + - ApiKeyAuth: [] + summary: Clean monitor datas + tags: + - Monitor + x-panel-log: + BeforeFunctions: [] + bodyKeys: [] + formatEN: clean monitor datas + formatZH: 清空监控数据 + paramKeys: [] + /hosts/monitor/search: + post: + description: 获取监控数据 + parameters: + - description: request + in: body + name: request + required: true + schema: + $ref: '#/definitions/dto.MonitorSearch' + responses: + "200": + description: OK + security: + - ApiKeyAuth: [] + summary: Load monitor datas + tags: + - Monitor /hosts/search: post: consumes: @@ -11244,6 +11307,32 @@ paths: summary: Load system address tags: - System Setting + /settings/menu/update: + post: + consumes: + - application/json + description: 更新系统菜单配置 + parameters: + - description: request + in: body + name: request + required: true + schema: + $ref: '#/definitions/dto.SettingUpdate' + responses: + "200": + description: OK + security: + - ApiKeyAuth: [] + summary: Update system setting + tags: + - System Setting + x-panel-log: + BeforeFunctions: [] + bodyKeys: [] + formatEN: modify system advanced function menu hidden settings. + formatZH: 修改系统高级功能菜单隐藏设置 + paramKeys: [] /settings/mfa: post: consumes: @@ -11292,23 +11381,6 @@ paths: formatEN: bind mfa formatZH: mfa 绑定 paramKeys: [] - /settings/monitor/clean: - post: - description: 清空监控数据 - responses: - "200": - description: OK - security: - - ApiKeyAuth: [] - summary: Clean monitor datas - tags: - - System Setting - x-panel-log: - BeforeFunctions: [] - bodyKeys: [] - formatEN: clean monitor datas - formatZH: 清空监控数据 - paramKeys: [] /settings/password/update: post: consumes: diff --git a/frontend/src/api/interface/host.ts b/frontend/src/api/interface/host.ts index e40c188bb..d03b87c6e 100644 --- a/frontend/src/api/interface/host.ts +++ b/frontend/src/api/interface/host.ts @@ -116,6 +116,18 @@ export namespace Host { rules: Array; } + export interface MonitorData { + param: string; + date: Array; + value: Array; + } + export interface MonitorSearch { + param: string; + info: string; + startTime: Date; + endTime: Date; + } + export interface SSHInfo { autoStart: boolean; status: string; diff --git a/frontend/src/api/interface/monitor.ts b/frontend/src/api/interface/monitor.ts deleted file mode 100644 index f153006fb..000000000 --- a/frontend/src/api/interface/monitor.ts +++ /dev/null @@ -1,13 +0,0 @@ -export namespace Monitor { - export interface MonitorData { - param: string; - date: Array; - value: Array; - } - export interface MonitorSearch { - param: string; - info: string; - startTime: Date; - endTime: Date; - } -} diff --git a/frontend/src/api/modules/host.ts b/frontend/src/api/modules/host.ts index 50488de9e..6bdb6963b 100644 --- a/frontend/src/api/modules/host.ts +++ b/frontend/src/api/modules/host.ts @@ -101,6 +101,20 @@ export const batchOperateRule = (params: Host.BatchRule) => { return http.post(`/hosts/firewall/batch`, params, TimeoutEnum.T_60S); }; +// monitors +export const loadMonitor = (param: Host.MonitorSearch) => { + return http.post>(`/hosts/monitor/search`, param); +}; +export const getNetworkOptions = () => { + return http.get>(`/hosts/monitor/netoptions`); +}; +export const getIOOptions = () => { + return http.get>(`/hosts/monitor/iooptions`); +}; +export const cleanMonitors = () => { + return http.post(`/hosts/monitor/clean`, {}); +}; + // ssh export const getSSHInfo = () => { return http.post(`/hosts/ssh/search`); diff --git a/frontend/src/api/modules/monitor.ts b/frontend/src/api/modules/monitor.ts deleted file mode 100644 index 4d129bed2..000000000 --- a/frontend/src/api/modules/monitor.ts +++ /dev/null @@ -1,14 +0,0 @@ -import http from '@/api'; -import { Monitor } from '../interface/monitor'; - -export const loadMonitor = (param: Monitor.MonitorSearch) => { - return http.post>(`/monitors/search`, param); -}; - -export const getNetworkOptions = () => { - return http.get>(`/monitors/netoptions`); -}; - -export const getIOOptions = () => { - return http.get>(`/monitors/iooptions`); -}; diff --git a/frontend/src/api/modules/setting.ts b/frontend/src/api/modules/setting.ts index 08991c13d..f94ea52fe 100644 --- a/frontend/src/api/modules/setting.ts +++ b/frontend/src/api/modules/setting.ts @@ -29,6 +29,10 @@ export const updateSetting = (param: Setting.SettingUpdate) => { return http.post(`/settings/update`, param); }; +export const updateMenu = (param: Setting.SettingUpdate) => { + return http.post(`/settings/menu/update`, param); +}; + export const updatePassword = (param: Setting.PasswordUpdate) => { return http.post(`/settings/password/update`, param); }; @@ -66,10 +70,6 @@ export const syncTime = (ntpSite: string) => { return http.post(`/settings/time/sync`, { ntpSite: ntpSite }); }; -export const cleanMonitors = () => { - return http.post(`/settings/monitor/clean`, {}); -}; - export const loadMFA = (param: Setting.MFARequest) => { return http.post(`/settings/mfa`, param); }; diff --git a/frontend/src/routers/modules/setting.ts b/frontend/src/routers/modules/setting.ts index 5fbb7cd83..99e6def22 100644 --- a/frontend/src/routers/modules/setting.ts +++ b/frontend/src/routers/modules/setting.ts @@ -24,7 +24,7 @@ const settingRouter = { hidden: true, meta: { requiresAuth: true, - activeMenu: 'Setting', + activeMenu: '/settings', }, }, { diff --git a/frontend/src/views/home/index.vue b/frontend/src/views/home/index.vue index b9837faf3..39127b1c3 100644 --- a/frontend/src/views/home/index.vue +++ b/frontend/src/views/home/index.vue @@ -250,7 +250,7 @@ import { Dashboard } from '@/api/interface/dashboard'; import { dateFormatForSecond, computeSize } from '@/utils/util'; import { useRouter } from 'vue-router'; import { loadBaseInfo, loadCurrentInfo } from '@/api/modules/dashboard'; -import { getIOOptions, getNetworkOptions } from '@/api/modules/monitor'; +import { getIOOptions, getNetworkOptions } from '@/api/modules/host'; import { getSettingInfo, loadUpgradeInfo } from '@/api/modules/setting'; import { GlobalStore } from '@/store'; const router = useRouter(); diff --git a/frontend/src/views/host/monitor/monitor/index.vue b/frontend/src/views/host/monitor/monitor/index.vue index abf4924a9..493710e95 100644 --- a/frontend/src/views/host/monitor/monitor/index.vue +++ b/frontend/src/views/host/monitor/monitor/index.vue @@ -202,13 +202,13 @@