Modify the monitoring table to return field types

This commit is contained in:
Liujian
2025-05-06 10:43:09 +08:00
parent 9572c4157e
commit ef1c48e395
4 changed files with 75 additions and 130 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ func FormatCountInt64(count int64) string {
func FormatCountFloat64(count float64) string {
switch {
case count < 1000:
return strconv.FormatFloat(count, 'f', -1, 64)
return fmt.Sprintf("%.1f", count)
case count < 1000000:
return fmt.Sprintf("%.1fK", count/1000)
case count < 1000000000:
@@ -184,7 +184,7 @@ func (f *fluxQuery) CommonTendencyTag(ctx context.Context, queryApi api.QueryAPI
tagMap := make(map[string]struct{})
defer result.Close()
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 {
dateMap[date] = map[string]struct{}{}
}
+35 -30
View File
@@ -162,48 +162,53 @@ type TokenFloatOverview struct {
type ChartAIOverview struct {
RequestOverview []*StatusCodeOverview `json:"request_overview"`
AvgRequestPerSubscriber string `json:"avg_request_per_subscriber"` //请求概况
AvgRequestPerSubscriberOverview []float64 `json:"avg_request_per_subscriber_overview"` //平均响应时间概况
RequestTotal string `json:"request_total"`
Request2xxTotal string `json:"request_2xx_total"`
Request4xxTotal string `json:"request_4xx_total"`
Request5xxTotal string `json:"request_5xx_total"`
TokenTotal string `json:"token_total"` //总token流量
InputTokenTotal string `json:"input_token_total"`
OutputTokenTotal string `json:"output_token_total"` //最大token流量
TokenOverview []*TokenOverview `json:"token_overview"` //token概况
AvgTokenOverview []float64 `json:"avg_token_overview"`
AvgTokenPerSubscriberOverview []*TokenFloatOverview `json:"avg_token_per_subscriber_overview"`
AvgToken string `json:"avg_token"`
MaxToken string `json:"max_token"`
MinToken string `json:"min_token"`
AvgTokenPerSubscriber string `json:"avg_token_per_subscriber"`
Date []string `json:"date"`
MaxRequestPerSubscriber float64 `json:"max_request_per_subscriber"`
MinRequestPerSubscriber float64 `json:"min_request_per_subscriber"`
RequestTotal int64 `json:"request_total"`
Request2xxTotal int64 `json:"request_2xx_total"`
Request4xxTotal int64 `json:"request_4xx_total"`
Request5xxTotal int64 `json:"request_5xx_total"`
TokenTotal int64 `json:"token_total"` //token流量
InputTokenTotal int64 `json:"input_token_total"`
OutputTokenTotal int64 `json:"output_token_total"` //最大token流量
TokenOverview []*TokenOverview `json:"token_overview"` //token概况
AvgTokenOverview []float64 `json:"avg_token_overview"`
AvgTokenPerSubscriberOverview []*TokenFloatOverview `json:"avg_token_per_subscriber_overview"`
AvgToken float64 `json:"avg_token"`
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 {
RequestOverview []*StatusCodeOverview `json:"request_overview"` //请求概况
AvgRequestPerSubscriber string `json:"avg_request_per_subscriber"`
RequestOverview []*StatusCodeOverview `json:"request_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"`
Request2xxTotal string `json:"request_2xx_total"`
Request4xxTotal string `json:"request_4xx_total"`
Request5xxTotal string `json:"request_5xx_total"`
RequestTotal int64 `json:"request_total"`
Request2xxTotal int64 `json:"request_2xx_total"`
Request4xxTotal int64 `json:"request_4xx_total"`
Request5xxTotal int64 `json:"request_5xx_total"`
TrafficOverview []*StatusCodeOverview `json:"traffic_overview"` //流量概况
Traffic2xxTotal string `json:"traffic_2xx_total"`
Traffic4xxTotal string `json:"traffic_4xx_total"` //流量概况
Traffic5xxTotal string `json:"traffic_5xx_total"` //流量概况
Traffic2xxTotal int64 `json:"traffic_2xx_total"`
Traffic4xxTotal int64 `json:"traffic_4xx_total"` //流量概况
Traffic5xxTotal int64 `json:"traffic_5xx_total"` //流量概况
AvgResponseTimeOverview []int64 `json:"avg_response_time_overview"` //平均响应时间概况
AvgTrafficPerSubscriberOverview []float64 `json:"avg_traffic_per_subscriber_overview"`
TrafficTotal string `json:"traffic_total"`
AvgResponseTime string `json:"avg_response_time"` //平均响应时间
MaxResponseTime string `json:"max_response_time"` //最大响应时间
MinResponseTime string `json:"min_response_time"` //最小响应时间
AvgTrafficPerSubscriber string `json:"avg_traffic_per_subscriber"`
TrafficTotal int64 `json:"traffic_total"`
AvgResponseTime int64 `json:"avg_response_time"` //平均响应时间
MaxResponseTime int64 `json:"max_response_time"` //最大响应时间
MinResponseTime int64 `json:"min_response_time"` //最小响应时间
Date []string `json:"date"`
MaxTrafficPerSubscriber float64 `json:"max_traffic_per_subscriber"`
MinTrafficPerSubscriber float64 `json:"min_traffic_per_subscriber"`
}
type ServiceChartRestOverview struct {
+38 -98
View File
@@ -83,33 +83,7 @@ func (i *imlMonitorStatisticModule) AIChartOverview(ctx context.Context, service
return nil, err
}
//serviceIds := make([]string, 0)
//// 从数据库中获取相关信息
//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)
_, consumerMap, err := executor.ConsumerOverview(ctx, formatTimeByMinute(start), formatTimeByMinute(end), wheres)
if err != nil {
return nil, err
}
@@ -142,15 +116,11 @@ func (i *imlMonitorStatisticModule) AIChartOverview(ctx context.Context, service
Status5xx: item.Status5xx,
})
}
avgRequestPerSubscriber := 0.0
if totalConsumerCount != 0 {
avgRequestPerSubscriber = float64(summary.StatusTotal) / float64(totalConsumerCount)
}
result.AvgRequestPerSubscriber = common.FormatCountFloat64(avgRequestPerSubscriber)
result.RequestTotal = common.FormatCountInt64(summary.StatusTotal)
result.Request2xxTotal = common.FormatCountInt64(summary.Status2xx)
result.Request4xxTotal = common.FormatCountInt64(summary.Status4xx)
result.Request5xxTotal = common.FormatCountInt64(summary.Status5xx)
result.RequestTotal = summary.StatusTotal
result.Request2xxTotal = summary.Status2xx
result.Request4xxTotal = summary.Status4xx
result.Request5xxTotal = summary.Status5xx
}()
sumResponseTimes := make([]int64, 0)
go func() {
@@ -208,18 +178,16 @@ func (i *imlMonitorStatisticModule) AIChartOverview(ctx context.Context, service
})
}
avgTokenPerSubscriber := 0.0
if totalConsumerCount != 0 {
avgTokenPerSubscriber = float64(summary.TotalToken) / float64(totalConsumerCount)
}
result.AvgToken = common.FormatCountFloat64(avgTokenPerSubscriber)
result.MaxToken = common.FormatCountInt64(maxToken)
result.MinToken = common.FormatCountInt64(minToken)
result.AvgTokenPerSubscriber = common.FormatCountFloat64(avgTokenPerSubscriber)
result.AvgTokenPerSubscriber = common.FormatCountInt64(summary.TotalToken / totalConsumerCount)
result.TokenTotal = common.FormatCountInt64(summary.TotalToken)
result.InputTokenTotal = common.FormatCountInt64(summary.InputToken)
result.OutputTokenTotal = common.FormatCountInt64(summary.OutputToken)
//avgTokenPerSubscriber := 0.0
//if totalConsumerCount != 0 {
// avgTokenPerSubscriber = float64(summary.TotalToken) / float64(totalConsumerCount)
//}
//result.AvgToken = avgTokenPerSubscriber
//result.MaxToken = maxToken
//result.MinToken = minToken
result.TokenTotal = summary.TotalToken
result.InputTokenTotal = summary.InputToken
result.OutputTokenTotal = summary.OutputToken
}()
go func() {
wg.Wait()
@@ -251,10 +219,10 @@ func (i *imlMonitorStatisticModule) AIChartOverview(ctx context.Context, service
avgTokenPerSecond += p
}
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.MinToken = fmt.Sprintf("%s Token/s", common.FormatCountFloat64(minTokenPerSecond))
result.MaxToken = maxTokenPerSecond
result.MinToken = minTokenPerSecond
return result, nil
}
@@ -268,32 +236,7 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
return nil, err
}
//serviceIds := make([]string, 0)
//// 从数据库中获取相关信息
//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)
_, consumerMap, err := executor.ConsumerOverview(ctx, formatTimeByMinute(start), formatTimeByMinute(end), wheres)
if err != nil {
return nil, err
}
@@ -315,6 +258,8 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
result.AvgRequestPerSubscriberOverview = make([]float64, 0, len(items))
result.RequestOverview = make([]*monitor_dto.StatusCodeOverview, 0, len(items))
for index, item := range items {
t := date[index]
log.Infof("date: %v, item: %v", t, item)
consumerNum := consumerMap[date[index]]
avgRequestPerSubscriber := 0.0
if consumerNum != 0 {
@@ -327,15 +272,14 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
Status5xx: item.Status5xx,
})
}
avgRequestPerSubscriber := 0.0
if totalConsumerCount != 0 {
avgRequestPerSubscriber = float64(summary.StatusTotal) / float64(totalConsumerCount)
}
result.AvgRequestPerSubscriber = common.FormatCountFloat64(avgRequestPerSubscriber)
result.RequestTotal = common.FormatCountInt64(summary.StatusTotal)
result.Request2xxTotal = common.FormatCountInt64(summary.Status2xx)
result.Request4xxTotal = common.FormatCountInt64(summary.Status4xx)
result.Request5xxTotal = common.FormatCountInt64(summary.Status5xx)
//avgRequestPerSubscriber := 0.0
//if totalConsumerCount != 0 {
// avgRequestPerSubscriber = float64(summary.StatusTotal) / float64(totalConsumerCount)
//}
result.RequestTotal = summary.StatusTotal
result.Request2xxTotal = summary.Status2xx
result.Request4xxTotal = summary.Status4xx
result.Request5xxTotal = summary.Status5xx
}()
go func() {
@@ -348,9 +292,9 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
return
}
result.AvgResponseTimeOverview = items
result.AvgResponseTime = fmt.Sprintf("%d ms", summary.Avg)
result.MaxResponseTime = fmt.Sprintf("%d ms", summary.Max)
result.MinResponseTime = fmt.Sprintf("%d ms", summary.Min)
result.AvgResponseTime = summary.Avg
result.MaxResponseTime = summary.Max
result.MinResponseTime = summary.Min
}()
go func() {
@@ -377,15 +321,11 @@ func (i *imlMonitorStatisticModule) RestChartOverview(ctx context.Context, servi
}
result.AvgTrafficPerSubscriberOverview = append(result.AvgTrafficPerSubscriberOverview, avgTrafficPerSubscriber)
}
result.TrafficTotal = common.FormatByte(summary.StatusTotal)
result.Traffic2xxTotal = common.FormatByte(summary.Status2xx)
result.Traffic4xxTotal = common.FormatByte(summary.Status4xx)
result.Traffic5xxTotal = common.FormatByte(summary.Status5xx)
avgTrafficPerSubscriber := 0.0
if totalConsumerCount != 0 {
avgTrafficPerSubscriber = float64(summary.StatusTotal) / float64(totalConsumerCount)
}
result.AvgTrafficPerSubscriber = common.FormatCountFloat64(avgTrafficPerSubscriber)
result.TrafficTotal = summary.StatusTotal
result.Traffic2xxTotal = summary.Status2xx
result.Traffic4xxTotal = summary.Status4xx
result.Traffic5xxTotal = summary.Status5xx
}()
go func() {
wg.Wait()