(ctx context.Context, limit int, input *monitor_dto.CommonInput)
| 1014 | } |
| 1015 | |
| 1016 | func (i *imlMonitorStatisticModule) TopAPIStatistics(ctx context.Context, limit int, input *monitor_dto.CommonInput) ([]*monitor_dto.ApiStatisticItem, error) { |
| 1017 | clusterId := cluster.DefaultClusterID |
| 1018 | wheres, err := i.genCommonWheres(ctx, clusterId) |
| 1019 | if err != nil { |
| 1020 | return nil, err |
| 1021 | } |
| 1022 | |
| 1023 | statisticMap, err := i.statistics(ctx, clusterId, "api", formatTimeByMinute(input.Start), formatTimeByMinute(input.End), wheres, limit) |
| 1024 | if err != nil { |
| 1025 | return nil, err |
| 1026 | } |
| 1027 | |
| 1028 | uuids := utils.MapToSlice(statisticMap, func(key string, value monitor.MonCommonData) string { |
| 1029 | return value.ID |
| 1030 | }) |
| 1031 | apis, err := i.apiService.ListInfo(ctx, uuids...) |
| 1032 | if err != nil { |
| 1033 | return nil, err |
| 1034 | } |
| 1035 | apiMap := utils.SliceToMap(apis, func(t *api.Info) string { |
| 1036 | return t.UUID |
| 1037 | }) |
| 1038 | result := make([]*monitor_dto.ApiStatisticItem, 0, len(statisticMap)) |
| 1039 | for key, item := range statisticMap { |
| 1040 | statisticItem := &monitor_dto.ApiStatisticItem{ |
| 1041 | ApiStatisticBasicItem: &monitor_dto.ApiStatisticBasicItem{ |
| 1042 | Id: key, |
| 1043 | MonCommonData: monitor_dto.ToMonCommonData(item), |
| 1044 | }, |
| 1045 | } |
| 1046 | if a, ok := apiMap[item.ID]; ok { |
| 1047 | statisticItem.Name = a.Name |
| 1048 | statisticItem.Path = a.Path |
| 1049 | statisticItem.Service = auto.UUID(a.Service) |
| 1050 | } else { |
| 1051 | statisticItem.IsRed = true |
| 1052 | if key == "-" { |
| 1053 | statisticItem.Name = "Unknown API" |
| 1054 | } else { |
| 1055 | statisticItem.Name = fmt.Sprintf("Unknow-%s", key) |
| 1056 | } |
| 1057 | } |
| 1058 | result = append(result, statisticItem) |
| 1059 | } |
| 1060 | sort.Slice(result, func(i, j int) bool { |
| 1061 | return result[i].RequestTotal > result[j].RequestTotal |
| 1062 | }) |
| 1063 | return result, nil |
| 1064 | |
| 1065 | } |
| 1066 | |
| 1067 | func (i *imlMonitorStatisticModule) TopSubscriberStatistics(ctx context.Context, limit int, input *monitor_dto.CommonInput) ([]*monitor_dto.ServiceStatisticItem, error) { |
| 1068 | clusterId := cluster.DefaultClusterID |
nothing calls this directly
no test coverage detected