Add database file size and reorganize status page
- Add database file size tracking to Stats struct and GetStats() - Move routing table metrics to separate 'Routing Table' status box - Add IPv4/IPv6 updates per second to routing table metrics - Database box now shows: ASNs, prefixes, peerings, and database size - Routing table box shows: live routes, IPv4/IPv6 counts, and update rates
This commit is contained in:
@@ -25,6 +25,7 @@ const dirPermissions = 0750 // rwxr-x---
|
||||
type Database struct {
|
||||
db *sql.DB
|
||||
logger *slog.Logger
|
||||
path string
|
||||
}
|
||||
|
||||
// Config holds database configuration
|
||||
@@ -112,7 +113,7 @@ func NewWithConfig(config Config, logger *slog.Logger) (*Database, error) {
|
||||
db.SetMaxIdleConns(1)
|
||||
db.SetConnMaxLifetime(0)
|
||||
|
||||
database := &Database{db: db, logger: logger}
|
||||
database := &Database{db: db, logger: logger, path: config.Path}
|
||||
|
||||
if err := database.Initialize(); err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize database: %w", err)
|
||||
@@ -437,6 +438,16 @@ func (d *Database) GetStats() (Stats, error) {
|
||||
return stats, err
|
||||
}
|
||||
|
||||
// Get database file size
|
||||
d.logger.Info("Getting database file size")
|
||||
fileInfo, err := os.Stat(d.path)
|
||||
if err != nil {
|
||||
d.logger.Warn("Failed to get database file size", "error", err)
|
||||
stats.FileSizeBytes = 0
|
||||
} else {
|
||||
stats.FileSizeBytes = fileInfo.Size()
|
||||
}
|
||||
|
||||
d.logger.Info("Stats collection complete")
|
||||
|
||||
return stats, nil
|
||||
|
||||
@@ -6,11 +6,12 @@ import (
|
||||
|
||||
// Stats contains database statistics
|
||||
type Stats struct {
|
||||
ASNs int
|
||||
Prefixes int
|
||||
IPv4Prefixes int
|
||||
IPv6Prefixes int
|
||||
Peerings int
|
||||
ASNs int
|
||||
Prefixes int
|
||||
IPv4Prefixes int
|
||||
IPv6Prefixes int
|
||||
Peerings int
|
||||
FileSizeBytes int64
|
||||
}
|
||||
|
||||
// Store defines the interface for database operations
|
||||
|
||||
Reference in New Issue
Block a user