MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / TopAPIStatistics

Method TopAPIStatistics

module/monitor/iml.go:1016–1065  ·  view source on GitHub ↗
(ctx context.Context, limit int, input *monitor_dto.CommonInput)

Source from the content-addressed store, hash-verified

1014}
1015
1016func (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
1067func (i *imlMonitorStatisticModule) TopSubscriberStatistics(ctx context.Context, limit int, input *monitor_dto.CommonInput) ([]*monitor_dto.ServiceStatisticItem, error) {
1068 clusterId := cluster.DefaultClusterID

Callers

nothing calls this directly

Calls 4

genCommonWheresMethod · 0.95
statisticsMethod · 0.95
formatTimeByMinuteFunction · 0.70
ListInfoMethod · 0.65

Tested by

no test coverage detected