Gunicorn

Supported OS Linux Mac OS

통합 버전2.7.0

Gunicorn 대시보드

개요

Datadog 에이전트는 Gunicorn에 대한 하나의 주요 메트릭, 즉 실행 중인 작업자 프로세스의 수를 수집합니다. 또한 Gunicorn이 실행 중인지 여부에 대한 서비스 점검 정보를 전송합니다.

Gunicorn 자체에서 DogStatsD를 사용하여 다음을 포함한 메트릭을 추가로 제공할 수 있습니다:

  • 총 요청 비율
  • 상태 코드별 요청 비율(2xx, 3xx, 4xx, 5xx)
  • 요청 기간(평균, 중앙값, 최대, 95번째 백분위수 등)
  • 로그 수준(심각, 오류, 경고, 예외)별 로그 메시지 비율

설정

설치

Datadog 에이전트의 Gunicorn 점검은 Datadog 에이전트 패키지에 포함되어 있으므로 Gunicorn 서버에 아무 것도 설치할 필요가 없습니다.

Gunicorn 점검을 사용하려면 Gunicorn 앱의 파이썬(Python) 환경에 setproctitle 패키지가 있어야 합니다. 없는 경우 Datadog 에이전트는 gunicorn 마스터 프로세스를 찾을 수 없다고 보고합니다(따라서 작업자를 찾을 수 없음). gunicorn.workers 메트릭을 수집하려면 앱의 파이썬 환경에 setproctitle 패키지를 설치하세요.

설정

에이전트의 설정 디렉토리 루트의 conf.d/ 폴더에 있는 gunicorn.d/conf.yaml 파일을 수정하여 Gunicorn [메트릭](#메트릭 수집) 및 [로그](#로그 수집) 수집을 시작하세요. 사용 가능한 모든 설정 옵션은 gunicorn.yaml 샘플을 참조하세요.

메트릭 수집

Gunicorn을 DogStatsD에 연결
  1. 버전 19.1부터 Gunicorn은 DogStatsD과 마찬가지로 StatsD 프로토콜을 구현하는 데몬에 메트릭을 전송하는 옵션6을 제공합니다. 다른 많은 Gunicorn 옵션과 같이 CLI에서 gunicorn(--statsd-host)로 전달하거나 앱의 설정 파일(statsd_host)에 설정할 수 있습니다. 모든 Gunicorn 메트릭을 수집하려면 앱을 설정하여 "localhost:8125"에서 DogStatsD로 메트릭을 전송하합니다. 그런 다음 앱을 다시 시작하세요.

  2. gunicorn.d/conf.yaml 파일에 설정 블록을 추가하여 Gunicorn 메트릭 수집을 시작하세요.

init_config:

instances:
    ## @param proc_name - string - required
    ## The name of the gunicorn process. For the following gunicorn server:
    ##
    ## gunicorn --name <WEB_APP_NAME> <WEB_APP_CONFIG>.ini
    ##
    ## the name is `<WEB_APP_NAME>`
  - proc_name: <YOUR_APP_NAME>
  1. 에이전트를 다시 시작하여 메트릭을 Datadog로 전송하기 시작합니다.

로그 수집

에이전트 버전 6.0 이상에서 사용 가능

  1. Datadog 에이전트에서 로그 수집은 기본적으로 사용하지 않도록 설정되어 있습니다. datadog.yaml파일에서 로그 수집을 사용하도록 설정합니다.

    logs_enabled: true
    
  2. 다음 명령을 사용하여 액세스 로그 파일의 경로를 설정합니다. --access-logfile <MY_FILE_PATH>

  3. 다음 명령을 사용하여 오류 로그 파일의 경로를 설정합니다. --error-logfile FILE, --log-file <MY_FILE_PATH>

  4. 이 설정 블록을 gunicorn.d/conf.yaml 파일에 추가하여 Gunicorn 로그 수집을 시작하세요.

    logs:
      - type: file
        path: /var/log/gunicorn/access.log
        service: "<MY_SERVICE>"
        source: gunicorn
    
      - type: file
        path: /var/log/gunicorn/error.log
        service: "<MY_SERVICE>"
        source: gunicorn
        log_processing_rules:
          - type: multi_line
            name: log_start_with_date
            pattern: \[\d{4}-\d{2}-\d{2}
    

    servicepath 파라미터 값을 변경하고 환경에 맞게 설정합니다. 사용 가능한 모든 설정 옵션은 gunicorn.yaml 샘플을 참조하세요.

  5. 에이전트를 재시작합니다.

검증

에이전트의 상태 하위 명령을 실행하고 점검 섹션에서 gunicorn을 찾습니다.

상태가 OK가 아닌 경우 트러블슈팅 섹션을 참조하세요.

netstat을 사용하여 Gunicorn이 자체 메트릭도 전송하는지 확인합니다:

sudo netstat -nup | grep "127.0.0.1:8125.*ESTABLISHED"
udp 0 0 127.0.0.1:38374 127.0.0.1:8125 ESTABLISHED 15500/gunicorn: mas

수집한 데이터

메트릭

gunicorn.log.critical
(rate)
The rate of logged critical statements.
Shown as occurrence
gunicorn.log.error
(rate)
The rate of logged errors.
Shown as occurrence
gunicorn.log.exception
(rate)
The rate of logged exceptions.
Shown as occurrence
gunicorn.log.warning
(rate)
The rate of logged warnings.
Shown as occurrence
gunicorn.request.duration.95percentile
(gauge)
The 95th percentile of request duration time.
Shown as millisecond
gunicorn.request.duration.avg
(gauge)
The average request duration time.
Shown as millisecond
gunicorn.request.duration.count
(rate)
The rate of requests received.
Shown as request
gunicorn.request.duration.max
(gauge)
The maximum request duration time.
Shown as millisecond
gunicorn.request.duration.median
(gauge)
The median request duration time.
Shown as millisecond
gunicorn.request.status.100
(rate)
The rate of requests that generate responses with a 100 status code.
Shown as request
gunicorn.request.status.101
(rate)
The rate of requests that generate responses with a 101 status code.
Shown as request
gunicorn.request.status.102
(rate)
The rate of requests that generate responses with a 102 status code.
Shown as request
gunicorn.request.status.200
(rate)
The rate of requests that generate responses with a 200 status code.
Shown as request
gunicorn.request.status.201
(rate)
The rate of requests that generate responses with a 201 status code.
Shown as request
gunicorn.request.status.202
(rate)
The rate of requests that generate responses with a 202 status code.
Shown as request
gunicorn.request.status.203
(rate)
The rate of requests that generate responses with a 203 status code.
Shown as request
gunicorn.request.status.204
(rate)
The rate of requests that generate responses with a 204 status code.
Shown as request
gunicorn.request.status.205
(rate)
The rate of requests that generate responses with a 205 status code.
Shown as request
gunicorn.request.status.206
(rate)
The rate of requests that generate responses with a 206 status code.
Shown as request
gunicorn.request.status.207
(rate)
The rate of requests that generate responses with a 207 status code.
Shown as request
gunicorn.request.status.208
(rate)
The rate of requests that generate responses with a 208 status code.
Shown as request
gunicorn.request.status.226
(rate)
The rate of requests that generate responses with a 226 status code.
Shown as request
gunicorn.request.status.300
(rate)
The rate of requests that generate responses with a 300 status code.
Shown as request
gunicorn.request.status.301
(rate)
The rate of requests that generate responses with a 301 status code.
Shown as request
gunicorn.request.status.302
(rate)
The rate of requests that generate responses with a 302 status code.
Shown as request
gunicorn.request.status.303
(rate)
The rate of requests that generate responses with a 303 status code.
Shown as request
gunicorn.request.status.304
(rate)
The rate of requests that generate responses with a 304 status code.
Shown as request
gunicorn.request.status.305
(rate)
The rate of requests that generate responses with a 305 status code.
Shown as request
gunicorn.request.status.307
(rate)
The rate of requests that generate responses with a 307 status code.
Shown as request
gunicorn.request.status.308
(rate)
The rate of requests that generate responses with a 308 status code.
Shown as request
gunicorn.request.status.400
(rate)
The rate of requests that generate responses with a 400 status code.
Shown as request
gunicorn.request.status.401
(rate)
The rate of requests that generate responses with a 401 status code.
Shown as request
gunicorn.request.status.402
(rate)
The rate of requests that generate responses with a 402 status code.
Shown as request
gunicorn.request.status.403
(rate)
The rate of requests that generate responses with a 403 status code.
Shown as request
gunicorn.request.status.404
(rate)
The rate of requests that generate responses with a 404 status code.
Shown as request
gunicorn.request.status.405
(rate)
The rate of requests that generate responses with a 405 status code.
Shown as request
gunicorn.request.status.406
(rate)
The rate of requests that generate responses with a 406 status code.
Shown as request
gunicorn.request.status.407
(rate)
The rate of requests that generate responses with a 407 status code.
Shown as request
gunicorn.request.status.408
(rate)
The rate of requests that generate responses with a 408 status code.
Shown as request
gunicorn.request.status.409
(rate)
The rate of requests that generate responses with a 409 status code.
Shown as request
gunicorn.request.status.410
(rate)
The rate of requests that generate responses with a 410 status code.
Shown as request
gunicorn.request.status.411
(rate)
The rate of requests that generate responses with a 411 status code.
Shown as request
gunicorn.request.status.412
(rate)
The rate of requests that generate responses with a 412 status code.
Shown as request
gunicorn.request.status.413
(rate)
The rate of requests that generate responses with a 413 status code.
Shown as request
gunicorn.request.status.414
(rate)
The rate of requests that generate responses with a 414 status code.
Shown as request
gunicorn.request.status.415
(rate)
The rate of requests that generate responses with a 415 status code.
Shown as request
gunicorn.request.status.416
(rate)
The rate of requests that generate responses with a 416 status code.
Shown as request
gunicorn.request.status.417
(rate)
The rate of requests that generate responses with a 417 status code.
Shown as request
gunicorn.request.status.419
(rate)
The rate of requests that generate responses with a 419 status code.
Shown as request
gunicorn.request.status.421
(rate)
The rate of requests that generate responses with a 421 status code.
Shown as request
gunicorn.request.status.422
(rate)
The rate of requests that generate responses with a 422 status code.
Shown as request
gunicorn.request.status.423
(rate)
The rate of requests that generate responses with a 423 status code.
Shown as request
gunicorn.request.status.424
(rate)
The rate of requests that generate responses with a 424 status code.
Shown as request
gunicorn.request.status.426
(rate)
The rate of requests that generate responses with a 426 status code.
Shown as request
gunicorn.request.status.428
(rate)
The rate of requests that generate responses with a 428 status code.
Shown as request
gunicorn.request.status.429
(rate)
The rate of requests that generate responses with a 429 status code.
Shown as request
gunicorn.request.status.431
(rate)
The rate of requests that generate responses with a 431 status code.
Shown as request
gunicorn.request.status.451
(rate)
The rate of requests that generate responses with a 451 status code.
Shown as request
gunicorn.request.status.500
(rate)
The rate of requests that generate responses with a 500 status code.
Shown as request
gunicorn.request.status.501
(rate)
The rate of requests that generate responses with a 501 status code.
Shown as request
gunicorn.request.status.502
(rate)
The rate of requests that generate responses with a 502 status code.
Shown as request
gunicorn.request.status.503
(rate)
The rate of requests that generate responses with a 503 status code.
Shown as request
gunicorn.request.status.504
(rate)
The rate of requests that generate responses with a 504 status code.
Shown as request
gunicorn.request.status.505
(rate)
The rate of requests that generate responses with a 505 status code.
Shown as request
gunicorn.request.status.506
(rate)
The rate of requests that generate responses with a 506 status code.
Shown as request
gunicorn.request.status.507
(rate)
The rate of requests that generate responses with a 507 status code.
Shown as request
gunicorn.request.status.508
(rate)
The rate of requests that generate responses with a 508 status code.
Shown as request
gunicorn.request.status.510
(rate)
The rate of requests that generate responses with a 510 status code.
Shown as request
gunicorn.request.status.511
(rate)
The rate of requests that generate responses with a 511 status code.
Shown as request
gunicorn.request.status.512
(rate)
The rate of requests that generate responses with a 512 status code.
Shown as request
gunicorn.requests
(rate)
The rate of requests received.
Shown as request
gunicorn.workers
(gauge)
The number of workers tagged by state (idle or working).
Shown as worker

이벤트

Gunicorn 점검은 이벤트를 포함하지 않습니다.

서비스 점검

gunicorn.is_running
Returns CRITICAL if the Agent is unable to find the Gunicorn master process. Returns OK otherwise.
Statuses: ok, critical

트러블슈팅

에이전트가 Gunicorn 프로세스를 찾을 수 없습니다.

  Checks
  ======

    gunicorn (5.12.1)
    -----------------
      - instance #0 [ERROR]: 'Found no master process with name: gunicorn: master [my_web_app]'
      - Collected 0 metrics, 0 events & 1 service check
      - Dependencies:
          - psutil: 4.4.1

Gunicorn이 실제로 실행되고 있지 않거나 앱의 파이썬(Python) 환경에 setproctitle 패키지가 설치되어 있지 않습니다.

setproctitle이 설치되어 있지 않으면 프로세스 표에 Gunicorn이 다음과 같이 표시됩니다.

$ ps -ef | grep gunicorn
ubuntu   18013 16695  2 20:23 pts/0    00:00:00 /usr/bin/python /usr/bin/gunicorn --config test-app-config.py gunicorn-test:app
ubuntu   18018 18013  0 20:23 pts/0    00:00:00 /usr/bin/python /usr/bin/gunicorn --config test-app-config.py gunicorn-test:app
ubuntu   18019 18013  0 20:23 pts/0    00:00:00 /usr/bin/python /usr/bin/gunicorn --config test-app-config.py gunicorn-test:app

설치되어_있는_경우 gunicorn 프로세스가 Datadog 에이전트에서 예상한 형식대로 표시됩니다.

$ ps -ef | grep gunicorn
ubuntu   18457 16695  5 20:26 pts/0    00:00:00 gunicorn: master [my_app]
ubuntu   18462 18457  0 20:26 pts/0    00:00:00 gunicorn: worker [my_app]
ubuntu   18463 18457  0 20:26 pts/0    00:00:00 gunicorn: worker [my_app]

참고 자료