Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 18 additions & 36 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,33 @@ Custom telemetry exporter plug-ins can be created according to [src/plugins/tele
### Event Structure

Each telemetry event contains:
- **Category**: Event category for filtering and aggregation

- **Event type**: Descriptive name/identifier for the event
- **Value**: Numeric value associated with the event

### Event Categories

The telemetry system supports the following event categories:

| Category | Description | Example Events |
|----------|-------------|----------------|
| `NIXL_TELEMETRY_MEMORY` | Memory operations | Memory registration, deregistration, allocation |
| `NIXL_TELEMETRY_TRANSFER` | Data transfer operations | Bytes transmitted/received, request counts |
| `NIXL_TELEMETRY_CONNECTION` | Connection management | Connect, disconnect events |
| `NIXL_TELEMETRY_BACKEND` | Backend-specific operations | Backend initialization, configuration |
| `NIXL_TELEMETRY_ERROR` | Error events | Error counts by type |
| `NIXL_TELEMETRY_PERFORMANCE` | Performance metrics | Transaction times, latency measurements |
| `NIXL_TELEMETRY_SYSTEM` | System-level events | Process start/stop, resource usage |
| `NIXL_TELEMETRY_CUSTOM` | Custom/user-defined events | Application-specific metrics |

Please note that some telemetry categories have no defined events yet.

### Metrics & Events Description

The following table lists all built-in telemetry metrics and events generated by NIXL:

| Event Name | Category | Unit | Description |
|------------|----------|------|-------------|
| `agent_memory_registered` | `NIXL_TELEMETRY_MEMORY` | bytes | registered memory size per registration API call |
| `agent_memory_deregistered` | `NIXL_TELEMETRY_MEMORY` | bytes | bytes of memory deregistered per API call |
| `agent_tx_bytes` | `NIXL_TELEMETRY_TRANSFER` | bytes | bytes transmitted by the agent per TX request |
| `agent_rx_bytes` | `NIXL_TELEMETRY_TRANSFER` | bytes | bytes received by the agent per RX request |
| `agent_tx_requests_num` | `NIXL_TELEMETRY_TRANSFER` | count | Number of transmit requests sent by the agent |
| `agent_rx_requests_num` | `NIXL_TELEMETRY_TRANSFER` | count | Number of receive requests processed by the agent |
| `agent_xfer_time` | `NIXL_TELEMETRY_PERFORMANCE` | microseconds | Transfer time from start to complete (per request) |
| `agent_xfer_post_time` | `NIXL_TELEMETRY_PERFORMANCE` | microseconds | Time from start to posting to backend (per request) |
| Backend-specific events | `NIXL_TELEMETRY_BACKEND` | - | Dynamic events generated by backend implementations |
| Error status strings | `NIXL_TELEMETRY_ERROR` | count | Error occurrences by status type |
| Event Name | Unit | Description |
| ---------- | ---- | ----------- |
| `agent_memory_registered` | bytes | registered memory size per registration API call |
| `agent_memory_deregistered` | bytes | bytes of memory deregistered per API call |
| `agent_tx_bytes` | bytes | bytes transmitted by the agent per TX request |
| `agent_rx_bytes` | bytes | bytes received by the agent per RX request |
| `agent_tx_requests_num` | count | Number of transmit requests sent by the agent |
| `agent_rx_requests_num` | count | Number of receive requests processed by the agent |
| `agent_xfer_time` | microseconds | Transfer time from start to complete (per request) |
| `agent_xfer_post_time` | microseconds | Time from start to posting to backend (per request) |
| `agent_err_*` | count | Error occurrences by status type |

The **Shared Memory Buffer** plug-in, contains the data per transaction event, without summarizing between events.

### Telemetry Details

- Producers append events under a mutex, consumers read them in **ring insertion order**.
- Current design allows silent telemetry loss.
- Current design does not support selective telemetry(e.g per category). All the telemetry events could be either ON or OFF.
- Current design does not support selective telemetry. All the telemetry events could be either ON or OFF.

## Enabling Telemetry

Expand All @@ -71,7 +53,7 @@ The **Shared Memory Buffer** plug-in, contains the data per transaction event, w
Telemetry is configured by environment variables:

| Variable | Description | Default |
|----------|-------------|---------|
| -------- | ----------- | ------- |
| `NIXL_TELEMETRY_ENABLE` | Enable telemetry collection | `false` |
| `NIXL_TELEMETRY_BUFFER_SIZE` | Number of events in buffer | `4096` |
| `NIXL_TELEMETRY_RUN_INTERVAL` | Flush interval (ms) | `100` |
Expand All @@ -88,7 +70,7 @@ Following sections applied specifically for configuration and usage of cyclic bu
### Configuration

| Variable | Description | Default |
|----------|-------------|---------|
| -------- | ----------- | ------- |
| `NIXL_TELEMETRY_DIR` | Directory for telemetry files | - |

- If telemetry is enabled via `NIXL_TELEMETRY_ENABLE`, but `NIXL_TELEMETRY_DIR` is not set, no telemetry file is generated and `NIXL_TELEMETRY_RUN_INTERVAL` is not used.
Expand All @@ -97,6 +79,8 @@ Following sections applied specifically for configuration and usage of cyclic bu

Telemetry data is stored in shared memory files with the agent name passed when creating the agent.

`TELEMETRY_VERSION` is the binary layout version of `nixlTelemetryEvent` as serialized in the shared-memory cyclic buffer. Bump it whenever the struct's size, field offsets, or enum widths change. Readers exact-match this value; the C++ shared-ring-buffer path unlinks the file on mismatch, while the Python example raises a `RuntimeError`. There is no backward-compatibility path.

### Using Telemetry Readers

### C++ Telemetry Reader
Expand Down Expand Up @@ -125,15 +109,13 @@ python3 examples/python/telemetry_reader.py --telemetry_path /tmp/agent_name

Both readers produce similar formatted output:

```
```text
=== NIXL Telemetry Event ===
Category: TRANSFER
Event: agent_tx_bytes
Value: 1048576
===========================

=== NIXL Telemetry Event ===
Category: MEMORY
Event: agent_memory_registered
Value: 4096
===========================
Expand Down
2 changes: 0 additions & 2 deletions examples/cpp/telemetry_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ print_telemetry_event(const nixlTelemetryEvent &event) {
// Can be extended to more general ostream if needed
// friend std::ostream &operator<<(std::ostream &os, const nixlTelemetryEvent &event)
std::cout << "\n=== NIXL Telemetry Event ===" << std::endl;
std::cout << "Category: " << nixlEnumStrings::telemetryCategoryStr(event.category_)
<< std::endl;
std::cout << "Event name: " << nixlEnumStrings::telemetryEventTypeStr(event.eventType_)
<< std::endl;
std::cout << "Value: " << event.value_ << std::endl;
Expand Down
36 changes: 3 additions & 33 deletions examples/python/telemetry_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,7 @@
logger = logging.getLogger(__name__)

# Constants from telemetry_event.h
TELEMETRY_VERSION = 2

# NIXL telemetry categories
NIXL_TELEMETRY_MEMORY = 0
NIXL_TELEMETRY_TRANSFER = 1
NIXL_TELEMETRY_CONNECTION = 2
NIXL_TELEMETRY_BACKEND = 3
NIXL_TELEMETRY_ERROR = 4
NIXL_TELEMETRY_PERFORMANCE = 5
NIXL_TELEMETRY_SYSTEM = 6
NIXL_TELEMETRY_CUSTOM = 7
NIXL_TELEMETRY_MAX = 8
TELEMETRY_VERSION = 3

# NIXL telemetry event types (nixl_telemetry_event_type_t)
AGENT_TX_BYTES = 0
Expand Down Expand Up @@ -85,9 +74,8 @@ class NixlTelemetryEvent(ctypes.Structure):

_pack_ = 1
_fields_ = [
("category", ctypes.c_int),
("event_type", ctypes.c_uint8),
("_padding", ctypes.c_char * 3),
("event_type", ctypes.c_uint32),
("_padding", ctypes.c_char * 4),
("value", ctypes.c_uint64),
]

Expand Down Expand Up @@ -230,17 +218,6 @@ def format_bytes(bytes_val):
return f"{value:.2f} {units[unit_index]}"


_CATEGORY_STRINGS = {
NIXL_TELEMETRY_MEMORY: "MEMORY",
NIXL_TELEMETRY_TRANSFER: "TRANSFER",
NIXL_TELEMETRY_CONNECTION: "CONNECTION",
NIXL_TELEMETRY_BACKEND: "BACKEND",
NIXL_TELEMETRY_ERROR: "ERROR",
NIXL_TELEMETRY_PERFORMANCE: "PERFORMANCE",
NIXL_TELEMETRY_SYSTEM: "SYSTEM",
NIXL_TELEMETRY_CUSTOM: "CUSTOM",
}

_EVENT_TYPE_STRINGS = {
AGENT_TX_BYTES: "agent_tx_bytes",
AGENT_RX_BYTES: "agent_rx_bytes",
Expand All @@ -265,11 +242,6 @@ def format_bytes(bytes_val):
}


def get_telemetry_category_string(category):
"""Get string representation of telemetry category"""
return _CATEGORY_STRINGS.get(category, f"UNKNOWN_CATEGORY_{category}")


def get_telemetry_event_type_string(event_type):
"""Get string representation of telemetry event type enum"""
return _EVENT_TYPE_STRINGS.get(event_type, f"unknown_event_{event_type}")
Expand All @@ -280,9 +252,7 @@ def print_telemetry_event(event):
logger.info("\n=== NIXL Telemetry Event ===")

event_name = get_telemetry_event_type_string(event.event_type)
category_str = get_telemetry_category_string(event.category)

logger.info("Category: %s", category_str)
logger.info("Event: %s", event_name)
logger.info("Value: %s", event.value)
logger.info("===========================")
Expand Down
11 changes: 7 additions & 4 deletions src/api/cpp/backend/backend_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ class nixlBackendEngine {

void
addTelemetryEvent(nixl_telemetry_event_type_t event_type, uint64_t value) {
Comment thread
e-eygin marked this conversation as resolved.
Resolved
if (!enableTelemetry_) return;
if (telemetryEvents_.size() >= MAX_TELEMETRY_QUEUE_SIZE) return;
if (!enableTelemetry_) {
return;
}
std::lock_guard<std::mutex> lock(telemetryEventsMutex_);
telemetryEvents_.emplace_back(
nixl_telemetry_category_t::NIXL_TELEMETRY_BACKEND, event_type, value);
if (telemetryEvents_.size() >= MAX_TELEMETRY_QUEUE_SIZE) {
return;
}
telemetryEvents_.emplace_back(event_type, value);
Comment thread
e-eygin marked this conversation as resolved.
Resolved
}

public:
Expand Down
56 changes: 12 additions & 44 deletions src/core/telemetry/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,66 +201,52 @@ nixlTelemetry::registerPeriodicTask(periodicTask &task) {
}

void
nixlTelemetry::updateData(nixl_telemetry_event_type_t event_type,
nixl_telemetry_category_t category,
uint64_t value) {
nixlTelemetry::updateData(nixl_telemetry_event_type_t event_type, uint64_t value) {
// agent can be multi-threaded
std::lock_guard<std::mutex> lock(mutex_);
if (events_.size() >= maxBufferedEvents_) {
return;
}
events_.emplace_back(category, event_type, value);
events_.emplace_back(event_type, value);
Comment thread
e-eygin marked this conversation as resolved.
Resolved
}

// The next 4 methods might be removed, as addXferTime covers them.
void
nixlTelemetry::updateTxBytes(uint64_t tx_bytes) {
updateData(nixl_telemetry_event_type_t::AGENT_TX_BYTES,
nixl_telemetry_category_t::NIXL_TELEMETRY_TRANSFER,
tx_bytes);
updateData(nixl_telemetry_event_type_t::AGENT_TX_BYTES, tx_bytes);
}

void
nixlTelemetry::updateRxBytes(uint64_t rx_bytes) {
updateData(nixl_telemetry_event_type_t::AGENT_RX_BYTES,
nixl_telemetry_category_t::NIXL_TELEMETRY_TRANSFER,
rx_bytes);
updateData(nixl_telemetry_event_type_t::AGENT_RX_BYTES, rx_bytes);
}

void
nixlTelemetry::updateTxRequestsNum(uint32_t tx_requests_num) {
updateData(nixl_telemetry_event_type_t::AGENT_TX_REQUESTS_NUM,
nixl_telemetry_category_t::NIXL_TELEMETRY_TRANSFER,
tx_requests_num);
updateData(nixl_telemetry_event_type_t::AGENT_TX_REQUESTS_NUM, tx_requests_num);
}

void
nixlTelemetry::updateRxRequestsNum(uint32_t rx_requests_num) {
updateData(nixl_telemetry_event_type_t::AGENT_RX_REQUESTS_NUM,
nixl_telemetry_category_t::NIXL_TELEMETRY_TRANSFER,
rx_requests_num);
updateData(nixl_telemetry_event_type_t::AGENT_RX_REQUESTS_NUM, rx_requests_num);
}

void
nixlTelemetry::updateErrorCount(nixl_status_t error_type) {
NIXL_ASSERT_ALWAYS(static_cast<int>(error_type) < 0)
<< "nixlTelemetry::updateErrorCount expects a negative nixl_status_t error code";
const auto event_type = nixlTelemetryEventTypeForStatus(error_type);
updateData(event_type, nixl_telemetry_category_t::NIXL_TELEMETRY_ERROR, 1);
updateData(event_type, 1);
}

void
nixlTelemetry::updateMemoryRegistered(uint64_t memory_registered) {
updateData(nixl_telemetry_event_type_t::AGENT_MEMORY_REGISTERED,
nixl_telemetry_category_t::NIXL_TELEMETRY_MEMORY,
memory_registered);
updateData(nixl_telemetry_event_type_t::AGENT_MEMORY_REGISTERED, memory_registered);
}

void
nixlTelemetry::updateMemoryDeregistered(uint64_t memory_deregistered) {
updateData(nixl_telemetry_event_type_t::AGENT_MEMORY_DEREGISTERED,
nixl_telemetry_category_t::NIXL_TELEMETRY_MEMORY,
memory_deregistered);
updateData(nixl_telemetry_event_type_t::AGENT_MEMORY_DEREGISTERED, memory_deregistered);
}

void
Expand All @@ -274,32 +260,14 @@ nixlTelemetry::addXferTime(std::chrono::microseconds xfer_time, bool is_write, u
if (events_.size() + 3 > maxBufferedEvents_) {
return;
}
events_.emplace_back(nixl_telemetry_category_t::NIXL_TELEMETRY_PERFORMANCE,
nixl_telemetry_event_type_t::AGENT_XFER_TIME,
events_.emplace_back(nixl_telemetry_event_type_t::AGENT_XFER_TIME,
static_cast<uint64_t>(xfer_time.count()));
events_.emplace_back(nixl_telemetry_category_t::NIXL_TELEMETRY_TRANSFER, bytes_type, bytes);
events_.emplace_back(nixl_telemetry_category_t::NIXL_TELEMETRY_TRANSFER, requests_type, 1);
events_.emplace_back(bytes_type, bytes);
events_.emplace_back(requests_type, 1);
}

void
nixlTelemetry::addPostTime(std::chrono::microseconds post_time) {
updateData(nixl_telemetry_event_type_t::AGENT_XFER_POST_TIME,
nixl_telemetry_category_t::NIXL_TELEMETRY_PERFORMANCE,
static_cast<uint64_t>(post_time.count()));
}

std::string
nixlEnumStrings::telemetryCategoryStr(const nixl_telemetry_category_t &category) {
static std::array<std::string, 9> nixl_telemetry_category_str = {"NIXL_TELEMETRY_MEMORY",
"NIXL_TELEMETRY_TRANSFER",
"NIXL_TELEMETRY_CONNECTION",
"NIXL_TELEMETRY_BACKEND",
"NIXL_TELEMETRY_ERROR",
"NIXL_TELEMETRY_PERFORMANCE",
"NIXL_TELEMETRY_SYSTEM",
"NIXL_TELEMETRY_CUSTOM",
"NIXL_TELEMETRY_MAX"};
size_t category_int = static_cast<size_t>(category);
if (category_int >= nixl_telemetry_category_str.size()) return "BAD_CATEGORY";
return nixl_telemetry_category_str[category_int];
}
4 changes: 1 addition & 3 deletions src/core/telemetry/telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ class nixlTelemetry {
void
registerPeriodicTask(periodicTask &task);
void
updateData(nixl_telemetry_event_type_t event_type,
nixl_telemetry_category_t category,
uint64_t value);
updateData(nixl_telemetry_event_type_t event_type, uint64_t value);
bool
writeEventHelper();
std::unique_ptr<nixlTelemetryExporter> exporter_;
Expand Down
29 changes: 3 additions & 26 deletions src/core/telemetry/telemetry_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,14 @@
#define NIXL_SRC_CORE_TELEMETRY_TELEMETRY_EVENT_H

#include <cstdint>
#include <string>
#include <string_view>

#include "nixl_types.h"

constexpr char TELEMETRY_BUFFER_SIZE_VAR[] = "NIXL_TELEMETRY_BUFFER_SIZE";
constexpr char TELEMETRY_RUN_INTERVAL_VAR[] = "NIXL_TELEMETRY_RUN_INTERVAL";

constexpr inline int TELEMETRY_VERSION = 2;

/**
* @enum nixl_telemetry_category_t
* @brief An enumeration of main telemetry event categories for easy filtering and aggregation
Comment thread
e-eygin marked this conversation as resolved.
Resolved
*/
enum class nixl_telemetry_category_t {
NIXL_TELEMETRY_MEMORY = 0, // Memory operations (register, deregister, allocation)
NIXL_TELEMETRY_TRANSFER = 1, // Data transfer operations (read, write)
NIXL_TELEMETRY_CONNECTION = 2, // Connection management (connect, disconnect)
NIXL_TELEMETRY_BACKEND = 3, // Backend-specific operations
NIXL_TELEMETRY_ERROR = 4, // Error events
NIXL_TELEMETRY_PERFORMANCE = 5, // Performance metrics
NIXL_TELEMETRY_SYSTEM = 6, // System-level events
NIXL_TELEMETRY_CUSTOM = 7, // Custom/user-defined events
};
constexpr inline int TELEMETRY_VERSION = 3;

/**
* @enum nixl_telemetry_event_type_t
Expand Down Expand Up @@ -74,9 +58,6 @@ enum class nixl_telemetry_event_type_t : uint32_t {
nixlTelemetryEventTypeForStatus(nixl_status_t s);

namespace nixlEnumStrings {
std::string
telemetryCategoryStr(const nixl_telemetry_category_t &category);

[[nodiscard]] constexpr std::string_view
telemetryEventTypeStr(const nixl_telemetry_event_type_t type) noexcept {
switch (type) {
Expand Down Expand Up @@ -130,17 +111,13 @@ telemetryEventTypeStr(const nixl_telemetry_event_type_t type) noexcept {
* @brief A structure to hold individual telemetry event data for cyclic buffer storage
*/
struct nixlTelemetryEvent {
nixl_telemetry_category_t category_; // Main event category for filtering
nixl_telemetry_event_type_t eventType_; // Detailed event type/identifier
uint64_t value_; // Numeric value associated with the event

nixlTelemetryEvent() noexcept = default;

nixlTelemetryEvent(nixl_telemetry_category_t category,
nixl_telemetry_event_type_t event_type,
uint64_t value) noexcept
: category_(category),
eventType_(event_type),
nixlTelemetryEvent(nixl_telemetry_event_type_t event_type, uint64_t value) noexcept
: eventType_(event_type),
value_(value) {}
};

Expand Down
Loading
Loading