본문 바로가기
WIKI 기술 지식 베이스

데이터베이스 모니터링 모니터

원문 보기 위키 갱신

Database Monitoring(DBM) 모니터 유형을 사용하면 DBM에서 드러나는 데이터에 대해 모니터를 만들고 알림을 받을 수 있어요. DBM 이벤트 유형이 일정 기간 동안 미리 정의된 임계값에서 벗어나면 알림을 보내도록 구성할 수 있지요.

출처: 문서

본문

개요

Database Monitoring(DBM) 모니터 유형을 사용하면 DBM에서 드러나는 데이터에 대해 모니터를 만들고 알림을 받을 수 있어요. 이 모니터는 DBM 이벤트 유형이 일정 기간 동안 미리 정의된 임계값에서 벗어나면 알림을 보내도록 구성할 수 있어요.

일반적인 모니터링 시나리오는 다음과 같아요.

  • 대기 중인 쿼리(waiting queries) 수
  • 지정된 시간을 초과하는 쿼리 수
  • explain-plan 비용의 상당한 변화

단계별 지침은 예시 모니터를 참고하세요.

모니터 생성

Datadog에서 새 DBM 모니터를 만들려면 UI에서 Monitors > New Monitor > Database Monitoring으로 이동하세요.

{% alert level="info" %} 계정당 기본 DBM 모니터 제한은 1000개예요. 이 제한에 도달했다면 multi alerts 사용을 고려하거나, Support에 문의해 계정의 제한을 올려달라고 요청하세요. {% /alert %}

검색 쿼리 정의

참고: 쿼리가 변경되면 검색 바 위의 차트가 그에 맞춰 업데이트돼요.

일반적인 모니터 유형

처음부터 모니터를 만들고 싶지 않다면 다음 사전 정의된 모니터 유형 중 하나를 사용할 수 있어요.

  • Waiting Queries
  • Long Running Queries

{% image source="https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/dbm_common_monitor_types.fa8276a84f5b81896bd299cad98e1fef.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/dbm_common_monitor_types.fa8276a84f5b81896bd299cad98e1fef.png?auto=format&fit=max&w=850&dpr=2 2x" alt="Example OOTB monitors related to waiting queries and long running queries" /%}

이 기존 모니터 유형에 대한 피드백이나 추가로 보고 싶은 다른 유형은 Customer Success Manager 또는 Support Team에 공유하세요.

처음부터 모니터 만들기

  1. Query Samples 또는 Explain Plans 중 어느 것을 모니터링할지 결정하고 드롭다운 메뉴에서 해당 옵션을 선택하세요.

{% image source="https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/dbm_event_monitor_data_types.9e7f9479e8b625453cb91ae930bbb807.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/dbm_event_monitor_data_types.9e7f9479e8b625453cb91ae930bbb807.png?auto=format&fit=max&w=850&dpr=2 2x" alt="A dropdown menu showing the different data sources available for the Database Monitoring monitor type" /%} DBM Query Samples 활동과 explain plan 탐색기와 동일한 로직으로 검색 쿼리를 구성하세요. 즉 검색 바에 포함할 facet을 하나 이상 선택해야 해요. 예를 들어 사용자 postgresadmin이 실행한 대기 중인 쿼리(waiting queries)에 대해 알림을 받고 싶다면 검색 바는 다음과 같을 거예요: {% image source="https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/dbm_example_query_no_group_by.033bf57973a99a21f2a06ad1764e403f.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/dbm_example_query_no_group_by.033bf57973a99a21f2a06ad1764e403f.png?auto=format&fit=max&w=850&dpr=2 2x" alt="An example search query containing two facets in the search bar." /%}

참고: 구성한 모니터는 facet들의 고유 값 개수(unique value count) 에 대해 알림을 보내요. 또한 여러 차원으로 DBM 이벤트를 그룹화할 수도 있어요. 쿼리와 일치하는 모든 DBM 이벤트는 최대 네 개의 facet 값에 따라 함께 그룹화돼요. group by 기능을 사용하면 알림 그룹화 전략(alerting grouping strategy) 도 구성할 수 있어요.

  • Simple Alert: 단순 알림은 모든 보고 소스에 대해 집계하므로, 하나 이상의 그룹 값이 임계값을 위반하면 하나의 알림이 트리거돼요. 이 전략을 사용해 알림 노이즈를 줄일 수 있어요.
  • Multi Alert: 다중 알림은 그룹 매개변수에 따라 각 소스에 알림을 적용해요. 즉 설정된 조건을 충족하는 각 그룹에 대해 알림 이벤트가 생성돼요. 예를 들어 @db.user로 쿼리를 그룹화하고 Multi Alert 집계 유형을 선택하면, 정의한 대로 알림을 트리거하는 각 데이터베이스 사용자에 대해 별도의 알림을 받을 수 있어요.

알림 조건 설정

  1. 쿼리 결과가 정의한 임계값보다 above(위), above or equal to(위 또는 같음), below(아래), 또는 below or equal to(아래 또는 같음)일 때 알림이 트리거되도록 설정하세요. 이 보기의 옵션 구성에 대한 도움은 Configure Monitors를 참고하세요.
  2. 5분 동안 데이터가 없을 때의 원하는 동작을 결정하세요. 예: evaluate as zero, show NO DATA, show NO DATA and notify, 또는 show OK.

데이터 없음 및 아래 알림

애플리케이션이 DBM 이벤트 전송을 중단했을 때 알림을 받으려면 조건을 below 1로 설정하세요. 이 알림은 주어진 시간 범위 내 모든 집계 그룹에서 모니터 쿼리와 일치하는 DBM 이벤트가 없을 때 트리거돼요.

모니터를 어떤 차원(태그 또는 facet)으로 분할하고 below 조건을 사용하면, 다음 경우에만 알림이 트리거돼요:

  1. 특정 그룹에 DBM 이벤트가 있지만 개수가 임계값보다 낮은 경우.
  2. 어떤 그룹에도 DBM 이벤트가 없는 경우.

고급 알림 조건

evaluation delay와 같은 고급 알림 옵션에 대한 자세한 내용은 Configure Monitors를 참고하세요.

알림

Configure notifications and automations 섹션에 대한 자세한 내용은 Notifications를 참고하세요.

예시 모니터

대기 중인 쿼리 수

이 모니터는 대기 중인 쿼리(waiting queries) 수가 주어진 임계값을 초과했는지 감지해요.

{% image source="https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/waiting_queries_monitor.b28cfd6a90d8a906eef9ca57614b3f5f.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/waiting_queries_monitor.b28cfd6a90d8a906eef9ca57614b3f5f.png?auto=format&fit=max&w=850&dpr=2 2x" alt="A configured metrics query for monitoring the number of waiting database queries" /%}

모니터링 쿼리 구축

  1. Datadog에서 Monitors > New Monitor > Database Monitoring으로 이동하세요.
  2. Common monitor types 상자에서 Waiting Queries를 클릭하세요.

알림 임계값 설정

  1. 일반적인 값 범위에 대한 맥락을 얻으려면 차트 상단의 드롭다운 메뉴를 사용해 시간 범위를 Past 1 Month로 설정하세요.
  2. Alert threshold 상자에 선택한 알림 임계값을 입력하세요. 예를 들어 차트에서 대기 중인 쿼리 수가 3000 미만을 유지한다면, 비정상적인 활동을 나타내도록 Alert threshold를 4000으로 설정할 수 있어요. 구성 세부 사항은 Set alert conditions과 Advanced alert conditions을 참고하세요.
  3. 차트의 빨간색 음영 영역을 사용해 알림이 너무 드물게 또는 너무 자주 트리거되지 않는지 확인하고, 필요에 따라 임계값을 조정하세요.

알림 구성

  1. Configure notifications and automations에서 알림 메시지를 작성하세요. 자세한 지침은 Notifications를 참고하세요. 메시지 본문에 이 텍스트를 사용할 수 있어요.
    {{#is_alert}}
    Waiting queries on {{host.name}} have exceeded {{threshold}} 
    with a value of {{value}}.
    {{/is_alert}}
    
    {{#is_recovery}}
    The number of waiting queries on {{host.name}}, which exceeded {{threshold}},
    has recovered.
    {{/is_recovery}}
    
1. Notify your services and your team members 상자에 이름을 입력하고 선택해 자신을 알림 수신자에 추가하세요.

#### 모니터 확인 및 저장

1. 모니터 설정을 확인하려면 Test Notifications를 클릭하세요. Alert를 선택해 테스트 알림을 트리거한 다음 Run Test를 클릭하세요.
1. Create를 클릭해 모니터를 저장하세요.

### 30초를 초과하는 쿼리

이 모니터는 오래 실행되는 쿼리(long-running queries) 수가 주어진 임계값을 초과했는지 감지해요.

{% image
   source="https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/long_running_queries_monitor.2bd5c72c246bb333d6f81a25cd5d4ca7.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/long_running_queries_monitor.2bd5c72c246bb333d6f81a25cd5d4ca7.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="A configured metrics query for monitoring the number of long-running database queries" /%}

#### 모니터링 쿼리 구축

1. Datadog에서 [Monitors > New Monitor > Database Monitoring](https://app.datadoghq.com/monitors/create/database-monitoring)으로 이동하세요.
1. Common monitor types에서 Long Running Queries를 클릭하세요.
1. 쿼리 필터를 Duration:>30s로 업데이트하세요.

#### 알림 임계값 설정

1. 일반적인 값 범위에 대한 맥락을 얻으려면 차트 상단의 드롭다운 메뉴를 사용해 시간 범위를 Past 1 Month로 설정하세요.
1. Alert threshold 상자에 선택한 알림 임계값을 입력하세요. 예를 들어 차트의 값이 `2000` 미만을 유지한다면, 비정상적인 활동을 나타내도록 Alert threshold를 `2500`으로 설정할 수 있어요. 구성 세부 사항은 [Set alert conditions](https://docs.datadoghq.com/monitors/configuration.md?tab=thresholdalert#set-alert-conditions)과 [Advanced alert conditions](https://docs.datadoghq.com/monitors/create/configuration.md#advanced-alert-conditions)을 참고하세요.
1. 차트의 빨간색 음영 영역을 사용해 알림이 너무 드물게 또는 너무 자주 트리거되지 않는지 확인하고, 필요에 따라 임계값을 조정하세요.

#### 알림 구성

1. Configure notifications and automations에서 알림 메시지를 작성하세요. 자세한 지침은 [Notifications](https://docs.datadoghq.com/monitors/notify.md)를 참고하세요. 메시지 본문에 이 텍스트를 사용할 수 있어요.
   ```text
   {{#is_alert}}
   The number of queries with a duration of >30s has exceeded 
   {{threshold}} on {{host.name}} with a value of {{value}}.
   {{/is_alert}}
   
   {{#is_recovery}}
   The number of queries with a duration of >30s on {{host.name}}, 
   which exceeded {{threshold}}, has recovered.
   {{/is_recovery}}
  1. Notify your services and your team members 상자에 이름을 입력하고 선택해 자신을 알림 수신자에 추가하세요.

모니터 확인 및 저장

  1. 모니터 설정을 확인하려면 Test Notifications를 클릭하세요. Alert를 선택해 테스트 알림을 트리거한 다음 Run Test를 클릭하세요.
  2. Create를 클릭해 모니터를 저장하세요.

explain-plan 비용의 변화

{% image source="https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/explain_plan_cost_monitor.686f4b16d3af98cebb52ae6d5d421282.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/database_monitoring/dbm_event_monitor/explain_plan_cost_monitor.686f4b16d3af98cebb52ae6d5d421282.png?auto=format&fit=max&w=850&dpr=2 2x" alt="A monitor configured to track changes in average daily explain-plan cost" /%}

이 모니터는 두 쿼리의 결과를 비교해 일일 평균 explain-plan 비용의 상당한 변화를 감지해요.

  • 쿼리 a는 현재 explain-plan 비용을 반영해요.
  • 쿼리 b는 일주일 전 explain-plan 비용을 반영해요.

이를 통해 예를 들어 연속된 두 월요일을 비교할 수 있어요.

약간의 변경으로 이 모니터는 대신 시간별 평균을 반영하거나, 오늘과 어제의 차이를 측정하거나, 호스트 대신 쿼리 시그니처로 그룹화하는 등으로 바꿀 수 있어요.

첫 번째 모니터링 쿼리 구축

  1. Datadog에서 Monitors > New Monitor > Database Monitoring으로 이동하세요.
  2. Define the search query에서 다음 업데이트를 수행하세요.
    • Query Samples를 Explain Plans로 변경하세요.
    • *를 Explain Plan Cost(@db.plan.cost)로 변경하세요. 필드에 "cost"를 입력하면 자동 완성 옵션이 채워져요.
    • (everything)을 Host (host)로 변경하세요.
  3. ∑ 버튼을 클릭하고 rollup을 입력해 자동 완성 제안을 채우세요. moving_rollup을 선택하세요.

두 번째 모니터링 쿼리 구축

  1. Add Query를 클릭해 쿼리 a의 복사본인 쿼리 b를 만드세요.
  2. a + b를 a - b로 변경하세요. 두 쿼리가 일시적으로 동일하므로 이 값은 차트에 0으로 표시돼요.
  3. b 쿼리에서 ∑ 버튼을 클릭하고 Timeshift > Week before를 선택하세요. 이렇게 하면 지난 주와 현재 사이의 상당한 변화를 감지하도록 모니터가 구성돼요.

알림 임계값 설정

  1. 차트 상단의 드롭다운 메뉴에서 시간 범위를 Past 1 Month로 확장해 주별 일반적인 비용 변화에 대한 맥락을 얻으세요.
  2. alert threshold 상자에 선택한 알림 임계값을 입력하세요. 예를 들어 차트에서 explain-plan 비용의 차이가 8000 미만을 유지한다면, 비정상적인 활동을 나타내도록 alert threshold를 9000으로 설정할 수 있어요. 구성 세부 사항은 Set alert conditions과 Advanced alert conditions을 참고하세요.
  3. 차트의 빨간색 음영 영역을 사용해 알림이 너무 드물게 또는 너무 자주 트리거되지 않는지 확인하고, 필요에 따라 임계값을 조정하세요.

알림 구성

  1. Configure notifications and automations에서 알림 메시지를 작성하세요. 자세한 지침은 Notifications를 참고하세요. 메시지 본문에 이 텍스트를 사용할 수 있어요.
    {{#is_alert}}
    The daily average explain-plan cost on {{host.name}} has increased by at least {{threshold}} 
    versus one week ago, with a value of {{value}}.
    {{/is_alert}}
    
    {{#is_recovery}}
    The daily average explain-plan cost on {{host.name}} has recovered to within {{threshold}}
    of the cost on this day last week.
    {{/is_recovery}}
    
1. Notify your services and your team members 상자에 이름을 입력하고 선택해 자신을 알림 수신자에 추가하세요.

#### 모니터 확인 및 저장

1. 모니터 설정을 확인하려면 Test Notifications를 클릭하세요. Alert를 선택해 테스트 알림을 트리거한 다음 Run Test를 클릭하세요.
1. Create를 클릭해 모니터를 저장하세요.