@@ -6,6 +6,29 @@ import (
66 "github.com/gin-gonic/gin"
77)
88
9+ type dashboardOverviewPayload struct {
10+ GeneratedAt any `json:"generated_at"`
11+ Summary service.DashboardSummary `json:"summary"`
12+ Traffic service.DashboardTraffic `json:"traffic"`
13+ Capacity service.DashboardCapacity `json:"capacity"`
14+ Distributions dashboardDistributionsPayload `json:"distributions"`
15+ Trends dashboardTrendsPayload `json:"trends"`
16+ Nodes [][]any `json:"nodes"`
17+ }
18+
19+ type dashboardDistributionsPayload struct {
20+ StatusCodes [][]any `json:"status_codes"`
21+ TopDomains [][]any `json:"top_domains"`
22+ SourceCountries [][]any `json:"source_countries"`
23+ }
24+
25+ type dashboardTrendsPayload struct {
26+ Traffic24h [][]any `json:"traffic_24h"`
27+ Capacity24h [][]any `json:"capacity_24h"`
28+ Network24h [][]any `json:"network_24h"`
29+ DiskIO24h [][]any `json:"disk_io_24h"`
30+ }
31+
932// GetDashboardOverview godoc
1033// @Summary Get dashboard overview
1134// @Tags Dashboard
@@ -20,5 +43,130 @@ func GetDashboardOverview(c *gin.Context) {
2043 respondFailure (c , err .Error ())
2144 return
2245 }
23- respondSuccess (c , view )
46+ respondSuccess (c , compressDashboardOverview (view ))
47+ }
48+
49+ func compressDashboardOverview (view * service.DashboardOverviewView ) * dashboardOverviewPayload {
50+ if view == nil {
51+ return & dashboardOverviewPayload {
52+ Distributions : dashboardDistributionsPayload {
53+ StatusCodes : [][]any {},
54+ TopDomains : [][]any {},
55+ SourceCountries : [][]any {},
56+ },
57+ Trends : dashboardTrendsPayload {
58+ Traffic24h : [][]any {},
59+ Capacity24h : [][]any {},
60+ Network24h : [][]any {},
61+ DiskIO24h : [][]any {},
62+ },
63+ Nodes : [][]any {},
64+ }
65+ }
66+ return & dashboardOverviewPayload {
67+ GeneratedAt : view .GeneratedAt ,
68+ Summary : view .Summary ,
69+ Traffic : view .Traffic ,
70+ Capacity : view .Capacity ,
71+ Distributions : dashboardDistributionsPayload {
72+ StatusCodes : compressDistributionItems (view .Distributions .StatusCodes ),
73+ TopDomains : compressDistributionItems (view .Distributions .TopDomains ),
74+ SourceCountries : compressDistributionItems (view .Distributions .SourceCountries ),
75+ },
76+ Trends : dashboardTrendsPayload {
77+ Traffic24h : compressTrafficTrendPoints (view .Trends .Traffic24h ),
78+ Capacity24h : compressCapacityTrendPoints (view .Trends .Capacity24h ),
79+ Network24h : compressNetworkTrendPoints (view .Trends .Network24h ),
80+ DiskIO24h : compressDiskIOTrendPoints (view .Trends .DiskIO24h ),
81+ },
82+ Nodes : compressDashboardNodes (view .Nodes ),
83+ }
84+ }
85+
86+ func compressDistributionItems (items []service.DistributionItem ) [][]any {
87+ rows := make ([][]any , 0 , len (items ))
88+ for _ , item := range items {
89+ rows = append (rows , []any {item .Key , item .Value })
90+ }
91+ return rows
92+ }
93+
94+ func compressTrafficTrendPoints (points []service.TrafficTrendPoint ) [][]any {
95+ rows := make ([][]any , 0 , len (points ))
96+ for _ , point := range points {
97+ rows = append (rows , []any {
98+ point .BucketStartedAt ,
99+ point .RequestCount ,
100+ point .ErrorCount ,
101+ point .UniqueVisitorCount ,
102+ })
103+ }
104+ return rows
105+ }
106+
107+ func compressCapacityTrendPoints (points []service.CapacityTrendPoint ) [][]any {
108+ rows := make ([][]any , 0 , len (points ))
109+ for _ , point := range points {
110+ rows = append (rows , []any {
111+ point .BucketStartedAt ,
112+ point .AverageCPUUsagePercent ,
113+ point .AverageMemoryUsagePercent ,
114+ point .ReportedNodes ,
115+ })
116+ }
117+ return rows
118+ }
119+
120+ func compressNetworkTrendPoints (points []service.NetworkTrendPoint ) [][]any {
121+ rows := make ([][]any , 0 , len (points ))
122+ for _ , point := range points {
123+ rows = append (rows , []any {
124+ point .BucketStartedAt ,
125+ point .NetworkRxBytes ,
126+ point .NetworkTxBytes ,
127+ point .OpenrestyRxBytes ,
128+ point .OpenrestyTxBytes ,
129+ point .ReportedNodes ,
130+ })
131+ }
132+ return rows
133+ }
134+
135+ func compressDiskIOTrendPoints (points []service.DiskIOTrendPoint ) [][]any {
136+ rows := make ([][]any , 0 , len (points ))
137+ for _ , point := range points {
138+ rows = append (rows , []any {
139+ point .BucketStartedAt ,
140+ point .DiskReadBytes ,
141+ point .DiskWriteBytes ,
142+ point .ReportedNodes ,
143+ })
144+ }
145+ return rows
146+ }
147+
148+ func compressDashboardNodes (nodes []service.DashboardNodeHealth ) [][]any {
149+ rows := make ([][]any , 0 , len (nodes ))
150+ for _ , node := range nodes {
151+ rows = append (rows , []any {
152+ node .ID ,
153+ node .NodeID ,
154+ node .Name ,
155+ node .GeoName ,
156+ node .GeoLatitude ,
157+ node .GeoLongitude ,
158+ node .Status ,
159+ node .OpenrestyStatus ,
160+ node .CurrentVersion ,
161+ node .LastSeenAt ,
162+ node .ActiveEventCount ,
163+ node .CPUUsagePercent ,
164+ node .MemoryUsagePercent ,
165+ node .StorageUsagePercent ,
166+ node .RequestCount ,
167+ node .ErrorCount ,
168+ node .UniqueVisitorCount ,
169+ })
170+ }
171+ return rows
24172}
0 commit comments