🏭 OpenTelemetry Rednet Collector for ComputerCraft

The powerhouse behind your telemetry infrastructure! This module provides a central collector that receives metrics and logs from multiple clients over Rednet, batches them efficiently, and exports to external OpenTelemetry Protocol (OTLP) endpoints. Perfect for building comprehensive monitoring systems for your ComputerCraft empire! 🏰📊

  • 📡 Rednet Reception: Automatically receives telemetry from multiple clients
  • 📦 Smart Batching: Configurable batching for efficient network usage
  • 🔄 OTLP Export: Native support for OpenTelemetry Protocol endpoints
  • 📊 Metric Aggregation: Proper handling of counters, gauges, and histograms
  • 🧠 Memory Management: Automatic cleanup to prevent memory leaks
  • 📈 Real-time Stats: Built-in monitoring of collector performance
  • 🔧 Flexible Configuration: Customizable batch sizes, intervals, and endpoints
  • Central Monitoring Hub: Collect data from hundreds of turtles and computers
  • Performance Analytics: Aggregate metrics for trend analysis and alerting
  • Log Aggregation: Centralize logs from distributed automation systems
  • OTLP Integration: Bridge ComputerCraft telemetry to external monitoring systems
  • Real-time Dashboards: Feed data to Grafana, Prometheus, or other tools
  • Debugging Infrastructure: Centralized logging for complex distributed systems
  • Resource Requirements: Collectors need sufficient memory for batching and aggregation
  • Network Capacity: Consider bandwidth when setting batch intervals and sizes
  • OTLP Endpoints: Requires HTTP access to external endpoints (if using OTLP export)
  • State Management: Counter states are maintained for proper aggregation
  • Event Loop Required: Needs an active event loop for Rednet message processing
import { RednetCollector } from "@cc-ts/helpers/otel";
import { runOsEventLoop } from "@cc-ts/helpers/scheduler";

// Create and configure the collector
const collector = new RednetCollector({
batchInterval: 30000, // Batch every 30 seconds
maxBatchSize: 1000, // Max 1000 items per batch
otlpMetricsEndpoint: "http://prometheus:9090/api/v1/otlp/v1/metrics",
otlpLogsEndpoint: "http://loki:3100/otlp/v1/logs",
otlpHeaders: {
"Authorization": "Bearer your-token-here"
}
});

// Start the collector
collector.start();

// Run the event loop to process Rednet messages
runOsEventLoop();
// Configuration for high-throughput environments
const collector = new RednetCollector({
batchInterval: 10000, // Faster batching (10s)
maxBatchSize: 5000, // Larger batches
counterStateTTL: 7200000, // 2 hour TTL for counter states
maxCounterStates: 50000, // More counter states
protocol: "high_perf_telemetry" // Custom protocol
});

collector.start();

// Monitor collector performance
setInterval(() => {
const stats = collector.getStats();
console.log(`Pending: ${stats.pendingTelemetry}, States: ${stats.counterStates}`);
}, 5000);
const collector = new RednetCollector({
batchInterval: 15000,
maxBatchSize: 2000
});

collector.start();

// Custom processing loop
async function customProcessing() {
while (true) {
await asyncSleep(10000);

// Get current data without clearing
const stats = collector.getStats();

if (stats.pendingTelemetry > 500) {
console.log("High telemetry volume detected");
// Maybe trigger immediate flush
collector.tick();
}

// Custom log analysis
const logs = collector.getCollectedLogs();
// Process logs for alerts, etc.
}
}

void customProcessing();
runOsEventLoop();
// Separate collectors for different data types
const metricsCollector = new RednetCollector({
protocol: "metrics_only",
otlpMetricsEndpoint: "http://prometheus:9090/api/v1/otlp/v1/metrics",
batchInterval: 30000
});

const logsCollector = new RednetCollector({
protocol: "logs_only",
otlpLogsEndpoint: "http://loki:3100/otlp/v1/logs",
batchInterval: 10000 // Faster log processing
});

metricsCollector.start();
logsCollector.start();

runOsEventLoop();

Classes

RednetCollector

Interfaces

CollectorConfig