mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-10-09 16:00:29 +00:00
* perf(monitor): improve monitor query and chart performance for large ranges - enable LTTB sampling in the shared line chart to bound rendered points - empty io/network in monitor search now means no name filter, returning all device rows in one query instead of fanning out per device - merge device names recorded in the monitor db into io/network/gpu options so removed devices stay selectable; move logic to service layer - add composite indexes (name, created_at) on monitor_ios/monitor_networks and (product_name, created_at) on monitor_gpus - stop migrating the unused MonitorGPU model into MonitorDB - fix the memory param which was compared against "mem" and never matched * chore(monitor): remove monitor test fixtures --------- Co-authored-by: ssongliu <sloooop1x@gmail.com>
107 lines
2.9 KiB
Go
107 lines
2.9 KiB
Go
package v2
|
|
|
|
import (
|
|
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
|
|
"github.com/1Panel-dev/1Panel/agent/app/dto"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// @Tags Monitor
|
|
// @Summary Load monitor data
|
|
// @Param request body dto.MonitorSearch true "request"
|
|
// @Success 200 {array} dto.MonitorData
|
|
// @Security ApiKeyAuth
|
|
// @Security Timestamp
|
|
// @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
|
|
}
|
|
|
|
data, err := monitorService.LoadMonitorData(req)
|
|
if err != nil {
|
|
helper.InternalServer(c, err)
|
|
return
|
|
}
|
|
helper.SuccessWithDataGzipped(c, data)
|
|
}
|
|
|
|
// @Tags Monitor
|
|
// @Summary Clean host or GPU monitor data
|
|
// @Param request body dto.MonitorClean true "request"
|
|
// @Success 200
|
|
// @Security ApiKeyAuth
|
|
// @Security Timestamp
|
|
// @Router /hosts/monitor/clean [post]
|
|
// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清空 [type] 监控数据","formatEN":"clean [type] monitoring data"}
|
|
func (b *BaseApi) CleanMonitor(c *gin.Context) {
|
|
var req dto.MonitorClean
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
|
return
|
|
}
|
|
if err := monitorService.CleanData(req.Type); err != nil {
|
|
helper.InternalServer(c, err)
|
|
return
|
|
}
|
|
|
|
helper.Success(c)
|
|
}
|
|
|
|
// @Tags Monitor
|
|
// @Summary Load monitor setting
|
|
// @Success 200 {object} dto.MonitorSetting
|
|
// @Security ApiKeyAuth
|
|
// @Security Timestamp
|
|
// @Router /hosts/monitor/setting [get]
|
|
func (b *BaseApi) LoadMonitorSetting(c *gin.Context) {
|
|
setting, err := monitorService.LoadSetting()
|
|
if err != nil {
|
|
helper.InternalServer(c, err)
|
|
return
|
|
}
|
|
|
|
helper.SuccessWithData(c, setting)
|
|
}
|
|
|
|
// @Tags Monitor
|
|
// @Summary Update monitor setting
|
|
// @Param request body dto.MonitorSettingUpdate true "request"
|
|
// @Success 200
|
|
// @Security ApiKeyAuth
|
|
// @Security Timestamp
|
|
// @Router /hosts/monitor/setting/update [post]
|
|
// @x-panel-log {"bodyKeys":["key", "value"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"修改默认监控网卡 [key]-[value]","formatEN":"update default monitor [key]-[value]"}
|
|
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 {
|
|
helper.InternalServer(c, err)
|
|
return
|
|
}
|
|
|
|
helper.Success(c)
|
|
}
|
|
|
|
// @Tags Monitor
|
|
// @Summary Get network options
|
|
// @Success 200
|
|
// @Security ApiKeyAuth
|
|
// @Security Timestamp
|
|
// @Router /hosts/monitor/netoptions [get]
|
|
func (b *BaseApi) GetNetworkOptions(c *gin.Context) {
|
|
helper.SuccessWithData(c, monitorService.LoadNetworkOptions())
|
|
}
|
|
|
|
// @Tags Monitor
|
|
// @Summary Get IO options
|
|
// @Success 200
|
|
// @Security ApiKeyAuth
|
|
// @Security Timestamp
|
|
// @Router /hosts/monitor/iooptions [get]
|
|
func (b *BaseApi) GetIOOptions(c *gin.Context) {
|
|
helper.SuccessWithData(c, monitorService.LoadIOOptions())
|
|
}
|