문서 메뉴
문서 홈
/ / /
Go 드라이버
/ /

클러스터 모니터링

이 페이지의 내용

  • 개요
  • 이벤트 구독
  • 이벤트 설명
  • 이벤트 문서 예시
  • ServerDescriptionChangedEvent
  • ServerOpeningEvent
  • ServerClosedEvent
  • 토폴로지 설명 변경 이벤트
  • 토폴로지OpeningEvent
  • 토폴로지 닫힘 이벤트
  • ServerHeartbeatStartedEvent
  • ServerHeartbeatSucceededEvent
  • ServerHeartbeatFailedEvent
  • API 문서

이 가이드에서는 Go 드라이버를 사용하여 MongoDB 인스턴스, 복제본 세트 또는 cluster에서 토폴로지 이벤트를 모니터링하는 방법을 보여 줍니다. 연결된 인스턴스 또는 cluster의 상태가 변경될 때 드라이버는 토폴로지 이벤트(서버 검색 및 모니터링(SDAM) 이벤트라고도 함)를 생성합니다.

애플리케이션의 토폴로지 이벤트에 대한 정보를 사용하여 cluster 변경 사항을 이해하거나, cluster 상태를 평가하거나, 용량 계획을 수행할 수 있습니다.

로깅

애플리케이션에서 로그인을 구성하여 드라이버 이벤트에 대해 자세히 알아볼 수도 있습니다. 자세한 내용은 로깅을 참조하세요.

애플리케이션에서 SDAM 이벤트를 구독하면 해당 이벤트에 대한 세부 정보에 액세스할 수 있습니다. 다음 예제에서는 ServerMonitor 를 인스턴스화하고 배포서버에 연결하여 ServerClosed 이벤트를 구독하는 방법을 보여 줍니다.

var eventArray []*event.ServerClosedEvent
srvMonitor := &event.ServerMonitor{
ServerClosed: func(e *event.ServerClosedEvent) {
eventArray = append(eventArray, e)
},
}
clientOpts := options.Client().ApplyURI(uri).SetServerMonitor(srvMonitor)
client, err := mongo.Connect(context.TODO(), clientOpts)

ServerMonitor 인스턴스의 속성을 지정하여 다음 SDAM 이벤트를 구독할 수 있습니다.

이벤트 이름
설명
ServerDescriptionChangedEvent
인스턴스 상태가 변경될 때 생성됩니다(예: 세컨더리에서 프라이머리로).
ServerOpeningEvent
서버가 초기화될 때 생성됩니다.
ServerClosedEvent
서버가 닫힐 때 생성됩니다.
TopologyDescriptionChangedEvent
새 기본 프록시가 투표되거나 mongos 프록시의 연결이 끊어지는 등 토폴로지가 변경될 때 생성됩니다.
TopologyOpeningEvent
토폴로지가 초기화될 때 생성됩니다.
TopologyClosedEvent
토폴로지가 닫힐 때 생성됩니다.
ServerHeartbeatStartedEvent
하트비트가 시작될 때 생성됩니다.
ServerHeartbeatSucceededEvent
하트비트가 성공할 때 생성됩니다.
ServerHeartbeatFailedEvent
하트비트가 실패할 때 생성됩니다.

다음 섹션에서는 각 유형의 SDAM 이벤트에 대한 샘플 출력을 보여줍니다.

*event.ServerDescriptionChangedEvent
{
"Address": "...",
"TopologyID": "...",
"PreviousDescription": {
"Addr": "...",
"Arbiters": null,
"AverageRTT": 0,
"AverageRTTSet": false,
"Compression": null,
"CanonicalAddr": "...",
"ElectionID": "...",
"HeartbeatInterval": 0,
"HelloOK": false,
"Hosts": null,
"LastError": null,
"LastUpdateTime": "...",
"LastWriteTime": "...",
"MaxBatchCount": 0,
"MaxDocumentSize": 0,
"MaxMessageSize": 0,
"Members": null,
"Passives": null,
"Passive": false,
"Primary": "...",
"ReadOnly": false,
"ServiceID": null,
"SessionTimeoutMinutes": 0,
"SetName": "...",
"SetVersion": 0,
"Tags": null,
"TopologyVersion": null,
"Kind": 0,
"WireVersion": null
},
"NewDescription": {
"Addr": "...",
"Arbiters": null,
"AverageRTT": ...,
"AverageRTTSet": true,
"Compression": null,
"CanonicalAddr": "...",
"ElectionID": "...",
"HeartbeatInterval": ...,
"HelloOK": true,
"Hosts": [...],
"LastError": null,
"LastUpdateTime": "...",
"LastWriteTime": "...",
"MaxBatchCount": ...,
"MaxDocumentSize": ...,
"MaxMessageSize": ...,
"Members": [...],
"Passives": null,
"Passive": false,
"Primary": "...",
"ReadOnly": false,
"ServiceID": null,
"SessionTimeoutMinutes": 30,
"SetName": "...",
"SetVersion": 9,
"Tags": [...],
"TopologyVersion": {...},
"Kind": 10,
"WireVersion": {...}
}
}

이벤트 문서의 Kind 필드는 토폴로지의 단일 서버 유형을 나타내며 다음 값을 가질 수 있습니다.

설명
0
알 수 없는 인스턴스
1
독립형 인스턴스
2
복제본 세트 멤버
6
프라이머리 인스턴스
10
세컨더리 인스턴스
18
중재자 인스턴스
34
복제본 세트 고스트(쿼리할 수 없는 멤버)
256
mongos 프록시 인스턴스
512
로드 밸런서 인스턴스
*event.ServerOpeningEvent
{
"Address": "...",
"TopologyID": "..."
}
*event.ServerClosedEvent
{
"Address": "...",
"TopologyID": "..."
}

중요

배포 토폴로지가 잠겨 있을 때 드라이버는 TopologyDescriptionChangedEvent 를 호출하므로 이 이벤트에 대한 콜백(함수 인수)은 동일한 클라이언트에서 서버 선택이 필요한 작업을 시도해서는 안 됩니다.

*event.TopologyDescriptionChangedEvent
{
"TopologyID": "...",
"PreviousDescription": {
"Servers": [
{
"Addr": "...",
"Arbiters": null,
"AverageRTT": 0,
"AverageRTTSet": false,
"Compression": null,
"CanonicalAddr": "...",
"ElectionID": "...",
"HeartbeatInterval": 0,
"HelloOK": false,
"Hosts": null,
"LastError": null,
"LastUpdateTime": "...",
"LastWriteTime": "...",
"MaxBatchCount": 0,
"MaxDocumentSize": 0,
"MaxMessageSize": 0,
"Members": null,
"Passives": null,
"Passive": false,
"Primary": "...",
"ReadOnly": false,
"ServiceID": null,
"SessionTimeoutMinutes": 0,
"SetName": "...",
"SetVersion": 0,
"Tags": null,
"TopologyVersion": null,
"Kind": 0,
"WireVersion": null
},
...
],
"SetName": "...",
"Kind": 10,
"SessionTimeoutMinutes": 30,
"CompatibilityErr": null
},
"NewDescription": {
"Servers": [...],
"SetName": "...",
"Kind": 10,
"SessionTimeoutMinutes": 30,
"CompatibilityErr": null
}
}

Kind 필드의 값을 해석하려면 종류 필드 값 섹션을 참조하세요.

*event.TopologyOpeningEvent
{
"TopologyID": "..."
}
*event.TopologyClosedEvent
{
"TopologyID": "..."
}
*event.ServerHeartbeatStartedEvent
{
"ConnectionID": "...",
"Awaited": true
}
*event.ServerHeartbeatSucceededEvent
{
"DurationNanos": ...,
"Reply": {
"Addr": "...",
"Arbiters": null,
"AverageRTT": 0,
"AverageRTTSet": false,
"Compression": null,
"CanonicalAddr": "...",
"ElectionID": "...",
"HeartbeatInterval": 0,
"HelloOK": true,
"Hosts": [...],
"LastError": null,
"LastUpdateTime": "...",
"LastWriteTime": "...",
"MaxBatchCount": ...,
"MaxDocumentSize": ...,
"MaxMessageSize": ...,
"Members": [...],
"Passives": null,
"Passive": false,
"Primary": "...",
"ReadOnly": false,
"ServiceID": null,
"SessionTimeoutMinutes": 30,
"SetName": "...",
"SetVersion": 9,
"Tags": [...],
"TopologyVersion": {...},
"Kind": 6,
"WireVersion": {...}
},
"ConnectionID": "...",
"Awaited": true
}

Kind 필드의 값을 해석하려면 종류 필드 값 섹션을 참조하세요.

*event.ServerHeartbeatFailedEvent
{
"DurationNanos": ...,
"Failure": "<error message>"
"ConnectionID": "...",
"Awaited": true
}
← 모니터링