Supported OS Linux Mac OS

インテグレーションバージョン2.7.0

Gunicorn のダッシュボード

概要

Datadog Agent は、Gunicorn の主要なメトリクスとして、実行中のワーカープロセス数のみを収集します。サービスチェックについても、Gunicorn が実行中かどうかのみを送信します。

Gunicorn 自身は、これ以外にも以下のようなメトリクスを DogStatsD を使用して提供しています。

  • 合計リクエスト率
  • ステータスコード (2xx、3xx、4xx、5xx) 別のリクエスト率
  • リクエスト処理時間 (平均値、中央値、最大値、95 パーセンタイルなど)
  • ログレベル (重大、エラー、警告、例外) 別のログメッセージ率

セットアップ

インストール

Datadog Agent の Gunicorn チェックは Datadog Agent パッケージに含まれています。Gunicorn サーバーに追加でインストールする必要はありません。

Gunicorn チェックでは、Gunicorn アプリの Python 環境に setproctitle パッケージが含まれている必要があります。これがないと、Datadog Agent は常に gunicorn マスタープロセスが見つからない (したがって、ワーカーも見つからない) と報告します。gunicorn.workers メトリクスを収集する場合は、アプリの Python 環境に setproctitle パッケージをインストールしてください。

構成

Gunicorn のメトリクスログの収集を開始するには、Agent の構成ディレクトリのルートにある conf.d/ フォルダーの gunicorn.d/conf.yaml ファイルを編集します。 使用可能なすべての構成オプションの詳細については、サンプル gunicorn.yaml を参照してください。

Metric collection

Gunicorn の DogStatsD への接続
  1. バージョン 19.1 以降の Gunicorn では、DogStatsD のような StatsD プロトコルを実装するデーモンにメトリクスを送信するオプションが提供されるようになりました。Gunicorn の多くのオプションと同様に、このオプションは CLI (--statsd-host) で gunicorn に渡すか、アプリの構成ファイル (statsd_host) で設定できます。すべての Gunicorn メトリクスを収集するには、"localhost:8125"DogStatsD へメトリクスを送信するようにアプリを構成し、アプリを再起動します。

  2. Gunicorn のメトリクスの収集を開始するには、gunicorn.d/conf.yaml ファイルに次の構成ブロックを追加します。

init_config:

instances:
    ## @param proc_name - 文字列 - 必須
    ## gunicorn プロセスの名前。次の gunicorn サーバーの場合:
    ##
    ## gunicorn --name <WEB_APP_NAME> <WEB_APP_CONFIG>.ini
    ##
    ## 名前は `<WEB_APP_NAME>` です
  - proc_name: <YOUR_APP_NAME>
  1. Agent を再起動すると、Datadog への Gunicorn メトリクスの送信が開始されます。

ログ収集

Agent バージョン 6.0 以降で利用可能

  1. Datadog Agent で、ログの収集はデフォルトで無効になっています。以下のように、datadog.yaml ファイルでこれを有効にします。

    logs_enabled: true
    
  2. アクセスログファイルのパスを構成する場合は、次のコマンドを使用します。 --access-logfile <MY_FILE_PATH>

  3. エラーログファイルのパスを構成する場合は、次のコマンドを使用します。 --error-logfile FILE, --log-file <MY_FILE_PATH>

  4. Gunicorn のログの収集を開始するには、次の構成ブロックを gunicorn.d/conf.yaml ファイルに追加します。

    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}
    

    service パラメーターと path パラメーターの値を変更し、環境に合わせて構成します。使用可能なすべてのコンフィギュレーションオプションについては、サンプル gunicorn.yaml を参照してください。

  5. Agent を再起動します

検証

Agent の status サブコマンドを実行し、Checks セクションで 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
Agent が Gunicorn マスタープロセスを見つけられない場合は、CRITICAL を返します。それ以外の場合は、OK を返します。
Statuses: ok, クリティカル

トラブルシューティング

Agent が 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

インストールされている場合は、Datadog Agent が想定する形式で gunicorn プロセスが表示されます。

$ 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]

その他の参考資料

PREVIEWING: antoine.dussault/service-representation-ga-docs-us1