mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-04 10:13:53 +08:00
Modify the monitoring table to return field types
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ func FormatCountInt64(count int64) string {
|
|||||||
func FormatCountFloat64(count float64) string {
|
func FormatCountFloat64(count float64) string {
|
||||||
switch {
|
switch {
|
||||||
case count < 1000:
|
case count < 1000:
|
||||||
return strconv.FormatFloat(count, 'f', -1, 64)
|
return fmt.Sprintf("%.1f", count)
|
||||||
case count < 1000000:
|
case count < 1000000:
|
||||||
return fmt.Sprintf("%.1fK", count/1000)
|
return fmt.Sprintf("%.1fK", count/1000)
|
||||||
case count < 1000000000:
|
case count < 1000000000:
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ func (f *fluxQuery) CommonTendencyTag(ctx context.Context, queryApi api.QueryAPI
|
|||||||
tagMap := make(map[string]struct{})
|
tagMap := make(map[string]struct{})
|
||||||
defer result.Close()
|
defer result.Close()
|
||||||
for result.Next() {
|
for result.Next() {
|
||||||
date := result.Record().Values()["_time"].(time.Time).In(time.Local)
|
date := result.Record().Values()["_stop"].(time.Time).In(time.Local)
|
||||||
if _, ok := dateMap[date]; !ok {
|
if _, ok := dateMap[date]; !ok {
|
||||||
dateMap[date] = map[string]struct{}{}
|
dateMap[date] = map[string]struct{}{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,48 +162,53 @@ type TokenFloatOverview struct {
|
|||||||
|
|
||||||
type ChartAIOverview struct {
|
type ChartAIOverview struct {
|
||||||
RequestOverview []*StatusCodeOverview `json:"request_overview"`
|
RequestOverview []*StatusCodeOverview `json:"request_overview"`
|
||||||
AvgRequestPerSubscriber string `json:"avg_request_per_subscriber"` //请求概况
|
|
||||||
AvgRequestPerSubscriberOverview []float64 `json:"avg_request_per_subscriber_overview"` //平均响应时间概况
|
AvgRequestPerSubscriberOverview []float64 `json:"avg_request_per_subscriber_overview"` //平均响应时间概况
|
||||||
RequestTotal string `json:"request_total"`
|
MaxRequestPerSubscriber float64 `json:"max_request_per_subscriber"`
|
||||||
Request2xxTotal string `json:"request_2xx_total"`
|
MinRequestPerSubscriber float64 `json:"min_request_per_subscriber"`
|
||||||
Request4xxTotal string `json:"request_4xx_total"`
|
|
||||||
Request5xxTotal string `json:"request_5xx_total"`
|
RequestTotal int64 `json:"request_total"`
|
||||||
TokenTotal string `json:"token_total"` //总token流量
|
Request2xxTotal int64 `json:"request_2xx_total"`
|
||||||
InputTokenTotal string `json:"input_token_total"`
|
Request4xxTotal int64 `json:"request_4xx_total"`
|
||||||
OutputTokenTotal string `json:"output_token_total"` //最大token流量
|
Request5xxTotal int64 `json:"request_5xx_total"`
|
||||||
TokenOverview []*TokenOverview `json:"token_overview"` //token概况
|
TokenTotal int64 `json:"token_total"` //总token流量
|
||||||
AvgTokenOverview []float64 `json:"avg_token_overview"`
|
InputTokenTotal int64 `json:"input_token_total"`
|
||||||
AvgTokenPerSubscriberOverview []*TokenFloatOverview `json:"avg_token_per_subscriber_overview"`
|
OutputTokenTotal int64 `json:"output_token_total"` //最大token流量
|
||||||
AvgToken string `json:"avg_token"`
|
TokenOverview []*TokenOverview `json:"token_overview"` //token概况
|
||||||
MaxToken string `json:"max_token"`
|
AvgTokenOverview []float64 `json:"avg_token_overview"`
|
||||||
MinToken string `json:"min_token"`
|
AvgTokenPerSubscriberOverview []*TokenFloatOverview `json:"avg_token_per_subscriber_overview"`
|
||||||
AvgTokenPerSubscriber string `json:"avg_token_per_subscriber"`
|
AvgToken float64 `json:"avg_token"`
|
||||||
Date []string `json:"date"`
|
MaxToken float64 `json:"max_token"`
|
||||||
|
MinToken float64 `json:"min_token"`
|
||||||
|
Date []string `json:"date"`
|
||||||
|
MaxTokenPerSubscriber float64 `json:"max_token_per_subscriber"`
|
||||||
|
MinTokenPerSubscriber float64 `json:"min_token_per_subscriber"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChartRestOverview struct {
|
type ChartRestOverview struct {
|
||||||
RequestOverview []*StatusCodeOverview `json:"request_overview"` //请求概况
|
RequestOverview []*StatusCodeOverview `json:"request_overview"` //请求概况
|
||||||
AvgRequestPerSubscriber string `json:"avg_request_per_subscriber"`
|
|
||||||
AvgRequestPerSubscriberOverview []float64 `json:"avg_request_per_subscriber_overview"` //平均响应时间概况
|
AvgRequestPerSubscriberOverview []float64 `json:"avg_request_per_subscriber_overview"` //平均响应时间概况
|
||||||
|
MaxRequestPerSubscriber float64 `json:"max_request_per_subscriber"`
|
||||||
|
MinRequestPerSubscriber float64 `json:"min_request_per_subscriber"`
|
||||||
|
|
||||||
RequestTotal string `json:"request_total"`
|
RequestTotal int64 `json:"request_total"`
|
||||||
Request2xxTotal string `json:"request_2xx_total"`
|
Request2xxTotal int64 `json:"request_2xx_total"`
|
||||||
Request4xxTotal string `json:"request_4xx_total"`
|
Request4xxTotal int64 `json:"request_4xx_total"`
|
||||||
Request5xxTotal string `json:"request_5xx_total"`
|
Request5xxTotal int64 `json:"request_5xx_total"`
|
||||||
|
|
||||||
TrafficOverview []*StatusCodeOverview `json:"traffic_overview"` //流量概况
|
TrafficOverview []*StatusCodeOverview `json:"traffic_overview"` //流量概况
|
||||||
Traffic2xxTotal string `json:"traffic_2xx_total"`
|
Traffic2xxTotal int64 `json:"traffic_2xx_total"`
|
||||||
Traffic4xxTotal string `json:"traffic_4xx_total"` //流量概况
|
Traffic4xxTotal int64 `json:"traffic_4xx_total"` //流量概况
|
||||||
Traffic5xxTotal string `json:"traffic_5xx_total"` //流量概况
|
Traffic5xxTotal int64 `json:"traffic_5xx_total"` //流量概况
|
||||||
|
|
||||||
AvgResponseTimeOverview []int64 `json:"avg_response_time_overview"` //平均响应时间概况
|
AvgResponseTimeOverview []int64 `json:"avg_response_time_overview"` //平均响应时间概况
|
||||||
AvgTrafficPerSubscriberOverview []float64 `json:"avg_traffic_per_subscriber_overview"`
|
AvgTrafficPerSubscriberOverview []float64 `json:"avg_traffic_per_subscriber_overview"`
|
||||||
TrafficTotal string `json:"traffic_total"`
|
TrafficTotal int64 `json:"traffic_total"`
|
||||||
AvgResponseTime string `json:"avg_response_time"` //平均响应时间
|
AvgResponseTime int64 `json:"avg_response_time"` //平均响应时间
|
||||||
MaxResponseTime string `json:"max_response_time"` //最大响应时间
|
MaxResponseTime int64 `json:"max_response_time"` //最大响应时间
|
||||||
MinResponseTime string `json:"min_response_time"` //最小响应时间
|
MinResponseTime int64 `json:"min_response_time"` //最小响应时间
|
||||||
AvgTrafficPerSubscriber string `json:"avg_traffic_per_subscriber"`
|
|
||||||
Date []string `json:"date"`
|
Date []string `json:"date"`
|
||||||
|
MaxTrafficPerSubscriber float64 `json:"max_traffic_per_subscriber"`
|
||||||
|
MinTrafficPerSubscriber float64 `json:"min_traffic_per_subscriber"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServiceChartRestOverview struct {
|
type ServiceChartRestOverview struct {
|
||||||
|
|||||||
+38
-98
@@ -83,33 +83,7 @@ func (i *imlMonitorStatisticModule) AIChartOverview(ctx context.Context, service
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//serviceIds := make([]string, 0)
|
_, consumerMap, err := executor.ConsumerOverview(ctx, formatTimeByMinute(start), formatTimeByMinute(end), wheres)
|
||||||
//// 从数据库中获取相关信息
|
|
||||||
//if serviceId == "" {
|
|
||||||
// // 获取全部服务
|
|
||||||
// list, err := i.serviceService.ServiceListByKind(ctx, service.AIService)
|
|
||||||
// if err != nil {
|
|
||||||
//
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// serviceIds = utils.SliceToSlice(list, func(t *service.Service) string {
|
|
||||||
// return t.Id
|
|
||||||
// })
|
|
||||||
//} else {
|
|
||||||
// serviceIds = append(serviceIds, serviceId)
|
|
||||||
//}
|
|
||||||
//appMap := make(map[string]struct{})
|
|
||||||
//for _, sId := range serviceIds {
|
|
||||||
// items, err := i.subscribeService.ListBySubscribeStatus(ctx, sId, subscribe.ApplyStatusSubscribe)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// for _, item := range items {
|
|
||||||
// appMap[item.Application] = struct{}{}
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//subscriberNum := int64(len(appMap))
|
|
||||||
totalConsumerCount, consumerMap, err := executor.ConsumerOverview(ctx, formatTimeByMinute(start), formatTimeByMinute(end), wheres)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -142,15 +116,11 @@ func (i *imlMonitorStatisticModule) AIChartOverview(ctx context.Context, service
|
|||||||
Status5xx: item.Status5xx,
|
Status5xx: item.Status5xx,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
avgRequestPerSubscriber := 0.0
|
|
||||||
if totalConsumerCount != 0 {
|
result.RequestTotal = summary.StatusTotal
|
||||||
avgRequestPerSubscriber = float64(summary.StatusTotal) / float64(totalConsumerCount)
|
result.Request2xxTotal = summary.Status2xx
|
||||||
}
|
result.Request4xxTotal = summary.Status4xx
|
||||||
result.AvgRequestPerSubscriber = common.FormatCountFloat64(avgRequestPerSubscriber)
|
result.Request5xxTotal = summary.Status5xx
|
||||||
result.RequestTotal = common.FormatCountInt64(summary.StatusTotal)
|
|
||||||
result.Request2xxTotal = common.FormatCountInt64(summary.Status2xx)
|
|
||||||
result.Request4xxTotal = common.FormatCountInt64(summary.Status4xx)
|
|
||||||
result.Request5xxTotal = common.FormatCountInt64(summary.Status5xx)
|
|
||||||
}()
|
}()
|
||||||
sumResponseTimes := make([]int64, 0)
|
sumResponseTimes := make([]int64, 0)
|
||||||
go func() {
|
go func() {
|
||||||
@@ -208,18 +178,16 @@ func (i *imlMonitorStatisticModule) AIChartOverview(ctx context.Context, service
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
avgTokenPerSubscriber := 0.0
|
//avgTokenPerSubscriber := 0.0
|
||||||
if totalConsumerCount != 0 {
|
//if totalConsumerCount != 0 {
|
||||||
avgTokenPerSubscriber = float64(summary.TotalToken) / float64(totalConsumerCount)
|
// avgTokenPerSubscriber = float64(summary.TotalToken) / float64(totalConsumerCount)
|
||||||
}
|
//}
|
||||||
result.AvgToken = common.FormatCountFloat64(avgTokenPerSubscriber)
|
//result.AvgToken = avgTokenPerSubscriber
|
||||||
result.MaxToken = common.FormatCountInt64(maxToken)
|
//result.MaxToken = maxToken
|
||||||
result.MinToken = common.FormatCountInt64(minToken)
|
//result.MinToken = minToken
|
||||||
result.AvgTokenPerSubscriber = common.FormatCountFloat64(avgTokenPerSubscriber)
|
result.TokenTotal = summary.TotalToken
|
||||||
result.AvgTokenPerSubscriber = common.FormatCountInt64(summary.TotalToken / totalConsumerCount)
|
result.InputTokenTotal = summary.InputToken
|
||||||
result.TokenTotal = common.FormatCountInt64(summary.TotalToken)
|
result.OutputTokenTotal = summary.OutputToken
|
||||||
result.InputTokenTotal = common.FormatCountInt64(summary.InputToken)
|
|
||||||
result.OutputTokenTotal = common.FormatCountInt64(summary.OutputToken)
|
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
@@ -251,10 +219,10 @@ func (i *imlMonitorStatisticModule) AIChartOverview(ctx context.Context, service
|
|||||||
avgTokenPerSecond += p
|
avgTokenPerSecond += p
|
||||||
}
|
}
|
||||||
if len(sumResponseTimes) > 0 {
|
if len(sumResponseTimes) > 0 {
|
||||||
result.AvgToken = fmt.Sprintf("%s Token/s", common.FormatCountFloat64(avgTokenPerSecond/float64(len(sumResponseTimes))))
|
result.AvgToken = avgTokenPerSecond / float64(len(sumResponseTimes))
|
||||||
}
|
}
|
||||||
result.MaxToken = fmt.Sprintf("%s Token/s", common.FormatCountFloat64(maxTokenPerSecond))
|
result.MaxToken = maxTokenPerSecond
|
||||||
result.MinToken = fmt.Sprintf("%s Token/s", common.FormatCountFloat64(minTokenPerSecond))
|
result.MinToken = minTokenPerSecond
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,32 +236,7 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//serviceIds := make([]string, 0)
|
_, consumerMap, err := executor.ConsumerOverview(ctx, formatTimeByMinute(start), formatTimeByMinute(end), wheres)
|
||||||
//// 从数据库中获取相关信息
|
|
||||||
//if serviceId == "" {
|
|
||||||
// // 获取全部服务
|
|
||||||
// list, err := i.serviceService.ServiceListByKind(ctx, service.RestService)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// serviceIds = utils.SliceToSlice(list, func(t *service.Service) string {
|
|
||||||
// return t.Id
|
|
||||||
// })
|
|
||||||
//} else {
|
|
||||||
// serviceIds = append(serviceIds, serviceId)
|
|
||||||
//}
|
|
||||||
//appMap := make(map[string]struct{})
|
|
||||||
//for _, sId := range serviceIds {
|
|
||||||
// items, err := i.subscribeService.ListBySubscribeStatus(ctx, sId, subscribe.ApplyStatusSubscribe)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// for _, item := range items {
|
|
||||||
// appMap[item.Id] = struct{}{}
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//subscriberNum := int64(len(appMap))
|
|
||||||
totalConsumerCount, consumerMap, err := executor.ConsumerOverview(ctx, formatTimeByMinute(start), formatTimeByMinute(end), wheres)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -315,6 +258,8 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
|
|||||||
result.AvgRequestPerSubscriberOverview = make([]float64, 0, len(items))
|
result.AvgRequestPerSubscriberOverview = make([]float64, 0, len(items))
|
||||||
result.RequestOverview = make([]*monitor_dto.StatusCodeOverview, 0, len(items))
|
result.RequestOverview = make([]*monitor_dto.StatusCodeOverview, 0, len(items))
|
||||||
for index, item := range items {
|
for index, item := range items {
|
||||||
|
t := date[index]
|
||||||
|
log.Infof("date: %v, item: %v", t, item)
|
||||||
consumerNum := consumerMap[date[index]]
|
consumerNum := consumerMap[date[index]]
|
||||||
avgRequestPerSubscriber := 0.0
|
avgRequestPerSubscriber := 0.0
|
||||||
if consumerNum != 0 {
|
if consumerNum != 0 {
|
||||||
@@ -327,15 +272,14 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
|
|||||||
Status5xx: item.Status5xx,
|
Status5xx: item.Status5xx,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
avgRequestPerSubscriber := 0.0
|
//avgRequestPerSubscriber := 0.0
|
||||||
if totalConsumerCount != 0 {
|
//if totalConsumerCount != 0 {
|
||||||
avgRequestPerSubscriber = float64(summary.StatusTotal) / float64(totalConsumerCount)
|
// avgRequestPerSubscriber = float64(summary.StatusTotal) / float64(totalConsumerCount)
|
||||||
}
|
//}
|
||||||
result.AvgRequestPerSubscriber = common.FormatCountFloat64(avgRequestPerSubscriber)
|
result.RequestTotal = summary.StatusTotal
|
||||||
result.RequestTotal = common.FormatCountInt64(summary.StatusTotal)
|
result.Request2xxTotal = summary.Status2xx
|
||||||
result.Request2xxTotal = common.FormatCountInt64(summary.Status2xx)
|
result.Request4xxTotal = summary.Status4xx
|
||||||
result.Request4xxTotal = common.FormatCountInt64(summary.Status4xx)
|
result.Request5xxTotal = summary.Status5xx
|
||||||
result.Request5xxTotal = common.FormatCountInt64(summary.Status5xx)
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -348,9 +292,9 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result.AvgResponseTimeOverview = items
|
result.AvgResponseTimeOverview = items
|
||||||
result.AvgResponseTime = fmt.Sprintf("%d ms", summary.Avg)
|
result.AvgResponseTime = summary.Avg
|
||||||
result.MaxResponseTime = fmt.Sprintf("%d ms", summary.Max)
|
result.MaxResponseTime = summary.Max
|
||||||
result.MinResponseTime = fmt.Sprintf("%d ms", summary.Min)
|
result.MinResponseTime = summary.Min
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -377,15 +321,11 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
|
|||||||
}
|
}
|
||||||
result.AvgTrafficPerSubscriberOverview = append(result.AvgTrafficPerSubscriberOverview, avgTrafficPerSubscriber)
|
result.AvgTrafficPerSubscriberOverview = append(result.AvgTrafficPerSubscriberOverview, avgTrafficPerSubscriber)
|
||||||
}
|
}
|
||||||
result.TrafficTotal = common.FormatByte(summary.StatusTotal)
|
result.TrafficTotal = summary.StatusTotal
|
||||||
result.Traffic2xxTotal = common.FormatByte(summary.Status2xx)
|
result.Traffic2xxTotal = summary.Status2xx
|
||||||
result.Traffic4xxTotal = common.FormatByte(summary.Status4xx)
|
result.Traffic4xxTotal = summary.Status4xx
|
||||||
result.Traffic5xxTotal = common.FormatByte(summary.Status5xx)
|
result.Traffic5xxTotal = summary.Status5xx
|
||||||
avgTrafficPerSubscriber := 0.0
|
|
||||||
if totalConsumerCount != 0 {
|
|
||||||
avgTrafficPerSubscriber = float64(summary.StatusTotal) / float64(totalConsumerCount)
|
|
||||||
}
|
|
||||||
result.AvgTrafficPerSubscriber = common.FormatCountFloat64(avgTrafficPerSubscriber)
|
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|||||||
Reference in New Issue
Block a user