mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 01:38:50 +02:00
feat(metrics): enhance SystemInfoRequest with agent name support and update response type
- Added agentName field to SystemInfoRequest for improved querying. - Updated SystemInfoAggregate type to use AggregatedJSON - Modified SystemInfo function to handle agent lookup by name in addition to address.
This commit is contained in:
@@ -17,11 +17,12 @@ import (
|
|||||||
|
|
||||||
type SystemInfoRequest struct {
|
type SystemInfoRequest struct {
|
||||||
AgentAddr string `query:"agent_addr"`
|
AgentAddr string `query:"agent_addr"`
|
||||||
|
AgentName string `query:"agent_name"`
|
||||||
Aggregate systeminfo.SystemInfoAggregateMode `query:"aggregate"`
|
Aggregate systeminfo.SystemInfoAggregateMode `query:"aggregate"`
|
||||||
Period period.Filter `query:"period"`
|
Period period.Filter `query:"period"`
|
||||||
} // @name SystemInfoRequest
|
} // @name SystemInfoRequest
|
||||||
|
|
||||||
type SystemInfoAggregate period.ResponseType[systeminfo.Aggregated] // @name SystemInfoAggregate
|
type SystemInfoAggregate period.ResponseType[systeminfo.AggregatedJSON] // @name SystemInfoAggregate
|
||||||
|
|
||||||
// @x-id "system_info"
|
// @x-id "system_info"
|
||||||
// @BasePath /api/v1
|
// @BasePath /api/v1
|
||||||
@@ -34,21 +35,25 @@ type SystemInfoAggregate period.ResponseType[systeminfo.Aggregated] // @name Sys
|
|||||||
// @Success 200 {object} SystemInfoAggregate "period specified"
|
// @Success 200 {object} SystemInfoAggregate "period specified"
|
||||||
// @Failure 400 {object} apitypes.ErrorResponse
|
// @Failure 400 {object} apitypes.ErrorResponse
|
||||||
// @Failure 403 {object} apitypes.ErrorResponse
|
// @Failure 403 {object} apitypes.ErrorResponse
|
||||||
// @Failure 404 {object} apitypes.ErrorResponse
|
|
||||||
// @Failure 500 {object} apitypes.ErrorResponse
|
// @Failure 500 {object} apitypes.ErrorResponse
|
||||||
// @Router /metrics/system_info [get]
|
// @Router /metrics/system_info [get]
|
||||||
func SystemInfo(c *gin.Context) {
|
func SystemInfo(c *gin.Context) {
|
||||||
query := c.Request.URL.Query()
|
query := c.Request.URL.Query()
|
||||||
agentAddr := query.Get("agent_addr")
|
agentAddr := query.Get("agent_addr")
|
||||||
|
agentName := query.Get("agent_name")
|
||||||
query.Del("agent_addr")
|
query.Del("agent_addr")
|
||||||
if agentAddr == "" {
|
query.Del("agent_name")
|
||||||
|
if agentAddr == "" && agentName == "" {
|
||||||
systeminfo.Poller.ServeHTTP(c)
|
systeminfo.Poller.ServeHTTP(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
agent, ok := agentPkg.GetAgent(agentAddr)
|
agent, ok := agentPkg.GetAgent(agentAddr)
|
||||||
if !ok {
|
if !ok {
|
||||||
c.JSON(http.StatusNotFound, apitypes.Error("agent_addr not found"))
|
agent, ok = agentPkg.GetAgentByName(agentName)
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusNotFound, apitypes.Error("agent_addr or agent_name not found"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user