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

자체 호스팅 SQL Server용 데이터베이스 모니터링 설정

원문 보기 위키 갱신

Database Monitoring은 Microsoft SQL Server 데이터베이스에 대한 깊은 가시성을 제공해요. 쿼리 메트릭, 쿼리 샘플, 실행 계획(explain plan), 데이터베이스 상태, 장애 조치(failover), 이벤트까지 한눈에 볼 수 있어요.

데이터베이스에서 Database Monitoring을 활성화하려면 다음 단계를 진행해요.

  1. Agent 접근 권한 부여
  2. Agent 설치

출처: 문서

본문

시작하기 전에

{% dl %}

{% dt %} 지원되는 SQL Server 버전 {% /dt %}

{% dd %} 2012, 2014, 2016, 2017, 2019, 2022, 2025 (Agent 7.79+ 필요) {% /dd %}

{% dt %} 지원되는 Agent 버전 {% /dt %}

{% dd %} 7.41.0+ {% /dd %}

{% dt %} 성능 영향 {% /dt %}

{% dd %} Database Monitoring의 기본 Agent 설정은 보수적이지만, 수집 간격이나 쿼리 샘플링 비율 같은 설정은 필요에 맞게 조정할 수 있어요. 대부분의 워크로드에서 Agent는 데이터베이스의 쿼리 실행 시간의 1% 미만, CPU의 1% 미만을 차지합니다. Database Monitoring은 기본 Agent 위에서 통합(integration)으로 실행돼요 (벤치마크 참고). {% /dd %}

{% dt %} 프록시, 로드 밸런서, 커넥션 풀러 {% /dt %}

{% dd %} Datadog Agent는 모니터링 대상 호스트에 직접 연결해야 해요. Agent는 프록시, 로드 밸런서, 커넥션 풀러를 통해 데이터베이스에 연결하면 안 됩니다. 실행 중에 Agent가 다른 호스트에 연결하면(장애 조치, 로드 밸런싱 등) 두 호스트 간의 통계 차이를 계산하므로 부정확한 메트릭이 만들어져요. {% /dd %}

{% dt %} 데이터 보안 고려 사항 {% /dt %}

{% dd %} Agent가 데이터베이스에서 수집하는 데이터와 안전하게 보호하는 방법에 대해서는 Database Management가 민감 정보를 어떻게 처리하는지 읽어보세요. {% /dd %}

{% dt %} RDS Custom {% /dt %}

{% dd %} Datadog는 OS 수준 변경을 하는 일부 RDS Custom 구성에 대해 DBM을 지원해요. 이 지원은 커스터마이제이션이 DBM과 안정적으로 호환되는지에 따라 달라져요. {% /dd %}

{% /dl %}

Agent 접근 권한 부여

Datadog Agent는 통계와 쿼리를 수집하려면 데이터베이스 서버에 대한 읽기 전용 접근이 필요해요.

서버에 연결할 읽기 전용 로그인을 만들고 필요한 권한을 부여하세요:

{% tab title="SQL Server 2014+" %}

CREATE LOGIN datadog WITH PASSWORD = '<PASSWORD>';
CREATE USER datadog FOR LOGIN datadog;
GRANT CONNECT ANY DATABASE to datadog;
GRANT VIEW SERVER STATE to datadog;
GRANT VIEW ANY DEFINITION to datadog;
-- If not using either of Log Shipping Monitoring (available in Agent v7.50+) or
-- SQL Server Agent Monitoring (available in Agent v7.57+), comment out the next three lines:
USE msdb;
CREATE USER datadog FOR LOGIN datadog;
GRANT SELECT to datadog;

{% /tab %}

{% tab title="SQL Server 2012" %}

CREATE LOGIN datadog WITH PASSWORD = '<PASSWORD>';
CREATE USER datadog FOR LOGIN datadog;
GRANT VIEW SERVER STATE to datadog;
GRANT VIEW ANY DEFINITION to datadog;
-- If not using either of Log Shipping Monitoring (available in Agent v7.50+) or
-- SQL Server Agent Monitoring (available in Agent v7.57+), comment out the next three lines:
USE msdb;
CREATE USER datadog FOR LOGIN datadog;
GRANT SELECT to datadog;

추가 애플리케이션 데이터베이스마다 datadog 사용자를 생성하세요:

USE [database_name];
CREATE USER datadog FOR LOGIN datadog;

{% /tab %}

비밀번호 안전하게 보관

