datadog ec2 log collection

마가·2023년 1월 31일
0

trial-error

목록 보기
16/19

ec2에 접속후 aws agent 설치를 위해 커맨드 입력

DD_API_KEY=<키> DD_SITE="us3.datadoghq.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script_agent7.sh)"
사실 이거 치는게 전부
여기서 키를 입력하지 않고 나중에 yaml파일에서 입력하는 방법도 있다.
us3.datadoghq.com 는 내가 쓰는게 us3이라서 그렇고, 자기가 쓰는 리전을 입력.

* Adding your API key to the Datadog Agent configuration: /etc/datadog-agent/datadog.yaml


* Setting SITE in the Datadog Agent configuration: /etc/datadog-agent/datadog.yaml

/usr/bin/systemctl
* Starting the Datadog Agent...

  Your Datadog Agent is running and functioning properly.
  It will continue to run in the background and submit metrics to Datadog.
  If you ever want to stop the Datadog Agent, run:

      sudo systemctl stop datadog-agent

  And to run it again run:

      sudo systemctl start datadog-agent

이런 로그가 뜬다.

/etc/datadog-agent/datadog.yaml 파일에 apikey가 입력되었는지 확인
해당 파일에서 logs_enabled 를 true로 변경
이제 로그 에이전트도 같이 활성화되었다.

/etc/datadog-agent/conf.d/ 로 이동
수 많은 앱 중에 내가 만든 로그가 어떤 앱으로 집계되는지 생각하고 해당 폴더로 이동.
본인은 nodejs batch 로그를 남기고 싶었으나, 그런게 없어서 nginx.d/ 로 이동.
conf.yaml.example이 있을텐데 지워도 되고 냅둬도 됨.

logs:
  - type: file
    path: /home/ubuntu/.pm2/logs/runner-1-error.log
    source: runner
    service: runner
  - type: file
    path: /home/ubuntu/.pm2/logs/runner-1-out.log
    source: runner
    service: runner

이렇게 입력하면 datadog 에서 runner로 로그를 받음.

이후 sudo systemctl restart datadog-agent 입력
sudo datadog-agent status 입력해서

==========
Logs Agent
==========
    Reliable: Sending compressed logs in HTTPS to agent-http-intake.logs.us3.datadoghq.com on port 443
    BytesSent: 21949
    EncodedBytesSent: 2643
    LogsProcessed: 124
    LogsSent: 85

  nginx
  -----
    - Type: file
      Path: /home/ubuntu/.pm2/logs/runner-1-error.log
      Service: runner
      Source: runner
      Status: OK

가 뜨면 데이터독에서 로그가 보인다.

참고
agent설치 https://us3.datadoghq.com/account/settings#agent/aws
로그설정 : https://docs.datadoghq.com/agent/logs/?tab=tailfiles

profile
마음 가는 길은 죽 곧은 길

0개의 댓글