Skip to content

🚁 High-performance distributed SBS/ADS-B message processor with real-time aircraft tracking, flight session management, and TimescaleDB storage. Built with Go microservices and NATS messaging.

License

Notifications You must be signed in to change notification settings

saviobatista/sbs-logger

Repository files navigation

SBS Logger

Go Version License Go Report Card Code Coverage Security Scan Docker Build Trivy Security Go Modules Dependabot GitHub Issues GitHub Pull Requests

A high-performance, distributed Go application for capturing, processing, and storing SBS (BaseStation) messages from ADS-B receivers. The system provides real-time aircraft tracking, flight session management, and comprehensive data persistence with TimescaleDB.

πŸš€ Features

  • Real-time SBS Message Ingestion: Connects to multiple ADS-B receivers simultaneously
  • Distributed Architecture: Microservices-based design with NATS messaging
  • Aircraft State Tracking: Real-time position, altitude, speed, and flight data
  • Flight Session Management: Automatic flight detection and session tracking
  • High-Performance Storage: TimescaleDB for time-series data with automatic retention policies
  • Redis Caching: Fast access to active aircraft states and flight data
  • Comprehensive Logging: Daily log rotation with automatic compression
  • Statistics & Monitoring: Real-time system metrics and performance tracking
  • Docker Support: Complete containerized deployment with docker-compose

πŸ›‘οΈ Quality & Security

This project maintains high code quality and security standards through automated checks:

  • πŸ” Code Quality: Automated linting with golangci-lint
  • πŸ§ͺ Testing: Comprehensive unit and integration tests with race condition detection
  • πŸ“Š Code Coverage: Continuous coverage tracking with Codecov
  • πŸ”’ Security Scanning: Automated vulnerability scanning with Trivy
  • 🐳 Container Security: Docker image scanning and multi-platform builds
  • πŸ“‹ Go Report Card: Code quality analysis and grading
  • πŸ”„ CI/CD: Automated testing, building, and deployment pipeline

πŸ—οΈ Architecture

The system consists of several microservices that communicate via NATS:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Ingestor  │───▢│     NATS    │───▢│   Logger    β”‚
β”‚             β”‚    β”‚             β”‚    β”‚             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           β–Ό
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚   Tracker   β”‚
                   β”‚             β”‚
                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
                    β–Ό             β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ TimescaleDB β”‚ β”‚    Redis    β”‚
            β”‚             β”‚ β”‚             β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Components

  • Ingestor: Connects to SBS sources and publishes messages to NATS
  • Logger: Subscribes to messages and writes to daily log files
  • Tracker: Processes messages, tracks aircraft states, manages flight sessions, and handles database migrations
  • NATS: Message broker for inter-service communication
  • TimescaleDB: Time-series database for aircraft states and statistics
  • Redis: Caching layer for active aircraft and flight data

πŸ“‹ Prerequisites

  • Go 1.24.5 or later
  • Docker and Docker Compose
  • PostgreSQL/TimescaleDB
  • Redis
  • NATS Server

πŸ› οΈ Installation

Option 1: Docker Compose (Recommended)

  1. Clone the repository:
git clone https://github.com/saviobatista/sbs-logger.git
cd sbs-logger
  1. Configure environment variables:
# Copy the sample environment file
cp .env.sample .env

# Edit the .env file with your configuration
nano .env
  1. Update the key variables in .env:
# Your ADS-B receiver(s)
SOURCES=your-adsb-receiver:30003,another-receiver:30003

# Your receiver location (for Ultrafeeder)
ULTRAFEEDER_LAT=your_latitude
ULTRAFEEDER_LON=your_longitude
ULTRAFEEDER_ALT=your_altitude

# Database credentials (change for production)
POSTGRES_PASSWORD=your_secure_password
  1. Start the services:
docker-compose up -d

Option 2: Manual Build

  1. Install dependencies:
go mod download
  1. Build all components:
go build ./cmd/ingestor
go build ./cmd/logger
go build ./cmd/tracker
  1. Start the services:
# Migrations will run automatically when the tracker service starts
./tracker

The tracker service will automatically run database migrations on startup.

βš™οΈ Configuration

Environment Setup

The project uses a .env file for configuration. Start by copying the sample file:

cp .env.sample .env

Environment Variables

Ingestor

  • SOURCES: Comma-separated list of SBS sources (e.g., 10.0.0.1:30003,10.0.0.2:30003)
  • NATS_URL: NATS server URL (default: nats://nats:4222)

Logger

  • OUTPUT_DIR: Directory for log files (default: ./logs)
  • NATS_URL: NATS server URL (default: nats://nats:4222)

Tracker

  • NATS_URL: NATS server URL (default: nats://nats:4222)
  • DB_CONN_STR: Database connection string
  • REDIS_ADDR: Redis server address (default: redis:6379)

Environment Variables Organization

The .env.sample file is organized into sections:

  • Ultrafeeder Configuration: ADS-B receiver settings and web interface
  • SBS Services: Configuration for ingestor, logger, and tracker
  • Database Configuration: TimescaleDB connection settings
  • Security: Optional authentication and SSL settings

Database Schema

The system uses TimescaleDB with the following main tables:

  • aircraft_states: Time-series table for aircraft position and state data
  • flights: Flight session information
  • system_stats: System performance and statistics

NATS Configuration

NATS is configured with JetStream enabled for message persistence:

port: 4222
http_port: 8222

jetstream {
    store_dir: "/data"
    max_memory_store: 1G
    max_file_store: 10G
}

πŸ“Š Data Processing

SBS Message Types

The system processes the following SBS message types:

  • MSG,1: Selection change
  • MSG,2: New aircraft
  • MSG,3: New ID
  • MSG,4: New callsign
  • MSG,5: New altitude
  • MSG,6: New ground speed
  • MSG,7: New track
  • MSG,8: New lat/lon (position)
  • MSG,9: New ground status

Aircraft State Tracking

The tracker maintains real-time state for each aircraft:

  • Position (latitude/longitude)
  • Altitude and vertical rate
  • Ground speed and track
  • Callsign and squawk
  • Ground status

Flight Sessions

Flight sessions are automatically detected and tracked:

  • Session start/end times
  • Flight path (first/last position)
  • Maximum altitude and speed
  • Session statistics

πŸ“ˆ Monitoring & Statistics

The system provides comprehensive statistics:

  • Message processing rates
  • Aircraft and flight counts
  • Processing performance metrics
  • Error rates and system health

Statistics are logged every minute and persisted to the database every 5 minutes.

πŸ”§ Development

Project Structure

sbs-logger/
β”œβ”€β”€ cmd/                    # Application entry points
β”‚   β”œβ”€β”€ ingestor/          # SBS message ingestion
β”‚   β”œβ”€β”€ logger/            # Log file management
β”‚   └── tracker/           # Aircraft state tracking
β”œβ”€β”€ internal/              # Private application code
β”‚   β”œβ”€β”€ capture/           # Network capture logic
β”‚   β”œβ”€β”€ config/            # Configuration management
β”‚   β”œβ”€β”€ db/                # Database operations
β”‚   β”œβ”€β”€ nats/              # NATS client
β”‚   β”œβ”€β”€ parser/            # SBS message parsing
β”‚   β”œβ”€β”€ redis/             # Redis client
β”‚   β”œβ”€β”€ stats/             # Statistics tracking
β”‚   β”œβ”€β”€ storage/           # Storage abstractions
β”‚   └── types/             # Data structures
β”œβ”€β”€ config/                # Configuration files
β”‚   └── nats/              # NATS server configuration
β”œβ”€β”€ logs/                  # Log file output
└── docker-compose.yml     # Container orchestration

Running Tests

go test ./...

Building for Production

# Build all components
make build

# Build individual components
make build-ingestor
make build-logger
make build-tracker

Docker Hub Publishing

The project includes automated Docker Hub publishing. To set up:

  1. Setup Docker Hub publishing:
make dockerhub-setup
  1. Test Docker builds locally:
make dockerhub-test
  1. Manual push to Docker Hub:
make dockerhub-push DOCKERHUB_USERNAME=youruser DOCKERHUB_TOKEN=yourtoken VERSION=v1.0.0
  1. Automated publishing: Create a GitHub release to trigger automatic publishing

For detailed setup instructions, see Docker Hub Setup Guide.

πŸš€ Deployment

Docker Images

The project provides pre-built Docker images on multiple registries:

GitHub Container Registry (GHCR)

# Pull images from GHCR
docker pull ghcr.io/saviobatista/sbs-logger/sbs-ingestor:latest
docker pull ghcr.io/saviobatista/sbs-logger/sbs-logger:latest
docker pull ghcr.io/saviobatista/sbs-logger/sbs-tracker:latest

Docker Hub

# Pull images from Docker Hub
docker pull saviobatista/sbs-ingestor:latest
docker pull saviobatista/sbs-logger:latest
docker pull saviobatista/sbs-tracker:latest

Production Considerations

  1. Scaling: Run multiple ingestor instances for high availability
  2. Storage: Configure appropriate retention policies for TimescaleDB
  3. Monitoring: Set up monitoring for NATS, Redis, and TimescaleDB
  4. Backup: Implement regular database backups
  5. Security: Use TLS for NATS and database connections

Docker Deployment

# Production deployment
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d

# Scale services
docker-compose up -d --scale ingestor=3

Using Pre-built Images

Update your docker-compose.yml to use pre-built images:

services:
  ingestor:
    image: saviobatista/sbs-ingestor:latest
    # or: image: ghcr.io/saviobatista/sbs-logger/sbs-ingestor:latest
    environment:
      - SOURCES=your-adsb-receiver:30003
      - NATS_URL=nats://nats:4222
    depends_on:
      - nats

  logger:
    image: saviobatista/sbs-logger:latest
    environment:
      - OUTPUT_DIR=/app/logs
      - NATS_URL=nats://nats:4222
    volumes:
      - ./logs:/app/logs
    depends_on:
      - nats

πŸ“ Logging

Logs are written to daily files with automatic rotation:

  • Format: sbs_YYYY-MM-DD.log
  • Compression: Previous day's logs are automatically compressed
  • Location: ./logs/ directory (configurable)

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ†˜ Support

For issues and questions:

  1. Check the documentation
  2. Search existing issues
  3. Create a new issue with detailed information

πŸ”— Related Projects

About

🚁 High-performance distributed SBS/ADS-B message processor with real-time aircraft tracking, flight session management, and TimescaleDB storage. Built with Go microservices and NATS messaging.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •