service
service
¶
Monitor service for relay health monitoring with NIP-66 compliance.
Performs comprehensive health checks on relays and stores results as content-addressed Metadata. Optionally publishes Kind 30166 relay discovery events and Kind 10166 monitor announcements to the Nostr network.
Health checks include:
- Nip11: Relay info document (name, description, pubkey, supported NIPs).
- Nip66RttMetadata: Open/read/write round-trip times in milliseconds.
- Nip66SslMetadata: SSL certificate validation (clearnet only).
- Nip66DnsMetadata: DNS hostname resolution (clearnet only).
- Nip66GeoMetadata: IP geolocation (clearnet only).
- Nip66NetMetadata: ASN/organization info (clearnet only).
- Nip66HttpMetadata: HTTP status codes and headers.
Note
Event building is delegated to bigbrotr.nips.event_builders and broadcasting to bigbrotr.utils.transport. The Monitor handles orchestration: when to publish, which data to extract from CheckResult, and lifecycle management of publishing intervals via service state checkpoints.
See Also
MonitorConfig: Configuration
model for networks, processing, geo, publishing, and discovery.
BaseService: Abstract base
class providing run(), run_forever(), and from_yaml().
Brotr: Database facade used for metadata
persistence and checkpoint management.
Validator: Upstream service
that promotes candidates to the relay table.
Examples:
from bigbrotr.core import Brotr
from bigbrotr.services import Monitor
brotr = Brotr.from_yaml("config/brotr.yaml")
monitor = Monitor.from_yaml("config/services/monitor.yaml", brotr=brotr)
async with brotr:
async with monitor:
await monitor.run_forever()
Classes¶
CheckResult
¶
Bases: NamedTuple
Result of a single relay health check.
Each field contains the typed NIP metadata container if that check was run
and produced data, or None if the check was skipped (disabled in config)
or failed completely. Use has_data to test whether any check produced
results.
Attributes:
-
generated_at(int) –Unix timestamp when the health check was performed.
-
nip11(Nip11InfoMetadata | None) –NIP-11 relay information document (name, description, pubkey, etc.).
-
nip66_rtt(Nip66RttMetadata | None) –Round-trip times for open/read/write operations in milliseconds.
-
nip66_ssl(Nip66SslMetadata | None) –SSL certificate validation (valid, expiry timestamp, issuer).
-
nip66_geo(Nip66GeoMetadata | None) –Geolocation data (country, city, coordinates, timezone, geohash).
-
nip66_net(Nip66NetMetadata | None) –Network information (IP address, ASN, organization).
-
nip66_dns(Nip66DnsMetadata | None) –DNS resolution data (IPs, CNAME, nameservers, reverse DNS).
-
nip66_http(Nip66HttpMetadata | None) –HTTP metadata (status code, headers, redirect chain).
See Also
MetadataFlags: Boolean flags controlling which check types are computed and stored.
Monitor
¶
Monitor(brotr: Brotr, config: MonitorConfig | None = None)
Bases: ChunkProgressMixin, NetworkSemaphoresMixin, GeoReaderMixin, BaseService[MonitorConfig]
Relay health monitoring service with NIP-66 compliance.
Performs comprehensive health checks on relays and stores results as content-addressed Metadata. Optionally publishes NIP-66 events:
- Kind 10166: Monitor announcement (capabilities, frequency, timeouts).
- Kind 30166: Per-relay discovery event (RTT, SSL, geo, NIP-11 tags).
Each cycle updates GeoLite2 databases, publishes profile/announcement events if due, fetches relays needing checks, processes them in chunks with per-network semaphores, persists metadata results, and publishes Kind 30166 discovery events. Supports clearnet (direct), Tor, I2P, and Lokinet (via SOCKS5 proxy).
Event building is delegated to bigbrotr.nips.event_builders and broadcasting to bigbrotr.utils.transport.
See Also
MonitorConfig:
Configuration model for this service.
Validator: Upstream
service that promotes candidates to the relay table.
Synchronizer:
Downstream service that collects events from monitored relays.
Source code in src/bigbrotr/services/monitor/service.py
Functions¶
run
async
¶
Execute one complete monitoring cycle.
Orchestrates setup, publishing, monitoring, and cycle-level logging.
Delegates the core work to update_geo_databases,
publish_profile, publish_announcement, and monitor.
Source code in src/bigbrotr/services/monitor/service.py
update_geo_databases
async
¶
Download or re-download GeoLite2 databases if missing or stale.
Download failures are logged and suppressed so that a transient network error does not prevent the monitor cycle from proceeding with a stale (or missing) database.
Source code in src/bigbrotr/services/monitor/service.py
monitor
async
¶
Count, check, persist, and publish all pending relays.
High-level entry point that counts relays due for checking, processes
them in chunks via check_chunks, publishes Kind 30166 discovery
events, persists metadata results, and emits progress metrics.
Returns the total number of relays processed.
This is the method run() delegates to after setup. It can also
be called standalone when GeoIP update and profile/announcement
publishing are not desired.
Returns:
-
int–Total number of relays processed (successful + failed).
Source code in src/bigbrotr/services/monitor/service.py
check_chunks
async
¶
check_chunks() -> AsyncIterator[
tuple[list[tuple[Relay, CheckResult]], list[Relay]]
]
Yield (successful, failed) for each processed chunk of relays.
Requires geo_readers.open() for full checks. Handles chunk
fetching, budget calculation, and concurrent health checks.
Persistence and publishing are left to the caller. Networks, chunk
size, and relay limit are read from
MonitorConfig.
Yields:
-
AsyncIterator[tuple[list[tuple[Relay, CheckResult]], list[Relay]]]–Tuple of (successful relay-result pairs, failed relays) per chunk.
Source code in src/bigbrotr/services/monitor/service.py
check_relay
async
¶
check_relay(relay: Relay) -> CheckResult
Perform all configured health checks on a single relay.
Runs Nip11, RTT, SSL, DNS, geo, net, and HTTP checks as configured. Uses the network-specific semaphore (from NetworkSemaphoresMixin) to limit concurrency.
Note
NIP-11 is fetched first because the RTT write-test may need
the min_pow_difficulty from NIP-11's limitation object
to apply proof-of-work on the test event. All other checks
(SSL, DNS, Geo, Net, HTTP) run in parallel after NIP-11 and RTT.
Returns:
-
CheckResult–CheckResult with
-
CheckResult–metadata for each completed check (
Noneif skipped/failed).
Source code in src/bigbrotr/services/monitor/service.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
publish_announcement
async
¶
Publish Kind 10166 monitor announcement if the configured interval has elapsed.
Source code in src/bigbrotr/services/monitor/service.py
publish_profile
async
¶
Publish Kind 0 profile metadata if the configured interval has elapsed.
Source code in src/bigbrotr/services/monitor/service.py
publish_relay_discoveries
async
¶
publish_relay_discoveries(
successful: list[tuple[Relay, CheckResult]],
) -> None
Publish Kind 30166 relay discovery events for successful health checks.