Vault 같은 시크릿 관리 소프트웨어로 비밀번호를 보관하세요. 그러면 Agent 설정 파일에서 ENC[<SECRET_NAME>] 형식으로 참조할 수 있어요. 예를 들어 ENC[datadog_user_database_password]처럼요. 자세한 내용은 Secrets Management를 참고해요.

이 페이지의 예제는 비밀번호가 저장된 시크릿 이름으로 datadog_user_database_password를 사용해요. 비밀번호를 평문으로도 참조할 수 있지만 권장하지 않아요.

Agent 설치

SQL Server 호스트에 직접 Agent를 설치하는 것을 권장해요. 그러면 SQL Server 특정 텔레메트리 외에도 다양한 시스템 텔레메트리(CPU, 메모리, 디스크, 네트워크)를 수집할 수 있기 때문이에요.

{% tab title="Windows Host" %} 참고: AlwaysOn 사용자는 각 개별 레플리카에 Agent를 설치하는 것을 권장해요. 그러면 각 레플리카에 대한 관련 인프라 메트릭(CPU, 메모리, 네트워킹)을 제공할 수 있어요. Agent가 연결된 각 레플리카에서 관련 가용성 그룹의 텔레메트리가 수집됩니다. 대체 방법으로 Agent를 별도 서버에 설치하고 리스너 엔드포인트를 통해 클러스터에 연결할 수도 있지만, 이 경우 기본 호스트의 인프라 메트릭을 연관시키는 것은 불가능해요. SQL Server 텔레메트리 수집을 시작하려면 먼저 Datadog Agent를 설치하세요.

SQL Server Agent 설정 파일 C:\ProgramData\Datadog\conf.d\sqlserver.d\conf.yaml을 생성하세요. 사용 가능한 모든 설정 옵션은 샘플 설정 파일을 참고해요.

init_config:
instances:
  - dbm: true
    host: '<HOSTNAME>,<PORT>'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    # Optional: For additional tags
    tags:  
      - 'service:<CUSTOM_SERVICE>'
      - 'env:<CUSTOM_ENV>'

Windows 인증을 사용하려면 connection_string: "Trusted_Connection=yes"를 설정하고 username과 password 필드는 생략하세요.

Agent는 7.41+ 버전에서 SQL Server Browser Service를 지원해요. SSBS를 활성화하려면 host 문자열에 포트 0을 지정하세요: <HOSTNAME>,0.

service와 env 태그를 사용해 공통 태그 구성 체계로 데이터베이스 텔레메트리를 다른 텔레메트리와 연결하세요. Datadog 전체에서 이 태그들을 어떻게 사용하는지는 Unified Service Tagging을 참고해요.

지원되는 드라이버

Microsoft ADO

권장 ADO 프로바이더는 Microsoft OLE DB Driver예요. Agent가 실행 중인 호스트에 드라이버가 설치되어 있는지 확인하세요.

connector: adodbapi
adoprovider: MSOLEDBSQL19  # Replace with MSOLEDBSQL for versions 18 and lower

다른 두 프로바이더인 SQLOLEDB와 SQLNCLI는 Microsoft에서 더 이상 사용하지 않는(deprecated) 것으로 간주하므로 더 이상 사용하면 안 돼요.

ODBC

권장 ODBC 드라이버는 Microsoft ODBC Driver예요. Agent가 실행 중인 호스트에 드라이버가 설치되어 있는지 확인하세요.

connector: odbc
driver: 'ODBC Driver 18 for SQL Server'

모든 Agent 설정이 완료되면 Datadog Agent를 재시작하세요.

검증

Agent의 status 하위 명령을 실행하고 Checks 섹션에서 sqlserver를 찾아보세요. Datadog의 Databases 페이지로 이동해서 시작하세요. {% /tab %}

{% tab title="Linux Host" %} 참고: AlwaysOn 사용자는 각 개별 레플리카에 Agent를 설치하는 것을 권장해요. 그러면 각 레플리카에 대한 관련 인프라 메트릭(CPU, 메모리, 네트워킹)을 제공할 수 있어요. Agent가 연결된 각 레플리카에서 관련 가용성 그룹의 텔레메트리가 수집됩니다. 대체 방법으로 Agent를 별도 서버에 설치하고 리스너 엔드포인트를 통해 클러스터에 연결할 수도 있지만, 이 경우 기본 호스트의 인프라 메트릭을 연관시키는 것은 불가능해요. SQL Server 텔레메트리 수집을 시작하려면 먼저 Datadog Agent를 설치하세요.

Linux에서 Datadog Agent는 추가로 ODBC SQL Server 드라이버가 설치되어 있어야 해요. 예를 들어 Microsoft ODBC driver처럼요. ODBC SQL Server가 설치되면 odbc.ini와 odbcinst.ini 파일을 /opt/datadog-agent/embedded/etc 폴더로 복사하세요.

odbc 커넥터를 사용하고 odbcinst.ini 파일에 표시된 대로 적절한 드라이버를 지정하세요.

SQL Server Agent 설정 파일 /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml을 생성하세요. 사용 가능한 모든 설정 옵션은 샘플 설정 파일을 참고해요.

init_config:
instances:
  - dbm: true
    host: '<HOSTNAME>,<PORT>'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: odbc
    driver: '<Driver from the `odbcinst.ini` file>'
    # Optional: For additional tags
    tags:  
      - 'service:<CUSTOM_SERVICE>'
      - 'env:<CUSTOM_ENV>'

service와 env 태그를 사용해 공통 태그 구성 체계로 데이터베이스 텔레메트리를 다른 텔레메트리와 연결하세요. Datadog 전체에서 이 태그들을 어떻게 사용하는지는 Unified Service Tagging을 참고해요.

모든 Agent 설정이 완료되면 Datadog Agent를 재시작하세요.

검증

Agent의 status 하위 명령을 실행하고 Checks 섹션에서 sqlserver를 찾아보세요. Datadog의 Databases 페이지로 이동해서 시작하세요. {% /tab %}

예제 Agent 설정

Linux에서 ODBC 드라이버로 DSN 연결

  1. odbc.ini와 odbcinst.ini 파일을 찾으세요. 기본적으로 ODBC를 설치할 때 /etc 디렉토리에 배치돼요.

  2. odbc.ini와 odbcinst.ini 파일을 /opt/datadog-agent/embedded/etc 폴더로 복사하세요.

  3. DSN 설정을 다음과 같이 구성하세요:

odbcinst.ini는 섹션 헤더 한 개와 ODBC 드라이버 위치를 제공해야 해요.

예:

[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.2.1
UsageCount=1

odbc.ini는 섹션 헤더와 odbcinst.ini와 일치하는 Driver 경로를 제공해야 해요.

예:

[datadog]
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.2.1
  1. DSN 정보로 /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml 파일을 업데이트하세요.

예:

instances:
  - dbm: true
    host: 'localhost,1433'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: 'odbc'
    driver: 'ODBC Driver 18 for SQL Server' # This is the section header of odbcinst.ini
    dsn: 'datadog' # This is the section header of odbc.ini
  1. Agent를 재시작하세요.

AlwaysOn 사용

AlwaysOn 사용자라면 Agent를 각 레플리카 서버에 설치하고 각 레플리카에 직접 연결하세요. 각 개별 레플리카에서 전체 AlwaysOn 텔레메트리가 수집되고, 각 서버의 호스트 기반 텔레메트리(CPU, 디스크, 메모리 등)도 함께 수집돼요.

instances:
  - dbm: true
    host: 'shopist-prod,1433'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    database_metrics:
      # If Availability Groups is enabled
      ao_metrics:
        enabled: true
      # If Failover Clustering is enabled
      fci_metrics:
        enabled: true

SQL Server Agent 작업 모니터링

{% alert level="info" %} SQL Server Agent 작업 모니터링을 활성화하려면 Datadog Agent가 [msdb] 데이터베이스에 접근할 수 있어야 해요. {% /alert %}

{% alert level="danger" %} SQL Server Agent 작업 모니터링은 Azure SQL Database에서 사용할 수 없어요. {% /alert %}

SQL Server Agent 작업 모니터링은 SQL Server 2016 이상 버전에서 지원돼요. Agent v7.57부터 Datadog Agent가 SQL Server Agent 작업 메트릭과 기록을 수집할 수 있어요. 이 기능을 활성화하려면 SQL Server 통합 설정 파일의 agent_jobs 섹션에서 enabled를 true로 설정하세요. collection_interval과 history_row_limit 필드는 선택 사항이에요.

instances:
  - dbm: true
    host: 'shopist-prod,1433'
    username: datadog
    password: '<PASSWORD>'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    agent_jobs:
      enabled: true
      collection_interval: 15
      history_row_limit: 10000

스키마 수집

{% alert level="danger" %} SQL Server 스키마 수집에는 Datadog Agent v7.56+와 SQL Server 2017 이상이 필요해요. {% /alert %}

이 기능을 활성화하려면 collect_schemas 옵션을 사용해요. 스키마는 Agent가 CONNECT 접근 권한이 있는 데이터베이스에서 수집돼요.

{% alert level="info" %} RDS 인스턴스에서 스키마 정보를 수집하려면 datadog 사용자에게 인스턴스의 각 데이터베이스에 대한 명시적 CONNECT 접근 권한을 부여해야 해요. 자세한 내용은 Agent 접근 권한 부여를 참고해요. {% /alert %}

각 논리적 데이터베이스를 지정하지 않으려면 database_autodiscovery 옵션을 사용해요. 자세한 내용은 sqlserver.d/conf.yaml 샘플을 참고해요.

init_config:
instances:
 # This instance detects every logical database automatically
  - dbm: true
        host: 'shopist-prod,1433'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    database_autodiscovery: true
    collect_schemas:
      enabled: true
    database_metrics:
      # Optional: enable metric collection for indexes
      index_usage_metrics:
        enabled: true
# This instance only collects schemas and index metrics from the `users` database
  - dbm: true
        host: 'shopist-prod,1433'
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    database: users
    collect_schemas:
      enabled: true
    database_metrics:
      # Optional: enable metric collection for indexes
      index_usage_metrics:
        enabled: true

참고: Agent v7.68 이하에서는 collect_schemas 대신 schemas_collection을 사용하세요.

하나의 Agent가 여러 호스트에 연결

단일 Agent 호스트가 여러 원격 데이터베이스 인스턴스에 연결하도록 설정하는 건 흔한 일이에요 (DBM의 Agent 설치 아키텍처 참조). 여러 호스트에 연결하려면 SQL Server 통합 설정에서 호스트마다 항목을 만들어요.

{% alert level="info" %} Datadog는 하나의 Agent로 최대 30개의 데이터베이스 인스턴스를 모니터링할 것을 권장해요. 벤치마크에 따르면 t4g.medium EC2 인스턴스(2 CPU, 4GB RAM)에서 실행 중인 Agent 하나가 RDS db.t3.medium 인스턴스(2 CPU, 4GB RAM) 30개를 성공적으로 모니터링할 수 있어요. {% /alert %}

init_config:
instances:
  - dbm: true
    host: 'example-service-primary.example-host.com,1433'
    username: datadog
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    password: 'ENC[datadog_user_database_password]'
    tags:
      - 'env:prod'
      - 'team:team-discovery'
      - 'service:example-service'
  - dbm: true
    host: 'example-service–replica-1.example-host.com,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    tags:
      - 'env:prod'
      - 'team:team-discovery'
      - 'service:example-service'
  - dbm: true
    host: 'example-service–replica-2.example-host.com,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    tags:
      - 'env:prod'
      - 'team:team-discovery'
      - 'service:example-service'
    [...]

커스텀 쿼리 실행

커스텀 메트릭을 수집하려면 custom_queries 옵션을 사용해요. 자세한 내용은 sqlserver.d/conf.yaml 샘플을 참고해요.

init_config:
instances:
  - dbm: true
    host: 'localhost,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    custom_queries:
    - query: SELECT age, salary, hours_worked, name FROM hr.employees;
      columns:
        - name: custom.employee_age
          type: gauge
        - name: custom.employee_salary
           type: gauge
        - name: custom.employee_hours
           type: count
        - name: name
           type: tag
      tags:
        - 'table:employees'

원격 프록시를 통한 호스트 연결

Agent가 원격 프록시를 통해 데이터베이스 호스트에 연결해야 한다면 모든 텔레메트리의 호스트네임이 데이터베이스 인스턴스가 아닌 프록시로 태그돼요. reported_hostname 옵션으로 Agent가 감지하는 호스트네임을 커스텀 오버라이드하세요.

init_config:
instances:
  - dbm: true
    host: 'localhost,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    reported_hostname: products-primary
  - dbm: true
    host: 'localhost,1433'
    connector: adodbapi
    adoprovider: MSOLEDBSQL
    username: datadog
    password: 'ENC[datadog_user_database_password]'
    reported_hostname: products-replica-1

포트 자동 발견

SQL Server Browser Service, Named Instances, 기타 서비스는 포트 번호를 자동으로 감지할 수 있어요. 연결 문자열에 포트 번호를 하드코딩하는 대신 이 기능을 사용할 수 있어요. 이 서비스 중 하나와 함께 Agent를 사용하려면 port 필드를 0으로 설정하세요.

예를 들어 Named Instance 설정:

init_config:
instances:
  - host: <hostname\instance name>
    port: 0

더 알아보기 (Learn more)

추가로 도움이 되는 문서, 링크, 아티클: