telemetry-service

module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: Apache-2.0

README ΒΆ

Telemetry Service

A robust Go-based telemetry aggregation and alert management service for the SpaceDF IoT platform. Processes device telemetry data, stores metrics in TimescaleDB, and manages real-time alerts.

Overview

The Telemetry Service is a high-performance message processor that:

  • Aggregates telemetry data from IoT devices via AMQP
  • Stores time-series data in TimescaleDB for historical analysis
  • Manages alert rules and generates alerts based on configurable thresholds
  • Processes messages in batches for optimal database performance
  • Provides REST API for querying metrics and alerts

Architecture

RabbitMQ (AMQP)
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Telemetry Service              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ AMQP Consumer (Multi-tenant)β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                 ↓                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚  Message Processing Engine   β”‚β”‚
β”‚  β”‚  - Data Transformation       β”‚β”‚
β”‚  β”‚  - Alert Evaluation          β”‚β”‚
β”‚  β”‚  - Batch Aggregation         β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚             ↓                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚ TimescaleDB (PostgreSQL)     β”‚β”‚
β”‚  β”‚ - Device Metrics             β”‚β”‚
β”‚  β”‚ - Alert History              β”‚β”‚
β”‚  β”‚ - Rule Configurations        β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚             ↕                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚ REST API                     β”‚β”‚
β”‚  β”‚ - Query Metrics              β”‚β”‚
β”‚  β”‚ - Manage Alerts              β”‚β”‚
β”‚  β”‚ - Health Checks              β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Features

πŸ“Š Data Processing
  • Multi-tenant support - Isolated data per organization/tenant
  • Batch processing - Efficient database writes with configurable flush intervals
  • Device location tracking - Processes location coordinates with trilateration
  • Message enrichment - Adds metadata and context to raw messages
πŸ—„οΈ Data Storage
  • TimescaleDB - Time-series optimized PostgreSQL extension
  • Hypertables - Automatic partitioning for scalability
  • Retention policies - Automatic old data cleanup
  • Indexed queries - Fast metric retrieval
πŸ”Œ Integration
  • AMQP/RabbitMQ - Message consumer with auto-reconnect
  • Multiple vhosts - Support for RabbitMQ virtual hosts
  • REST API - Query and manage telemetry data
  • Health checks - Liveness and readiness endpoints

Prerequisites

  • Go 1.24+
  • TimescaleDB 2.10+ (PostgreSQL with TimescaleDB extension)
  • RabbitMQ 3.12+
  • Docker & Docker Compose (for containerized deployment)

Installation

Clone and Setup
cd telemetry-service

# Download dependencies
go mod download
go mod tidy

# Copy environment template
cp .env.example .env

# Edit configuration
nano .env
Configuration

Create a .env file with the following example settings:

# Server
SERVER_LOG_LEVEL=info
SERVER_API_PORT=8080

# TimescaleDB Configuration
DB_NAME="spacedf_telemetry"
DB_USERNAME="postgres"
DB_PASSWORD="postgres"
DB_HOST="localhost"
DB_PORT="5437"
DB_BATCH_SIZE=1000
DB_FLUSH_INTERVAL=1s
DB_MAX_CONNECTIONS=25
DB_MAX_IDLE_CONNS=5

# RabbitMQ Configuration (Multi-tenant mode)
AMQP_BROKER_URL=amqp://admin:password@rabbitmq:5672/
AMQP_CONSUMER_TAG=telemetry-service
AMQP_PREFETCH_COUNT=100
AMQP_ALLOWED_VHOSTS=
AMQP_RECONNECT_DELAY=5s
Database Setup

Initialize TimescaleDB:

# Using dbmate migration tool
dbmate up

# Or manually create the database
createdb telemetry_db
psql telemetry_db -c "CREATE EXTENSION IF NOT EXISTS timescaledb;"

Usage

Run the Service
# Start the telemetry service
go run ./cmd/telemetry serve

# Or build and run
make build
./bin/telemetry serve
Docker
# Build image
docker build -t telemetry-service:latest .

# Run container
docker run -p 8080:8080 \
  --env-file .env \
  -e AMQP_BROKER_URL=amqp://rabbitmq:5672/ \
  -e DB_HOST=timescaledb \
  telemetry-service:latest

# Using Docker Compose
docker-compose up -d telemetry-service

Development

Running Tests
# Run all tests
go test -v ./...

# Run specific package tests
go test -v ./internal/services/...

# With coverage
go test -cover ./...
Code Quality
# Format code
gofmt -w .

# Install tools
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest

# Lint code
golangci-lint run ./...

# Security scan
gosec ./...
Database Migrations

The service uses dbmate for database migrations:

# Create new migration
dbmate new create_metrics_table

# Apply migrations
dbmate up

# Rollback
dbmate down

Contributing

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

License

Licensed under the Apache License, Version 2.0
See the LICENSE file for details.

SpaceDF - A project from Digital Fortress

Directories ΒΆ

Path Synopsis
cmd
telemetry command
@securityDefinitions.apikey Organization slug name @in header @name X-Organization
@securityDefinitions.apikey Organization slug name @in header @name X-Organization
telemetry/docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal
api
pkgs
db

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL