OpenTelemetry System Metrics Instrumentation

Instrument to report system (CPU, memory, network) and process (CPU, memory, garbage collection) metrics. By default, the following metrics are configured:

“system_memory”: [“total”, “available”, “used”, “free”], “system_cpu”: [“user”, “system”, “idle”], “network_bytes”: [“bytes_recv”, “bytes_sent”], “runtime_memory”: [“rss”, “vms”], “runtime_cpu”: [“user”, “system”],

Usage

from opentelemetry import metrics
from opentelemetry.ext.system_metrics import SystemMetrics
from opentelemetry.sdk.metrics import MeterProvider,
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter

metrics.set_meter_provider(MeterProvider())
exporter = ConsoleMetricsExporter()
SystemMetrics(exporter)

# metrics are collected asynchronously
input("...")

# to configure custom metrics
configuration = {
    "system_memory": ["total", "available", "used", "free", "active", "inactive", "wired"],
    "system_cpu": ["user", "nice", "system", "idle"],
    "network_bytes": ["bytes_recv", "bytes_sent"],
    "runtime_memory": ["rss", "vms"],
    "runtime_cpu": ["user", "system"],
}
SystemMetrics(exporter, config=configuration)

API

class opentelemetry.ext.system_metrics.SystemMetrics(exporter, interval=30, labels=None, config=None)[source]

Bases: object