2024-01-01 10:07:21 +00:00
|
|
|
package sideload
|
|
|
|
|
|
|
|
import (
|
2024-09-29 15:03:11 +00:00
|
|
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi"
|
|
|
|
"git.solsynth.dev/goatworks/roadsign/pkg/warden"
|
2024-01-01 10:07:21 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/samber/lo"
|
2024-10-01 15:33:18 +00:00
|
|
|
"time"
|
2024-01-01 10:07:21 +00:00
|
|
|
)
|
|
|
|
|
2024-01-25 16:11:44 +00:00
|
|
|
func getStats(c *fiber.Ctx) error {
|
2024-01-24 16:09:39 +00:00
|
|
|
locations := lo.FlatMap(navi.R.Regions, func(item *navi.Region, idx int) []navi.Location {
|
|
|
|
return item.Locations
|
2024-01-01 10:07:21 +00:00
|
|
|
})
|
2024-01-24 16:09:39 +00:00
|
|
|
destinations := lo.FlatMap(locations, func(item navi.Location, idx int) []navi.Destination {
|
|
|
|
return item.Destinations
|
2024-01-01 10:07:21 +00:00
|
|
|
})
|
2024-01-24 16:09:39 +00:00
|
|
|
applications := lo.FlatMap(navi.R.Regions, func(item *navi.Region, idx int) []warden.Application {
|
|
|
|
return item.Applications
|
2024-01-01 10:07:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return c.JSON(fiber.Map{
|
2024-01-25 16:11:44 +00:00
|
|
|
"regions": len(navi.R.Regions),
|
|
|
|
"locations": len(locations),
|
2024-01-24 16:09:39 +00:00
|
|
|
"destinations": len(destinations),
|
|
|
|
"applications": len(applications),
|
2024-10-01 15:33:18 +00:00
|
|
|
"uptime": time.Since(navi.R.Metrics.StartupAt).Milliseconds(),
|
|
|
|
"traffic": fiber.Map{
|
|
|
|
"total": navi.R.Metrics.TotalTraffic,
|
|
|
|
"unique_client": len(navi.R.Metrics.TrafficFrom),
|
|
|
|
},
|
2024-01-01 10:07:21 +00:00
|
|
|
})
|
|
|
|
}
|