🚀 Simple Rednet client - sends metrics and logs immediately to collector.

This is your main interface for sending telemetry data! The client handles all the formatting, metadata, and transmission details so you can focus on what matters - getting insights from your ComputerCraft systems.

The client is designed to be lightweight and fire-and-forget. Each metric and log is sent immediately over Rednet with no local buffering or batching. This makes it perfect for real-time monitoring but means you need a reliable network connection to your collector.

const client = new RednetClient(
42, // Collector computer ID
"my-awesome-turtle", // Service name
"1.0.0", // Service version
{ // Resource attributes
"turtle.role": "miner",
"location": "diamond_mine_1"
}
);

// Send metrics
client.sendCounter("blocks_mined", "Total blocks mined", "blocks", 1);
client.sendGauge("fuel_level", "Current fuel", "units", turtle.getFuelLevel());

// Send logs
client.info("Mining started", { "target.depth": 64 });
client.error("Low fuel warning", { "fuel.remaining": 10 });

Constructors

  • Create a new Rednet telemetry client.

    Parameters

    • collectorId: number

      Computer ID of the collector to send data to

    • serviceName: string

      Name of your service (e.g., "turtle-miner", "factory-controller")

    • serviceVersion: string = "1.0.0"

      Version of your service (defaults to "1.0.0")

    • resourceAttributes: Record<string, unknown> = {}

      Additional resource attributes to include with all telemetry

    • protocol: string = "otel_telemetry"

      Rednet protocol to use (defaults to "otel_telemetry")

    Returns RednetClient

    const client = new RednetClient(
    42, // Send to computer ID 42
    "quarry-turtle-001", // Service name
    "2.1.0", // Service version
    { // Resource attributes
    "turtle.type": "quarry",
    "location.x": 100,
    "location.z": 200,
    "owner": "steve"
    },
    "my_custom_protocol" // Custom protocol
    );

