diff --git a/src/modules/monitor/service/monitor.go b/src/modules/monitor/service/monitor.go index 0ed14547..5e836cc8 100644 --- a/src/modules/monitor/service/monitor.go +++ b/src/modules/monitor/service/monitor.go @@ -10,5 +10,5 @@ type IMonitor interface { RunMonitorDataCancel(removeBefore bool, interval float64) // SelectMonitorInfo 查询监控资源信息 - SelectMonitorInfo(query map[string]any) map[string]MonitorData + SelectMonitorInfo(query map[string]any) map[string]any } diff --git a/src/modules/monitor/service/monitor.impl.go b/src/modules/monitor/service/monitor.impl.go index b391745d..6defe4bc 100644 --- a/src/modules/monitor/service/monitor.impl.go +++ b/src/modules/monitor/service/monitor.impl.go @@ -212,14 +212,8 @@ func (s *MonitorImpl) saveNetDataToDB(ctx context.Context, interval float64) { } } -// MonitorData 监控资源信息 -type MonitorData struct { - Date []int64 `json:"date"` - Value []any `json:"value"` -} - // SelectMonitorInfo 查询监控资源信息 -func (s *MonitorImpl) SelectMonitorInfo(query map[string]any) map[string]MonitorData { +func (s *MonitorImpl) SelectMonitorInfo(query map[string]any) map[string]any { infoType := query["type"] startTimeMilli := query["startTime"] endTimeMilli := query["endTime"] @@ -228,7 +222,7 @@ func (s *MonitorImpl) SelectMonitorInfo(query map[string]any) map[string]Monitor name := query["name"] // 返回数据 - backdatas := map[string]MonitorData{} + backDatas := map[string]any{} // 基本信息 if infoType == "all" || infoType == "cpu" || infoType == "memory" { @@ -238,13 +232,7 @@ func (s *MonitorImpl) SelectMonitorInfo(query map[string]any) map[string]Monitor "neType": neType, "neId": neId, }) - // 组装数据 - var itemData MonitorData - for _, base := range rows { - itemData.Date = append(itemData.Date, base.CreateTime) - itemData.Value = append(itemData.Value, base) - } - backdatas["base"] = itemData + backDatas["base"] = rows } // 磁盘IO @@ -256,13 +244,7 @@ func (s *MonitorImpl) SelectMonitorInfo(query map[string]any) map[string]Monitor "neId": neId, "name": name, }) - // 组装数据 - var itemData MonitorData - for _, base := range rows { - itemData.Date = append(itemData.Date, base.CreateTime) - itemData.Value = append(itemData.Value, base) - } - backdatas["io"] = itemData + backDatas["io"] = rows } // 网络 @@ -274,14 +256,8 @@ func (s *MonitorImpl) SelectMonitorInfo(query map[string]any) map[string]Monitor "neId": neId, "name": name, }) - // 组装数据 - var itemData MonitorData - for _, base := range rows { - itemData.Date = append(itemData.Date, base.CreateTime) - itemData.Value = append(itemData.Value, base) - } - backdatas["network"] = itemData + backDatas["network"] = rows } - return backdatas + return backDatas }