LoginSignup
0
0

More than 1 year has passed since last update.

DatadogでEC2内部のログを監視する

Posted at

What's This

DatadogでEC2内部のログを監視対象にして、任意の文字列を検知したらアラート、という
仕組みを実装したのでメモです。

EC2設定

# 適当なディレクトリを作成する
sudo mkdir /etc/datadog-agent/conf.d/error_log.d/

# そのディレクトリ配下にconf作成し、編集
sudo vi /etc/datadog-agent/conf.d/error_log.d/conf.yaml

init_config:

instances:

logs:
  - type: file
       # 拾いたいファイル対象を記載する。
    path: /var/www/html/error*
       # DD logs上で表示するサービス名を記載(定義)する。
    service: error_log
       # DD logs上で表示するサービス名を記載(定義)する。
    source: error_log
    log_processing_rules:
      - type: include_at_match
        name: include_datadog_messages
        # 拾いたい文字列を記載する。
        pattern: error|Error|

# datadog.yamlを編集
sudo vi /etc/datadog-agent/datadog.yaml

# logs_enabled というパラメータを true にする
logs_enabled:true

# 再起動
sudo systemctl restart datadog-agent

# チェック
sudo datadog-agent status

Getting the status from the agent.

==========
Logs Agent
==========

    Reliable: Sending compressed logs in HTTPS to agent-http-intake.logs.datadoghq.com on port 443
    BytesSent: 0
    EncodedBytesSent: 0
    LogsProcessed: 0
    LogsSent: 0

  error_log
  -------------------
    - Type: file
      Path: /var/www/html/error*
      Status: OK
            # ここの** filesで、対象のファイル数がいくつかわかる。
        52 files tailed out of 52 files matching
      Inputs:
        /var/www/html/error2022-XX-XX.log
            〜省略〜(対象の52ファイルが羅列される)
      BytesRead: 0
      Average Latency (ms): 0
      24h Average Latency (ms): 0
      Peak Latency (ms): 0
      24h Peak Latency (ms): 0

Monitor設定

算定式的には、以下の感じ。
上記で設定したSerivce名を、クエリに算入する。

Service:error_log error(検知したい文字列を明示的に書く)(書かなくてもOKかもしれませんが)

実際に、以下でログを流し込むと、検知しました。(モニタークエリは若干上記で設定したものとは異なっています)

vi /var/www/html/error*
error

スクリーンショット 2022-03-23 18.27.02.png

Reference

https://docs.datadoghq.com/ja/getting_started/logs/
・社内有識者

参考になりました。ありがとうございます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0