Real-time monitoring and metrics for Rust channels

This crate provides an easy-to-configure way to monitor std::sync, Tokio and futures-rs channels (more flavors soon!). Track per-channel metrics such as queue depth, send/receive rates, and memory usage, directly from your terminal.
Features
- Zero-cost when disabled — fully gated by a feature flag
- Minimal configuration - just one
instrument!macro to start collecting metrics - Detailed stats - per channel status, sent/received messages, queue capacity, and memory usage
- Background processing - minimal profiling impact
- Live monitoring - view metrics in a clear, real-time TUI dashboard (built with ratatui.rs)
Getting started
Cargo.toml
= { = "0.1", = true, =['tokio', 'futures'] }
[]
= ["dep:channels-console"]
This config ensures that the lib has zero overhead unless explicitly enabled via a channels-console feature.
std::sync channels can be instrumented by default. Enable tokio and futures features for Tokio and futures-rs channels, respectively.
Next use instrument! macro to monitor selected channels:
let = ;
let = instrument!;
let = ;
let = instrument!;
Futures and std::sync bounded channels don't provide an API exposing their size, so you have to provide capacity to the instrument! macro.
This is the only change you have to do in your codebase. instrument! macro returns exactly the same channel types so it remains 100% compatible.
Now, install channels-console TUI:
Execute your program with --features=channels-console:
In a different terminal run channels-console CLI to start the TUI and see live usage metrics:

Quickstart demo guide
- Install CLI:
- Clone this repo:
- Run
console_feedexample:
- Run TUI (in a different terminal):
How it works?
instrument! wraps Tokio channels with lightweight proxies that transparently forward all messages while collecting real-time statistics. Each send and recv operation passes through a monitored proxy channel that emits updates to a background metrics system.
In the background a HTTP server process exposes gathered metrics in a JSON format, allowing TUI process to display them in the interface.
There be bugs 🐛
This library has just been released. I've tested it with several apps, and it consistently produced reliable metrics. However, please note that enabling monitoring can subtly affect channel behavior in some cases. For example, using try_send may not return an error as expected, since the proxy layers effectively increase total capacity. I'm actively improving the library, so any feedback, issues, bug reports are welcome.
API
Supported Channel Types
std::sync Channels
Tokio Channels
Futures Channels
I'm planning to support more channel types. PRs are welcome!
instrument! Macro
The instrument! macro is the primary way to monitor channels. It wraps channel creation expressions and returns instrumented versions that collect metrics.
Basic Usage:
use mpsc;
async
Zero-Cost Abstraction: When the channels-console feature is disabled, the #[cfg] attribute ensures the instrumentation code is completely removed at compile time - there's absolutely zero runtime overhead.
Note: The first invocation of instrument! automatically starts:
- A background thread for metrics collection
- An HTTP server on
http://127.0.0.1:6770(default port) exposing metrics in JSON format
This initialization happens only once and is shared across all instrumented channels.
Channel Labels:
By default, channels are labeled with their file location and line number (e.g., src/worker.rs:25). You can provide custom labels for easier identification:
let = ;
let = instrument!;
Capacity Parameter Requirement:
⚠️ Important: For std::sync::mpsc and futures::channel::mpsc bounded channels, you must specify the capacity parameter because their APIs don't expose the capacity after creation:
use mpsc;
// std::sync::mpsc::sync_channel - MUST specify capacity
let = ;
let = instrument!;
// With label
let = ;
let = instrument!;
use mpsc;
// futures bounded channel - MUST specify capacity
let = ;
let = instrument!;
Tokio channels don't require the capacity parameter because their capacity is accessible from the channel handles.
ChannelsGuard - Printing Statistics on Drop
Similar to the hotpath API the ChannelsGuard is a RAII guard that automatically prints channel statistics when dropped (typically at program end). This is useful for debugging and getting a summary of channel usage.
Basic Usage:
use mpsc;
async
Output Formats:
You can customize the output format using ChannelsGuardBuilder:
async
Output Example (Table Format):
=== Channel Statistics (runtime: 5.23s) ===
+------------------+-------------+--------+------+-------+----------+--------+-------+
| Channel | Type | State | Sent | Mem | Received | Queued | Mem |
+------------------+-------------+--------+------+-------+----------+--------+-------+
| task-queue | bounded[10] | active | 1543 | 12 KB | 1543 | 0 | 0 B |
| http-responses | unbounded | active | 892 | 89 KB | 890 | 2 | 200 B |
| shutdown-signal | oneshot | closed | 1 | 8 B | 1 | 0 | 0 B |
+------------------+-------------+--------+------+-------+----------+--------+-------+
Configuration
Metrics Server Port
The HTTP metrics server runs on port 6770 by default. You can customize this using the channels_console_METRICS_PORT environment variable:
CHANNELS_CONSOLE_METRICS_PORT=8080
When using the TUI console, specify the matching port with the --metrics-port flag: