Monocle
See through all Border Gateway Protocol (BGP) data with a monocle.

Table of Contents
Install
Using cargo
cargo install monocle
Using homebrew on macOS
brew install monocle
Install cargo-binstall first:
cargo install cargo-binstall
Then install monocle using cargo binstall
cargo binstall monocle
Using Docker
Pull the pre-built image or build locally:
# Build the image locally
docker build -t bgpkit/monocle:latest .
# Or use docker compose
docker compose build
Run monocle commands:
# Show help
docker run --rm bgpkit/monocle:latest --help
# Run a command (e.g., inspect an ASN)
docker run --rm bgpkit/monocle:latest inspect 13335
# Stream live BGP messages from RIS Live
docker run --rm bgpkit/monocle:latest watch --host rrc00 --origin-asn 13335
# Run with persistent data directory
docker run --rm -v monocle-data:/data bgpkit/monocle:latest inspect 13335
# Start the HTTP/SSE server; `server` is also the default command, so
# `docker run -p 8080:8080 -v monocle-data:/data bgpkit/monocle:latest` is equivalent
docker run --rm -p 8080:8080 -v monocle-data:/data bgpkit/monocle:latest server --address 0.0.0.0 --port 8080
# Using docker compose for server mode
docker compose up -d
curl http://localhost:8080/health
Library Usage
Monocle can also be used as a library in your Rust projects. Add it to your Cargo.toml:
[dependencies]
# Default: full CLI binary with all features
monocle = "1.1"
# Library only - all lenses and database operations
monocle = { version = "1.1", default-features = false, features = ["lib"] }
# Library + HTTP server
monocle = { version = "1.1", default-features = false, features = ["server"] }
Feature Tiers
Monocle uses a simplified feature system with three options:
| Feature |
Description |
Implies |
lib |
Complete library (database + all lenses + display) |
- |
server |
HTTP/SSE server for programmatic API access |
lib |
cli (default) |
Full CLI binary with all functionality |
lib, server |
Documentation
The following documentation files are available in the repository:
Architecture
The library is organized into the following core modules:
database: All database functionality (requires lib feature)
core: Connection management and schema definitions
session: One-time storage for search results
monocle: Main monocle database with ASInfo, AS2Rel, RPKI, and Pfx2as caching
lens: High-level business logic (requires lib feature)
time: Time parsing and formatting lens
country: Country code/name lookup lens
ip: IP information lookup lens
parse: MRT file parsing lens with progress tracking
search: BGP message search lens with progress tracking
rpki: RPKI validation and data lens
pfx2as: Prefix-to-AS mapping types
as2rel: AS-level relationships lens
inspect: Unified AS/prefix inspection lens
server: HTTP/SSE API server (requires server feature)
For detailed architecture documentation, see ARCHITECTURE.md.
Example: Using Lenses
use monocle::database::MonocleDatabase;
use monocle::lens::inspect::{InspectLens, InspectQueryOptions};
fn main() -> anyhow::Result<()> {
// Open the monocle database
let db = MonocleDatabase::open_in_dir("~/.local/share/monocle")?;
// Create a lens
let lens = InspectLens::new(&db);
// Query AS information
let options = InspectQueryOptions::default();
let results = lens.query_asn(13335, &options)?;
println!("AS{}: {}", results.asn, results.name.unwrap_or_default());
Ok(())
}
Example: Parse MRT Files with Progress
use monocle::lens::parse::{ParseLens, ParseFilters, ParseProgress};
use std::sync::Arc;
fn main() -> anyhow::Result<()> {
let lens = ParseLens::new();
let filters = ParseFilters::default();
// Define a progress callback
let callback = Arc::new(|progress: ParseProgress| {
match progress {
ParseProgress::Started { file_path } => {
eprintln!("Started parsing: {}", file_path);
}
ParseProgress::Update { messages_processed, rate, .. } => {
eprintln!("Processed {} messages ({:.0} msg/s)",
messages_processed, rate.unwrap_or(0.0));
}
ParseProgress::Completed { total_messages, duration_secs, .. } => {
eprintln!("Completed: {} messages in {:.2}s", total_messages, duration_secs);
}
}
});
// Parse with progress tracking
let elems = lens.parse_with_progress(
&filters,
"path/to/file.mrt",
Some(callback)
)?;
for elem in elems {
println!("{:?}", elem);
}
Ok(())
}
Usage
Subcommands:
parse: parse individual MRT files
search: search for matching messages from all available public MRT files
rib: reconstruct final RIB state at one or more arbitrary timestamps
server: start a HTTP/SSE server for programmatic access
inspect: unified AS and prefix information lookup
country: utility to look up country name and code
time: utility to convert time between unix timestamp and RFC3339 string
as2rel: AS-level relationship lookup between ASNs
pfx2as: prefix-to-ASN mapping lookup with RPKI validation
rpki: RPKI validation and ROA/ASPA listing
ip: IP information lookup
config: configuration display and database management (refresh, backup, sources)
Global Options
All commands support the following global options:
--format <FORMAT>: Output format (table, markdown, json, json-pretty, json-line, psv)
--json: Shortcut for --format json-pretty
--debug: Print debug information
Top-level help menu:
โ monocle --help
A commandline application to search, parse, and process BGP information in public sources.
Usage: monocle [OPTIONS] <COMMAND>
Commands:
parse Parse individual MRT files given a file path, local or remote
search Search BGP messages from all available public MRT files
rib Reconstruct final RIB state at one or more arbitrary timestamps
server Start the Monocle HTTP service (REST: /api/v1, search stream: /api/v1/search/stream)
inspect Unified AS and prefix information lookup
country Country name and code lookup utilities
time Time conversion utilities
rpki RPKI utilities
ip IP information lookup
as2rel AS-level relationship lookup between ASNs
pfx2as Prefix-to-ASN mapping lookup
config Show monocle configuration, data paths, and database management
help Print this message or the help of the given subcommand(s)
Options:
-c, --config <CONFIG> configuration file path (default: $XDG_CONFIG_HOME/monocle/monocle.toml)
--debug Print debug information
--format <FORMAT> Output format: table, markdown, json, json-pretty, json-line, psv (default varies by command)
--json Output as JSON objects (shortcut for --format json-pretty)
--no-update Disable automatic database updates (use existing cached data only)
-h, --help Print help
-V, --version Print version
monocle parse
Parsing a single MRT file given a local path or a remote URL.