📊 Simple metric data structure for transmission over Rednet.

This is the wire format for sending metrics from clients to collectors. Each metric includes all the context needed for proper aggregation and storage.

const metric: RednetMetric = {
type: "counter",
name: "http_requests_total",
description: "Total HTTP requests processed",
unit: "requests",
value: 42,
attributes: { "method": "GET", "status": "200" },
timestamp: os.epoch("utc"),
resource: { "service.name": "web-server" },
scope: { name: "web-server", version: "1.0.0" }
};
interface RednetMetric {
    attributes: Record<string, unknown>;
    description: string;
    name: string;
    resource: Record<string, unknown>;
    scope: { name: string; version: string };
    timestamp: number;
    type: "counter" | "gauge" | "histogram";
    unit: string;
    value:
        | number
        | {
            buckets: { bound: number; count: number }[];
            count: number;
            sum: number;
        };
}

Properties

attributes: Record<string, unknown>

Key-value attributes for this specific measurement

description: string

Human-readable description of what this metric measures

name: string

Unique name for this metric

resource: Record<string, unknown>

Resource attributes identifying the source

scope: { name: string; version: string }

Instrumentation scope information

Type declaration

  • name: string

    Name of the instrumentation scope

  • version: string

    Version of the instrumentation scope

timestamp: number

Timestamp in nanoseconds since Unix epoch

type: "counter" | "gauge" | "histogram"

The type of metric - determines how it's aggregated

unit: string

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

value:
    | number
    | {
        buckets: { bound: number; count: number }[];
        count: number;
        sum: number;
    }

The metric value - number for counter/gauge, histogram data for histogram

Type declaration

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

      Bucket counts for histogram distribution

    • count: number

      Number of observations in the histogram

    • sum: number

      Sum of all observed values