@@ -2,6 +2,7 @@ package monitor
22
33import (
44 "fmt"
5+ "strconv"
56 "time"
67
78 "github.com/APIParkLab/APIPark/module/monitor"
@@ -17,6 +18,66 @@ type imlMonitorStatisticController struct {
1718 module monitor.IMonitorStatisticModule `autowired:""`
1819}
1920
21+ func (i * imlMonitorStatisticController ) ChartRestOverview (ctx * gin.Context , start string , end string ) (* monitor_dto.ChartRestOverview , error ) {
22+ s , e , err := formatTime (start , end )
23+ if err != nil {
24+ return nil , err
25+ }
26+ return i .module .RestChartOverview (ctx , "" , s , e )
27+ }
28+
29+ func (i * imlMonitorStatisticController ) ChartAIOverview (ctx * gin.Context , start string , end string ) (* monitor_dto.ChartAIOverview , error ) {
30+ s , e , err := formatTime (start , end )
31+ if err != nil {
32+ return nil , err
33+ }
34+ return i .module .AIChartOverview (ctx , "" , s , e )
35+ }
36+
37+ func (i * imlMonitorStatisticController ) AITopN (ctx * gin.Context , start string , end string , limit string ) ([]* monitor_dto.TopN , []* monitor_dto.TopN , error ) {
38+ s , e , err := formatTime (start , end )
39+ if err != nil {
40+ return nil , nil , err
41+ }
42+ l , err := strconv .Atoi (limit )
43+ if err != nil {
44+ if limit == "" {
45+ l = 10
46+ } else {
47+ return nil , nil , fmt .Errorf ("parse limit %s error: %w" , limit , err )
48+ }
49+ }
50+ return i .module .Top (ctx , "" , s , e , l , "ai" )
51+ }
52+
53+ func formatTime (start string , end string ) (int64 , int64 , error ) {
54+ s , err := strconv .ParseInt (start , 10 , 64 )
55+ if err != nil {
56+ return 0 , 0 , fmt .Errorf ("parse start time %s error: %w" , start , err )
57+ }
58+ e , err := strconv .ParseInt (end , 10 , 64 )
59+ if err != nil {
60+ return 0 , 0 , fmt .Errorf ("parse end time %s error: %w" , end , err )
61+ }
62+ return s , e , nil
63+ }
64+
65+ func (i * imlMonitorStatisticController ) RestTopN (ctx * gin.Context , start string , end string , limit string ) ([]* monitor_dto.TopN , []* monitor_dto.TopN , error ) {
66+ s , e , err := formatTime (start , end )
67+ if err != nil {
68+ return nil , nil , err
69+ }
70+ l , err := strconv .Atoi (limit )
71+ if err != nil {
72+ if limit == "" {
73+ l = 10
74+ } else {
75+ return nil , nil , fmt .Errorf ("parse limit %s error: %w" , limit , err )
76+ }
77+ }
78+ return i .module .Top (ctx , "" , s , e , l , "rest" )
79+ }
80+
2081func (i * imlMonitorStatisticController ) Statistics (ctx * gin.Context , dataType string , input * monitor_dto.StatisticInput ) (interface {}, error ) {
2182 switch dataType {
2283 case monitor_dto .DataTypeApi :
0 commit comments