diff --git a/internal/database/database.go b/internal/database/database.go index a7da1b5..7234186 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -946,6 +946,23 @@ func (d *Database) GetStatsContext(ctx context.Context) (Stats, error) { } stats.LiveRoutes = v4Count + v6Count + // Get oldest and newest route timestamps + routeTimestampQuery := ` + SELECT MIN(last_updated), MAX(last_updated) FROM ( + SELECT last_updated FROM live_routes_v4 + UNION ALL + SELECT last_updated FROM live_routes_v6 + ) + ` + var oldestRoute, newestRoute *time.Time + err = d.db.QueryRowContext(ctx, routeTimestampQuery).Scan(&oldestRoute, &newestRoute) + if err != nil { + d.logger.Warn("Failed to get route timestamps", "error", err) + } else { + stats.OldestRoute = oldestRoute + stats.NewestRoute = newestRoute + } + // Get prefix distribution stats.IPv4PrefixDistribution, stats.IPv6PrefixDistribution, err = d.GetPrefixDistributionContext(ctx) if err != nil { diff --git a/internal/database/interface.go b/internal/database/interface.go index fb0f5c8..2c01173 100644 --- a/internal/database/interface.go +++ b/internal/database/interface.go @@ -18,6 +18,8 @@ type Stats struct { Peers int FileSizeBytes int64 LiveRoutes int + OldestRoute *time.Time + NewestRoute *time.Time IPv4PrefixDistribution []PrefixDistribution IPv6PrefixDistribution []PrefixDistribution } diff --git a/internal/server/handlers.go b/internal/server/handlers.go index 4464153..9aab1b1 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -164,6 +164,8 @@ func (s *Server) handleStatusJSON() http.HandlerFunc { LiveRoutes int `json:"live_routes"` IPv4Routes int `json:"ipv4_routes"` IPv6Routes int `json:"ipv6_routes"` + OldestRoute *time.Time `json:"oldest_route,omitempty"` + NewestRoute *time.Time `json:"newest_route,omitempty"` IPv4UpdatesPerSec float64 `json:"ipv4_updates_per_sec"` IPv6UpdatesPerSec float64 `json:"ipv6_updates_per_sec"` IPv4PrefixDistribution []database.PrefixDistribution `json:"ipv4_prefix_distribution"` @@ -258,6 +260,8 @@ func (s *Server) handleStatusJSON() http.HandlerFunc { LiveRoutes: dbStats.LiveRoutes, IPv4Routes: ipv4Routes, IPv6Routes: ipv6Routes, + OldestRoute: dbStats.OldestRoute, + NewestRoute: dbStats.NewestRoute, IPv4UpdatesPerSec: routeMetrics.IPv4UpdatesPerSec, IPv6UpdatesPerSec: routeMetrics.IPv6UpdatesPerSec, IPv4PrefixDistribution: dbStats.IPv4PrefixDistribution, @@ -369,6 +373,8 @@ func (s *Server) handleStats() http.HandlerFunc { LiveRoutes int `json:"live_routes"` IPv4Routes int `json:"ipv4_routes"` IPv6Routes int `json:"ipv6_routes"` + OldestRoute *time.Time `json:"oldest_route,omitempty"` + NewestRoute *time.Time `json:"newest_route,omitempty"` IPv4UpdatesPerSec float64 `json:"ipv4_updates_per_sec"` IPv6UpdatesPerSec float64 `json:"ipv6_updates_per_sec"` HandlerStats []HandlerStatsInfo `json:"handler_stats"` @@ -530,6 +536,8 @@ func (s *Server) handleStats() http.HandlerFunc { LiveRoutes: dbStats.LiveRoutes, IPv4Routes: ipv4Routes, IPv6Routes: ipv6Routes, + OldestRoute: dbStats.OldestRoute, + NewestRoute: dbStats.NewestRoute, IPv4UpdatesPerSec: routeMetrics.IPv4UpdatesPerSec, IPv6UpdatesPerSec: routeMetrics.IPv6UpdatesPerSec, HandlerStats: handlerStatsInfo, diff --git a/internal/templates/status.html b/internal/templates/status.html index bcdfbb5..86a38ff 100644 --- a/internal/templates/status.html +++ b/internal/templates/status.html @@ -321,6 +321,14 @@ IPv6 Updates/sec - +