ansibleでdatadogを導入する

2016.09.05

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

サクッと導入してみます。小ネタです。

以下の公式ページを参考にしました。(Datadogにログインすると見れます)

https://app.datadoghq.com/account/settings#agent/ansible

1. ローカルにDatadog公式Playbookをダウンロードする

$ ansible-galaxy install Datadog.datadog -p ansible/roles
- downloading role 'datadog', owned by Datadog
- downloading role from https://github.com/DataDog/ansible-datadog/archive/1.0.0-rc3.tar.gz
- extracting Datadog.datadog to ansible/roles/Datadog.datadog
- Datadog.datadog was installed successfully

2. DatadogのWebサイトでAPIキーを発行する

Datadogのwebサイトで行います。

datadog-Screen_Shot_2016-09-05_at_20_48_33-install

3. 呼び出し元のPlaybookを修正する

datadog-agentのインストールには管理権限が必要なので、become: yesを忘れないようにします。

- { role: Datadog.datadog, datadog_api_key: "0123456789abcdefg", when: rails_env == 'production', become: yes }

4. 必要に応じてDatadogに送るデータの設定をする

READMEに設定例があります。

https://github.com/DataDog/ansible-datadog/blob/master/README.md

vars:
  rails_env: "{{ lookup('env', 'RAILS_ENV') }}"
  datadog_config:
    collect_ec2_tags: yes
    collect_security_groups: yes
  datadog_checks:
    process:
      init_config:
      instances:
        - name: ssh
          search_string: ['ssh', 'sshd']
        - name: application
          search_string: ['puma']
          exact_match: false
    nginx:
      init_config:
      instances:
        - nginx_status_url: http://localhost/nginx_status/

ここでは、pumaとsshdのプロセス監視、及びnginxのメトリックをDatadogに送っています。 NginxはDatadog側でのIntegration設定が必要です。

nginxの設定はこちら http://docs.datadoghq.com/ja/integrations/nginx/

まとめ

サクッとDatadogの導入ができました。
今後もEC2構成の変更に備えて、メンテナス性の良いPlaybookに保っていきたいです。