Datadog agentの設定方法【cloudpack 大阪 BLOG】

Datadog agentはインストールするだけで、自動的にCPUやメモリなどのメトリクスを取得してくれますが、
少し手を加えることでもっと沢山の情報をDatadogに集めて、”見る”事が出来ます。今回はその設定方法を記載します。

1. インストール

一発でインストール・自動起動設定などが出来ます。超簡単です。

API_KEYを埋め込む必要があるため、Datadog管理画面([Integrations]-[Agent])より自OSを選択の上でコマンドラインをコピーして下さい。

DD_API_KEY=ABCDEFGHIJKLMNOPQRSTU bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/install_agent.sh)"

2. 設定ファイル確認

本題の設定方法です。
インストールすると''/etc/dd-agent/''というディレクトリができるので、 /etc/dd-agent/conf.dに移動します。

cd /etc/dd-agent/conf.d

すると以下のサンプルファイルが生成されています。

activemq.yaml.example
activemq_58.yaml.example
activemq_xml.yaml.example
agent_metrics.yaml.default
apache.yaml.example
btrfs.yaml.example
cacti.yaml.example
cassandra.yaml.example
couch.yaml.example
couchbase.yaml.example
directory.yaml.example
disk.yaml.default
docker.yaml.example
elastic.yaml.example
etcd.yaml.example
fluentd.yaml.example
gearmand.yaml.example
go_expvar.yaml.example
gunicorn.yaml.example
haproxy.yaml.example
hdfs.yaml.example
http_check.yaml.example
iis.yaml.example
jenkins.yaml.example
jmx.yaml.example
kafka.yaml.example
kafka_consumer.yaml.example
kyototycoon.yaml.example
lighttpd.yaml.example
marathon.yaml.example
mcache.yaml.example
mesos.yaml.example
mesos_master.yaml.example
mesos_slave.yaml.example
mongo.yaml.example
mysql.yaml.example
nagios.yaml.example
network.yaml.default
nginx.yaml.example
ntp.yaml.default
pgbouncer.yaml.example
php_fpm.yaml.example
postfix.yaml.example
postgres.yaml.example
process.yaml.example
rabbitmq.yaml.example
redisdb.yaml.example
riak.yaml.example
riakcs.yaml.example
snmp.yaml.example
solr.yaml.example
sqlserver.yaml.example
ssh_check.yaml.example
supervisord.yaml.example
system_core.yaml.example
system_swap.yaml.example
tcp_check.yaml.example
teamcity.yaml.example
tokumx.yaml.example
tomcat.yaml.example
varnish.yaml.example
vsphere.yaml.example
win32_event_log.yaml.example
windows_service.yaml.example
wmi_check.yaml.example
zk.yaml.example

それでは、実際の設定をしてみましょう。

3. 設定の有効化

基本的には/etc/dd-agent/conf.dに移動し有効化したいファイルをリネームし、中身を修正する。だけです。

cd /etc/dd-agent/conf.d
mv apache.yaml.example apache.yaml
vi apache.yaml

4. 反映

最後はいつものプロセスを再起動して完了です。

service datadog-agent restart

正常に値を取得出来ているか確認しましょう

service datadog-agent info

5. 以下は有用そうなものをピックアップしています。

  • 注意点: yamlファイルを修正する際にTabは使わず半角スペースを使って下さい。

tcp_check.yaml

■ 内容:ポート監視
■ 修正方法:

  • name: 対象の名前を定義(httpd/tomcatなど)
  • host: 接続先を定義(RDSなどの外部も可)
  • port: 接続先のPortを定義
  • timeout: タイムアウト値を定義
- name: httpd
   host: localhost
   port: 80
   timeout: 1

process.yaml

■ 内容:プロセス監視
■ 修正方法:

  • name: 対象の名前を定義(httpd/tomcatなど)
  • search_string:: 対象のプロセス名を定義、部分一致、複数指定可
  • critical: 以下の例は1以下 or 7以上でCritical
  • warning: 以下の例は2以下 or 6以上でWarning
  - name: ssh
    search_string: ['ssh', 'sshd']
    thresholds:
      critical: [1, 7]
      warning: [3, 5]

apache.yaml

■ 内容:Apacheの状態取得(server-status)
■ 修正方法:

  • 以下のようにmvする
  • (httpd.conf) mod_status がインストールされ、そのモジュールがExtendedStatus付きで有効化されている
  • (httpd.conf) localhostからserver-statusが参照出来るようにする
mv /etc/dd-agent/conf.d/apache.yaml.example /etc/dd-agent/conf.d/apache.yaml

■ 取得できる値

apache.net.bytes
apache.net.bytes_per_s
apache.net.hits
apache.net.request_per_s
apache.performance.busy_workers
apache.performance.cpu_load
apache.performance.idle_workers
apache.performance.uptime

http_check.yaml

■ 内容:URL監視
■ 修正方法:

  • name: 対象の名前を定義(Webサイト名など)
  • url: 監視先URLを定義
  • timeout: これを超えると遅延している。という値を定義(秒)
  • 補足
  • Basic認証やらオレオレSSL突破など色々オプション有り
- name: www.example.com
  url: http://www.example.com
  timeout: 4

mysql.yaml

■ 内容:MySQLの状態取得(AWS-RDSでも有用)
■ 修正方法:

  • server: localhost or AWS-RDSの場合はエンドポイント
  • user: MySQLのユーザ名
  • pass: MySQLのパスワード
  • port: MySQLのポートを定義(通常は3306)
  • AWS-RDSの場合は以下も設定(CloudWatchで取得した値を紐付けされる)
  • dbinstanceidentifier:RDSのdbinstanceidentifier
- server: mysqlrds.blah.us-east1-rds.amazonaws.com
  user: my_username
  pass: my_password
  port: 3306
  tags: 
    - dbinstanceidentifier:my_own_instance

■ 取得できる値

mysql.innodb.buffer_pool_size
mysql.innodb.data_reads
mysql.innodb.data_writes
mysql.innodb.os_log_fsyncs
mysql.net.connections
mysql.net.max_connections
mysql.performance.created_tmp_disk_tables
mysql.performance.open_files
mysql.performance.queries
mysql.performance.questions
mysql.performance.slow_queries
mysql.performance.table_locks_waited
mysql.performance.threads_connected

mcache.yaml

■ 内容:Memcachedのパフォーマンス取得(AWS-Memcachedでも有用)
■ 修正方法:

- url: localhost

■ 取得できる値

memcache.bytes
memcache.bytes_read
memcache.bytes_written
memcache.cmd_get
memcache.cmd_set
memcache.connection_structures
memcache.curr_connections
memcache.curr_items
memcache.evictions
memcache.get_hits
memcache.get_misses
memcache.limit_maxbytes
memcache.pointer_size
memcache.rusage_system
memcache.rusage_user
memcache.threads
memcache.total_connections
memcache.total_items

redisdb.yaml

■ 内容:Redisのパフォーマンス取得(AWS-Memcachedでも有用)
■ 修正方法:

- host: localhost

■ 取得できる値

redis.aof.buffer_length
redis.aof.last_rewrite_time
redis.aof.rewrite
redis.aof.size
redis.clients.biggest_input_buf
redis.clients.blocked
redis.clients.longest_output_list
redis.cpu.sys
redis.cpu.sys_children
redis.cpu.user
redis.cpu.user_children
redis.keys.evicted
redis.keys.expired
redis.mem.fragmentation_ratio
redis.mem.lua
redis.mem.peak
redis.mem.rss
redis.mem.used
redis.net.clients
redis.net.rejected
redis.net.slaves
redis.perf.latest_fork_usec
redis.pubsub.channels
redis.pubsub.patterns
redis.rdb.bgsave
redis.rdb.changes_since_last
redis.rdb.last_bgsave_time
redis.replication.last_io_seconds_ago
redis.replication.sync
redis.replication.sync_left_bytes
redis.stats.keyspace_hits
redis.stats.keyspace_misses

以下は検証中

Let's DD Life!!