Methods

  • 🐛 Send debug log.

    Use for detailed diagnostic information, typically only of interest when diagnosing problems.

    Parameters

    • message: string

      Debug message

    • attributes: Record<string, unknown> = {}

      Additional context

    Returns void

    client.debug("Checking inventory slot", {
    "slot": 3,
    "expected.item": "minecraft:coal"
    });
  • ❌ Send error log.

    Use for error events that might still allow the application to continue.

    Parameters

    • message: string

      Error message

    • attributes: Record<string, unknown> = {}

      Additional context

    Returns void

    client.error("Failed to mine block", {
    "block.position": { x: 10, y: 64, z: 20 },
    "error.reason": "bedrock_encountered"
    });
  • 💀 Send fatal log.

    Use for very severe error events that will likely lead to application abort.

    Parameters

    • message: string

      Fatal error message

    • attributes: Record<string, unknown> = {}

      Additional context

    Returns void

    client.fatal("Critical system failure", {
    "error.type": "out_of_memory",
    "system.state": "corrupted"
    });
  • ℹ️ Send info log.

    Use for general information about system operation.

    Parameters

    • message: string

      Info message

    • attributes: Record<string, unknown> = {}

      Additional context

    Returns void

    client.info("Mining operation started", {
    "target.depth": 64,
    "estimated.duration": "30min"
    });
  • 📈 Send a counter metric immediately.

    Counters track cumulative values that only increase (like total requests, blocks mined, or items produced). Perfect for tracking totals over time!

    Parameters

    • name: string

      Metric name (e.g., "http_requests_total", "blocks_mined")

    • description: string

      Human-readable description

    • unit: string

      Unit of measurement (e.g., "requests", "blocks", "bytes")

    • value: number

      The counter value (must be positive)

    • attributes: Record<string, unknown> = {}

      Additional attributes for this measurement

    Returns void

    // Track mining progress
    client.sendCounter("blocks_mined_total", "Total blocks mined", "blocks", 1, {
    "block.type": "minecraft:diamond_ore",
    "tool.type": "diamond_pickaxe",
    "depth": 12
    });

    // Track item production
    client.sendCounter("items_crafted", "Items crafted", "items", 64, {
    "item.type": "minecraft:iron_ingot",
    "recipe.type": "smelting"
    });
  • 📊 Send a gauge metric immediately.

    Gauges track current values that can go up or down (like fuel level, temperature, or queue size). Perfect for monitoring current state!

    Parameters

    • name: string

      Metric name (e.g., "fuel_level", "temperature", "queue_size")

    • description: string

      Human-readable description

    • unit: string

      Unit of measurement (e.g., "units", "celsius", "items")

    • value: number

      The current gauge value

    • attributes: Record<string, unknown> = {}

      Additional attributes for this measurement

    Returns void

    // Monitor turtle fuel
    client.sendGauge("fuel_level", "Current fuel level", "units",
    turtle.getFuelLevel(), {
    "fuel.type": "minecraft:coal",
    "max.fuel": 80000
    }
    );

    // Monitor storage utilization
    client.sendGauge("storage_utilization", "Storage space used", "percent",
    (usedSlots / totalSlots) * 100, {
    "storage.type": "chest",
    "location": "main_base"
    }
    );
  • 📈 Send a histogram metric immediately.

    Histograms track distributions of values (like request duration, file sizes, or operation timing). Perfect for understanding performance characteristics!

    Parameters

    • name: string

      Metric name (e.g., "request_duration", "file_size")

    • description: string

      Human-readable description

    • unit: string

      Unit of measurement (e.g., "seconds", "bytes", "ms")

    • count: number

      Number of observations

    • sum: number

      Sum of all observed values

    • buckets: { bound: number; count: number }[]

      Bucket counts for the histogram distribution

    • attributes: Record<string, unknown> = {}

      Additional attributes for this measurement

    Returns void

    // Track mining operation timing
    const startTime = os.epoch("utc");
    const success = turtle.dig();
    const duration = os.epoch("utc") - startTime;

    client.sendHistogram(
    "mining_duration",
    "Time to mine a block",
    "ms",
    1, // count
    duration, // sum
    [ // buckets (cumulative counts)
    { bound: 100, count: duration <= 100 ? 1 : 0 },
    { bound: 500, count: duration <= 500 ? 1 : 0 },
    { bound: 1000, count: duration <= 1000 ? 1 : 0 },
    { bound: Infinity, count: 1 }
    ],
    { "success": success, "block.hardness": "medium" }
    );
  • 📝 Send a log immediately.

    Send a structured log record with the specified severity level. Use the convenience methods (debug, info, warn, error, fatal) for common cases.

    Parameters

    • body: string

      The log message or structured data

    • severity: SeverityNumber

      Severity level using OpenTelemetry standard

    • attributes: Record<string, unknown> = {}

      Additional context attributes

    Returns void

    client.sendLog("Mining operation completed", SeverityNumber.INFO, {
    "blocks.mined": 64,
    "duration.seconds": 120,
    "fuel.consumed": 32
    });
  • 🔄 Update resource attributes (e.g., when turtle moves location).

    Use this to update resource attributes dynamically, such as when a turtle moves to a new location or changes its operational state.

    Parameters

    • newAttributes: Record<string, unknown>

      New attributes to merge with existing ones

    Returns void

    // Update turtle location after movement
    const pos = turtle.getPosition();
    client.updateResource({
    "location.x": pos.x,
    "location.y": pos.y,
    "location.z": pos.z,
    "last.update": os.epoch("utc")
    });
  • ⚠️ Send warn log.

    Use for potentially harmful situations that don't prevent operation.

    Parameters

    • message: string

      Warning message

    • attributes: Record<string, unknown> = {}

      Additional context

    Returns void

    client.warn("Low fuel warning", {
    "fuel.remaining": 100,
    "fuel.threshold": 500
    });