See through all BGP data with a monocle.
See through all Border Gateway Protocol (BGP) data with a monocle.
cargocargo install monoclehomebrew on macOSbrew install monoclecargo-binstallInstall cargo-binstall first:
cargo install cargo-binstallThen install monocle using cargo binstall
cargo binstall monoclePull the pre-built image or build locally:
# Build the image locally
docker build -t bgpkit/monocle:latest .
# Or use docker compose
docker compose buildRun monocle commands:
…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"] }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 |
The following documentation files are available in the repository:
| File | Description |
|---|---|
README.md (this file) |
User-facing CLI and library overview |
ARCHITECTURE.md |
Overall project structure and design principles |
DEVELOPMENT.md |
Contributor guide for adding lenses and fixing bugs |
AGENTS.md |
AI coding agent guidelines and code style |
CHANGELOG.md |
Version history and breaking changes |
src/server/README.md |
HTTP/SSE API specification |
src/lens/README.md |
Lens module patterns and conventions |
src/database/README.md |
Database module overview |
examples/README.md |
Usage examples by feature tier |
The library is organized into the following core modules:
database: All database functionality (requires lib feature)
core: Connection management and schema definitionssession: One-time storage for search resultsmonocle: Main monocle database with ASInfo, AS2Rel, RPKI, and Pfx2as cachinglens: High-level business logic (requires lib feature)
time: Time parsing and formatting lenscountry: Country code/name lookup lensip: IP information lookup lensparse: MRT file parsing lens with progress trackingsearch: BGP message search lens with progress trackingrpki: RPKI validation and data lenspfx2as: Prefix-to-AS mapping typesas2rel: AS-level relationships lensinspect: Unified AS/prefix inspection lensserver: HTTP/SSE API server (requires server feature)
For detailed architecture documentation, see ARCHITECTURE.md.
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(())
}…Subcommands:
parse: parse individual MRT filessearch: search for matching messages from all available public MRT filesrib: reconstruct final RIB state at one or more arbitrary timestampsserver: start a HTTP/SSE server for programmatic accessinspect: unified AS and prefix information lookupcountry: utility to look up country name and codetime: utility to convert time between unix timestamp and RFC3339 stringas2rel: AS-level relationship lookup between ASNspfx2as: prefix-to-ASN mapping lookup with RPKI validationrpki: RPKI validation and ROA/ASPA listingip: IP information lookupconfig: configuration display and database management (refresh, backup, sources)All commands support the following global options:
--format : Output format (table, markdown, json, json-pretty, json-line, psv)--json: Shortcut for --format json-pretty--debug: Print debug informationTop-level help menu:
…monocle parseParsing a single MRT file given a local path or a remote URL.
…The parse and search commands support filtering by multiple values with OR logic:
# Match elements from ANY of the specified origin ASNs
monocle parse file.mrt -o 13335,15169,8075
# Match ANY of the specified prefixes
monocle parse file.mrt -p 1.1.1.0/24,8.8.8.0/24
# Match elements from ANY of the specified peer ASNs
monocle parse file.mrt -J 174,2914Use the ! prefix to exclude values:
# Exclude elements from AS13335
monocle parse file.mrt -o '!13335'
# Exclude elements from AS13335 AND AS15169
monocle parse file.mrt -o '!13335,!15169'Note: Cannot mix positive and negative values in the same filter.
For large filter sets that exceed command-line argument limits, or for reusable
filter definitions, use --filter-file (JSON) or --prefix-file (newline text).
--prefix-file — a plain text file with one prefix per line. Blank lines and
# comments are ignored. This is the most ergonomic option for the common
RIB-extract → filter-updates workflow:
# Step 1: Extract prefix list from a RIB dump
monocle parse -o 64496 rib.gz | cut -d'|' -f5 | sort -u > prefixes.txt
# Step 2: Filter subsequent updates using the prefix file
monocle parse --prefix-file prefixes.txt updates.gzPrefix file format:
# Prefixes originated by AS64496 (extracted from RIB)
192.0.2.0/24
198.51.100.0/24
# IPv6 prefixes
2001:db8::/32--filter-file — a structured JSON file supporting all filter dimensions:
{
"prefixes": ["192.0.2.0/24", "2001:db8::/32"],
"origin_asns": ["64496"],
"peer_asns": ["174", "6939"],
"communities": ["64496:100", "*:200"],
"as_path_regex": "174 64496$",
"elem_type": "w",
"include_sub": true,
"start_ts": "2025-01-01T00:00:00Z",
"end_ts": "2025-01-01T01:00:00Z"
}All fields are optional — include only the dimensions you need. String-typed
fields use the same syntax as CLI flags, including ! prefix for negation.
Combining with CLI flags — file-based filters merge with CLI filter flags. Within each dimension, values are unioned (OR logic). For example:
# CLI prefix + file prefixes are unioned
monocle parse -p 10.0.0.0/8 --filter-file filters.json updates.gzFor scalar fields (as_path_regex, elem_type, time fields), CLI flags take
precedence over file values. Boolean flags (include_super, include_sub)
are OR-ed.
Using both file types together:
monocle parse \
--filter-file as_filters.json \
--prefix-file extra_prefixes.txt \
updates.gzPrefixes from both sources are unioned into a single prefix filter.
Use -f or --fields to select which columns to display:
# Show only prefix, as_path, and origin
monocle parse file.mrt -f prefix,as_path,origin
# Available fields: type, timestamp, peer_ip, peer_asn, prefix, path_id, as_path,
# origin_asns, origin, next_hop, local_pref, med, communities, atomic, aggr_asn,
# aggr_ip, only-to-customer, collectorUse --order-by and --order to sort the output:
# Sort by timestamp ascending (default)
monocle parse file.mrt --order-by timestamp
# Sort by prefix descending
monocle parse file.mrt --order-by prefix --order descUse --time-format to change timestamp output format (applies to all output formats
including json, json-line, and json-pretty):
# Unix timestamp (default) — numeric `timestamp` field in JSON
monocle parse file.mrt --time-format unix
# RFC3339/ISO 8601 format — string `timestamp` field in JSON
monocle parse file.mrt --time-format rfc3339Example: parse a remote MRT file and show only announcements for a specific prefix:
…The output contains the following fields:
| Field | Description |
|---|---|
type |
Message type: announce or withdraw |
timestamp |
Message timestamp in UTC |
peer_ip |
IP address of the BGP peer |
peer_asn |
ASN of the BGP peer |
peer_bgp_id |
BGP Identifier (Router ID) of the peer, when available |
prefix |
Network prefix being announced/withdrawn |
as_path |
AS path (space-separated) |
origin |
Origin type: IGP, EGP, or INCOMPLETE |
origin_asns |
Origin AS number(s) |
next_hop |
Next hop IP address |
local_pref |
Local preference value |
med |
Multi-exit discriminator |
communities |
BGP communities |
atomic |
Atomic aggregate flag |
aggr_asn |
Aggregator ASN |
aggr_ip |
Aggregator IP |
only_to_customer |
OTC attribute (RFC 9234). Select it with --fields only-to-customer; the JSON/PSV key is only_to_customer |
unknown |
Unknown attributes |
deprecated |
Deprecated attributes |
collector |
Collector name (for search results) |
JSON output example:
{
"type": "announce",
"timestamp": "2024-01-01T00:00:44Z",
"peer_ip": "2001:7f8:4::9d85:1",
"peer_asn": 40325,
"peer_bgp_id": "192.0.2.254",
"prefix": "1.1.1.0/24",
"as_path": "40325 13335",
"origin": "IGP",
"origin_asns": [13335],
"next_hop": "2001:7f8:4::9d85:1",
"local_pref": null,
"med": null,
"communities": [],
"atomic": false,
"aggr_asn": null,
"aggr_ip": null,
"only_to_customer": null,
"unknown": null,
"deprecated": null,
"collector": null
}monocle searchSearch for BGP messages from all available public MRT files using BGPKIT Broker.
…Enable local caching with --use-cache (default XDG cache path) or --cache-dir (custom path):
# Cache MRT files under $XDG_CACHE_HOME/monocle
monocle search -t 2024-01-01 -d 1h -p 1.1.1.0/24 --use-cache
# Cache MRT files to a custom directory
monocle search -t 2024-01-01 -d 1h -p 8.8.8.0/24 --cache-dir /tmp/mrt-cache
# --cache-dir overrides --use-cache when both are specified
monNo open issues yet, or sync has not completed.