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:
- Nip11InfoMetadata: 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.protocol. The Monitor handles orchestration: when to publish, which data to extract from CheckResult, and lifecycle management of publishing intervals via service state markers.
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 state 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¶
Monitor
¶
Monitor(brotr: Brotr, config: MonitorConfig | None = None)
Bases: ConcurrentStreamMixin, NetworkSemaphoresMixin, GeoReaderMixin, ClientsMixin, 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.protocol.
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 cleanup.
Delegates the core work to update_geo_databases,
publish_profile, publish_announcement, and monitor.
Publish relay connections are established lazily on first use
via clients.get() and torn down in the finally
block.
Source code in src/bigbrotr/services/monitor/service.py
cleanup
async
¶
Remove stale relay checkpoints and orphaned publishing state.
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
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_list
async
¶
Publish Kind 10002 relay list metadata if the configured interval has elapsed.
Source code in src/bigbrotr/services/monitor/service.py
publish_announcement
async
¶
Publish Kind 10166 monitor announcement if the configured interval has elapsed.
Source code in src/bigbrotr/services/monitor/service.py
publish_discovery
async
¶
publish_discovery(
relay: Relay, result: CheckResult
) -> None
Publish a Kind 30166 relay discovery event for a single relay.
Resolves discovery publish relays from config, connects lazily
via clients.get_many(), builds the event, and broadcasts.
Parameters:
-
relay(Relay) –The relay that was health-checked.
-
result(CheckResult) –Health check result containing metadata.
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 NIP-11, RTT, SSL, DNS, geo, net, and HTTP checks as configured. The caller is responsible for acquiring the per-network semaphore.
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
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
monitor
async
¶
Check, persist, and publish all pending relays.
Fetches relays in pages (chunk_size), checks each page
concurrently via _iter_concurrent(), persists results
at each pagination boundary, and publishes Kind 30166
discovery events per successful check.
Returns:
-
int–Total number of relays processed (succeeded + failed).