Files

106 lines
2.9 KiB
Go
Raw Permalink Normal View History

package v2
2024-07-23 14:48:37 +08:00
import (
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
2024-07-23 14:48:37 +08:00
"github.com/1Panel-dev/1Panel/agent/app/dto"
"github.com/gin-gonic/gin"
)
// @Tags Monitor
2024-08-05 18:22:25 +08:00
// @Summary Load monitor data
2024-07-23 14:48:37 +08:00
// @Param request body dto.MonitorSearch true "request"
2025-01-21 18:32:14 +08:00
// @Success 200 {array} dto.MonitorData
2024-07-23 14:48:37 +08:00
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
2024-07-23 14:48:37 +08:00
// @Router /hosts/monitor/search [post]
func (b *BaseApi) LoadMonitor(c *gin.Context) {
var req dto.MonitorSearch
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
2024-08-05 18:22:25 +08:00
data, err := monitorService.LoadMonitorData(req)
if err != nil {
2024-10-29 18:42:12 +08:00
helper.InternalServer(c, err)
2024-08-05 18:22:25 +08:00
return
2024-07-23 14:48:37 +08:00
}
helper.SuccessWithDataGzipped(c, data)
2024-07-23 14:48:37 +08:00
}
// @Tags Monitor
2026-09-29 15:19:30 +08:00
// @Summary Clean host or GPU monitor data
// @Param request body dto.MonitorClean true "request"
2024-07-23 14:48:37 +08:00
// @Success 200
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
2024-07-23 14:48:37 +08:00
// @Router /hosts/monitor/clean [post]
2026-09-29 15:19:30 +08:00
// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清空 [type] 监控数据","formatEN":"clean [type] monitoring data"}
2024-07-23 14:48:37 +08:00
func (b *BaseApi) CleanMonitor(c *gin.Context) {
2026-09-29 15:19:30 +08:00
var req dto.MonitorClean
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
if err := monitorService.CleanData(req.Type); err != nil {
2024-10-29 18:42:12 +08:00
helper.InternalServer(c, err)
2024-07-23 14:48:37 +08:00
return
}
2024-08-05 18:22:25 +08:00
helper.Success(c)
2024-08-05 18:22:25 +08:00
}
// @Tags Monitor
// @Summary Load monitor setting
2025-01-21 18:32:14 +08:00
// @Success 200 {object} dto.MonitorSetting
2024-08-05 18:22:25 +08:00
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
2024-08-05 18:22:25 +08:00
// @Router /hosts/monitor/setting [get]
func (b *BaseApi) LoadMonitorSetting(c *gin.Context) {
setting, err := monitorService.LoadSetting()
if err != nil {
2024-10-29 18:42:12 +08:00
helper.InternalServer(c, err)
2024-07-23 14:48:37 +08:00
return
}
2024-08-05 18:22:25 +08:00
helper.SuccessWithData(c, setting)
}
// @Tags Monitor
// @Summary Update monitor setting
// @Param request body dto.MonitorSettingUpdate true "request"
// @Success 200
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
2024-08-05 18:22:25 +08:00
// @Router /hosts/monitor/setting/update [post]
2026-06-02 15:11:43 +08:00
// @x-panel-log {"bodyKeys":["key", "value"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"修改默认监控网卡 [key]-[value]","formatEN":"update default monitor [key]-[value]"}
2024-08-05 18:22:25 +08:00
func (b *BaseApi) UpdateMonitorSetting(c *gin.Context) {
var req dto.MonitorSettingUpdate
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
if err := monitorService.UpdateSetting(req.Key, req.Value); err != nil {
2024-10-29 18:42:12 +08:00
helper.InternalServer(c, err)
2024-07-23 14:48:37 +08:00
return
}
helper.Success(c)
2024-07-23 14:48:37 +08:00
}
2026-06-02 15:11:43 +08:00
// @Tags Monitor
// @Summary Get network options
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/monitor/netoptions [get]
2024-07-23 14:48:37 +08:00
func (b *BaseApi) GetNetworkOptions(c *gin.Context) {
helper.SuccessWithData(c, monitorService.LoadNetworkOptions())
2024-07-23 14:48:37 +08:00
}
2026-06-02 15:11:43 +08:00
// @Tags Monitor
// @Summary Get IO options
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/monitor/iooptions [get]
2024-07-23 14:48:37 +08:00
func (b *BaseApi) GetIOOptions(c *gin.Context) {
helper.SuccessWithData(c, monitorService.LoadIOOptions())
2024-07-23 14:48:37 +08:00
}