개요
이 가이드에서는 Rust 드라이버를 사용하여 드라이버가 MongoDB deployment로 보내는 명령의 결과를 모니터링하는 방법을 보여줍니다.
애플리케이션의 명령 이벤트에 대한 정보를 사용하거나 명령을 모니터링하여 드라이버가 명령을 실행하는 방법에 대해 자세히 알아볼 수 있습니다.
이 가이드에는 다음 섹션이 포함되어 있습니다.
이벤트 설명
다음 명령 모니터링 이벤트 중 하나 이상을 구독할 수 있습니다.
이벤트 이름 | 설명 |
---|---|
명령이 시작될 때 생성됩니다. | |
명령이 성공하면 생성됩니다. | |
명령이 성공하지 못했을 때 생성됩니다. |
이벤트 구독 예시
애플리케이션에서 하나 이상의 명령 이벤트를 구독하여 액세스할 수 있습니다. 다음 예제에서는 MongoDB deployment에 연결하고 CommandStartedEvent
이벤트 유형을 구독합니다.
struct CommandStartHandler; impl CommandEventHandler for CommandStartHandler { fn handle_command_started_event(&self, event: CommandStartedEvent) { eprintln!("Command started: {:?}", event); } } let handler: Arc<dyn CommandEventHandler> = Arc::new(CommandStartHandler); client_options.command_event_handler = Some(handler); let client = Client::with_options(client_options)?; // ... perform actions with the client to generate events
이벤트 문서 예시
다음 섹션에서는 각 유형의 명령 모니터링 이벤트에 대한 샘플 출력을 보여줍니다.
CommandStartedEvent
CommandStartedEvent { request_id: 12, db: "testdb", command_name: "find", connection: ..., command: ..., service_id: ... }
CommandSucceededEvent
CommandSucceededEvent { duration: ..., reply: ..., command_name: "find", request_id: 12, connection: ..., service_id: ..., }
CommandFailedEvent
CommandFailedEvent { duration: ..., command_name: "find", failure: ..., request_id: 12, connection: ..., service_id: ..., }
추가 정보
MongoDB 배포 모니터링에 대해 자세히 알아보려면 MongoDB를 모니터링하는 방법 문서를 참조하세요.
MongoDB 작업 수행에 학습 보려면 CRUD 작업 가이드를 참조하세요.
API 문서
이 가이드에서 사용되는 메서드 또는 유형에 대해 자세히 알아보려면 다음 API 문서를 참조하세요.