Datadogを使っての監視(Mac + Raspberry Pi)

概要

監視SaaSであるDatadogの無料枠を利用して、自宅にあるMacやRaspberry Piを監視してみる

Datadogとは

サーバー/クラウドの監視SaaSで、ざっと以下の事が出来る

  • CPU/Memory/Disk/NWのメトリクス収集+可視化
  • アプリケーション監視も可能。Java/Python/Go等など
  • NginxやRDBといったミドルウェアにも対応
  • AWS等各種クラウドサービスも対応

無料枠の制限としては以下の通り

  • 5ホスト
  • データ保存期間は1日
  • アラートは送れない

アカウント作成

https://www.datadoghq.com から登録 利用環境など聞かれるが、オプションなので特に指定しなくても問題なし

Agentのインストール(Mac)

Agent選択画面からMac OS を選択すると、丁寧なマニュアルが表示されるので、まずは下記コマンドを実行

DD_API_KEY=自分のAPI-KEY bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/osx/install.sh)"

実行結果:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4974  100  4974    0     0  18882      0 --:--:-- --:--:-- --:--:-- 18912

* Downloading datadog-agent
######################################################################## 100.0%

* Installing datadog-agent, you might be asked for your sudo password...
Password:

    - Mounting the DMG installer...

    - Unpacking and copying files (this usually takes about a minute) ...

    - Unmounting the DMG installer ...

* Restarting the Agent...



Your Agent is running properly. It will continue to run in the
background and submit metrics to Datadog.

You can check the agent status using the "datadog-agent status" command
or by opening the webui using the "datadog-agent launch-gui" command.

If you ever want to stop the Agent, please use the Datadog Agent App or
the launchctl command. It will start automatically at login.

インストールが完了すると、自動的に監視が開始される

ログオン時に起動する場合は、追加で下記のコマンドを実行する

sudo cp '/opt/datadog-agent/etc/com.datadoghq.agent.plist.example' /Library/LaunchDaemons/com.datadoghq.agent.plist
sudo launchctl load -w /Library/LaunchDaemons/com.datadoghq.agent.plist

細かい設定等は設定ファイルを直接編集しても良いし、AgentにWebGUIが提供されているのでそっちでもOK

Agentのインストール(Raspberry Pi)

Raspberry Piの場合はFrom Sourceの手順でインストールを行う (Ubuntuでも良いかもしれない)

sysstatがインストールされていないとエラーになるので、事前にaptでインストールしておく

apt install sysstat

以下のコマンドを実行してインストール開始 (CPUが貧弱なのでビルドに相当時間がかかるのはご愛敬......平気で1時間以上かかる)

DD_API_KEY=自分のAPI−KEY sh -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/setup_agent.sh)"

実行結果:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24430  100 24430    0     0  40817      0 --:--:-- --:--:-- --:--:-- 40921
Checking that logfile is writable
OK
Checking installation requirements
* uname Linux
* sysstat is installed
* python found, using `python2.7`
* downloader found, using `curl -k -L -o`
* sed found, using `sed`


Installing Datadog Agent 5.32.2
Installation is logged at /root/.datadog-agent/ddagent-install.log

* Setting up a python virtual env
Done
* Activating the virtual env
Done
* Setting up setuptools
Done
* Setting up pip
Done
* Installing requirements
Done
* Downloading agent version 5.32.2 from GitHub (~5 MB)
Done
* Uncompressing tarball
Done
* Downloading integrations from GitHub
Done
* Uncompressing tarball
Done
* Setting up integrations
Done
* Trying to install optional requirements
Done
* Trying to install JMXFetch jarfile from https://dl.bintray.com/datadog/datadog-maven/com/datadoghq/jmxfetch
Done
* Setting up a datadog.conf generic configuration file
Done
* Setting up init scripts
Done
* Setting up supervisord
Done
* Starting the agent
    - supervisord started

Your Agent has started up for the first time. We're currently verifying
that data is being submitted. You should see your Agent show up in Datadog
shortly at:

      https://app.datadoghq.com/infrastructure

* Waiting 30s to see if the Agent submits metrics correctly
..............................
* Testing if the Agent is submitting metrics
....................
Success! Your Agent is functioning properly, and will continue to run
in the foreground. To stop it, simply press CTRL-C. To start it back
up again in the foreground, run the following command from the /root/.datadog-agent directory:

    bin/agent

フォアグランドで起動した状態になるので、ctrl+cで一度止める

自動起動のためにSystemdでサービス化

/etc/systemd/system/datadog.service

[Unit]
Description = datadog Daemon

[Service]
ExecStart = /root/.datadog-agent/bin/agent
Restart = always
Type = simple

[Install]
WantedBy = multi-user.target
# 設定読み込み
systemctl daemon-reload
# 自動起動を有効に
systemctl enable datadog
# datadogを起動
systemctl start datadog

ダッシュボードの作成

Datadogの画面から色んな部品を選んで画面を作成

参考

Built with Hugo
Theme Stack designed by Jimmy