📊 A gauge instrument that tracks current values.

Gauges are perfect for tracking things that can go up or down, like fuel levels, temperature, queue sizes, or active connections.

Unlike counters, gauges represent the current state of something rather than a cumulative total. You can set them to any value, add to them, or subtract from them.

const gauge = new RednetGauge(client, "queue_size", "Items in queue", "items");

// Set absolute values
gauge.set(42);

// Relative changes
gauge.add(5); // Add 5 items
gauge.subtract(2); // Remove 2 items

console.log(`Current queue size: ${gauge.getValue()}`);

Constructors

Methods

Constructors

  • Create a new gauge instrument.

    Parameters

    • client: RednetClient

      RednetClient for sending data

    • name: string

      Gauge name

    • description: string

      Human-readable description

    • unit: string

      Unit of measurement

    Returns RednetGauge

Methods

  • âž• Add to the current gauge value.

    This increases the gauge by the specified amount.

    Parameters

    • value: number

      Value to add (can be negative to subtract)

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

      Additional attributes for this measurement

    Returns void

    // Add items to inventory
    inventoryGauge.add(itemsAdded, { "item.type": "iron_ore" });

    // Increase power level
    powerGauge.add(generatedPower, { "generator.type": "solar" });
  • 📊 Get the current gauge value.

    Returns number

    The current gauge value

    const currentLevel = gauge.getValue();
    if (currentLevel < threshold) {
    client.warn("Low level warning", { "current": currentLevel });
    }
  • 📊 Set the gauge to a specific value.

    This sets the gauge to an absolute value and immediately sends it to the collector.

    Parameters

    • value: number

      The new gauge value

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

      Additional attributes for this measurement

    Returns void

    // Set fuel level
    fuelGauge.set(turtle.getFuelLevel(), {
    "fuel.type": "coal",
    "max.capacity": 80000
    });

    // Set temperature reading
    tempGauge.set(sensor.getTemperature(), {
    "sensor.location": "reactor_core",
    "sensor.id": "temp_001"
    });
  • âž– Subtract from the current gauge value.

    This decreases the gauge by the specified amount.

    Parameters

    • value: number

      Value to subtract

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

      Additional attributes for this measurement

    Returns void

    // Remove items from inventory
    inventoryGauge.subtract(itemsUsed, { "item.type": "coal" });

    // Consume fuel
    fuelGauge.subtract(fuelConsumed, { "operation": "mining" });