Skip to content

Instantly share code, notes, and snippets.

@ryanmaclean
Last active May 11, 2023 12:52
Show Gist options
  • Save ryanmaclean/8940c1bc33dd03c6ff1d6c745c059408 to your computer and use it in GitHub Desktop.
Save ryanmaclean/8940c1bc33dd03c6ff1d6c745c059408 to your computer and use it in GitHub Desktop.
Run Datadog As Container to Monitor NAS

Datadog on NASes

Monitoring your Synology or Asus ADM 4 NAS

Summary

Just a walkthrough of the containerized way to get NAS stats to Datadog.

The tl;dr is the container can monitor the host, processes, grab logs and SNMP. If you're using your NAS as a quick dev box you could also monitor other containers.

Synology DSM 6.X

Via SSH

SSH to your Synology NAS, edit YOURENV and YOURAPIKEY, in the following (found in synology_dd_install.sh) then run it via:

vi synolog_dd_install.sh
!#/usr/bin/env bash
DOCKER_CONTENT_TRUST=1 docker run -d \
  --name dsm-datadog \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v /proc/:/host/proc/:ro \
  -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
  -v /sys/kernel/debug:/sys/kernel/debug \
  -e DD_API_KEY="YOURAPIKEY" \
  -e DD_ENV="YOURENV" \
  -e DD_APM_ENABLED=false \
  -e DD_APM_NON_LOCAL_TRAFFIC=true \
  -e DD_PROCESS_AGENT_ENABLED=true \
  -e DD_LOGS_ENABLED=true \
  -e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true \
  --security-opt apparmor:unconfined \
  --privileged \
  --restart unless-stopped \
  datadog/agent:latest

Set the file as executable:

chmod +x synolog_dd_install.sh

Run it: ./synolog_dd_install.sh

Check the containers page under infrastructure in Datadog!

Asus Lockerstor ADM 4.0

SSH

SSH to your Lockerstor NAS, edit YOURENV and YOURAPIKEY, in the following (found in lockerstor_dd_install.sh) then run it via:

vi synolog_dd_install.sh
!#/usr/bin/env sh
DOCKER_CONTENT_TRUST=1 docker run -d \
  --name adm-datadog \
  -e DD_SYSTEM_PROBE_ENABLED=true \
  -e DD_PROCESS_AGENT_ENABLED=true \
  -e DD_API_KEY="${DD_API}" \
  -e DD_ENV="${DD_ENV}" \
  -e DD_APM_ENABLED=false \
  -e DD_APM_NON_LOCAL_TRAFFIC=true \
  -e DD_PROCESS_AGENT_ENABLED=true \
  -e DD_LOGS_ENABLED=true \
  -e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v /proc/:/host/proc/:ro \
  -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
  -v /sys/kernel/debug:/sys/kernel/debug \  
  --security-opt apparmor:unconfined \
  --cap-add=SYS_ADMIN \
  --cap-add=SYS_RESOURCE \
  --cap-add=SYS_PTRACE \
  --cap-add=NET_ADMIN \
  --cap-add=NET_BROADCAST \
  --cap-add=NET_RAW \
  --cap-add=IPC_LOCK \
  --cap-add=CHOWN \
  --privileged \
  --restart unless-stopped \
  datadog/agent:latest

Set the file as executable:

chmod +x synolog_dd_install.sh

Run it: ./synolog_dd_install.sh

Check the containers page under infrastructure in Datadog!

Notes

Documentation

Check Runners

If you're on a NAS with an Atom single or dual core, changing DD_CHECK_RUNNERS to one or two runners will do less at once, but if you have many checks may also lag. Per docs at the time of writing:

The Agent runs all checks concurrently by default (default value = 4 runners). To run the checks sequentially, set the value to 1. If you need to run a high number of checks (or slow checks) the collector-queue component might fall behind and fail the healthcheck. You can increase the number of runners to run checks in parallel.

QNAP

Ideally I'd have a QuTS-enabled NAS to try this on - if you've got one I'd love to help test!

#!/usr/bin/env sh
echo "Attempting to install Datadog Agent via Docker"
if [[ -z "$1" && -z "$2" ]]; then
echo "Please run with lockerstor_dd_install.sh YOURDDAPIKEY YOURENV"
echo "Exiting..."
exit
fi
DD_API="$1"
DD_ENV="$2"
DOCKER_CONTENT_TRUST=1 docker run -d \
--name adm-datadog \
-e DD_SYSTEM_PROBE_ENABLED=true \
-e DD_PROCESS_AGENT_ENABLED=true \
-e DD_API_KEY="${DD_API}" \
-e DD_ENV="${DD_ENV}" \
-e DD_APM_ENABLED=false \
-e DD_APM_NON_LOCAL_TRAFFIC=true \
-e DD_PROCESS_AGENT_ENABLED=true \
-e DD_LOGS_ENABLED=true \
-e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
-v /sys/kernel/debug:/sys/kernel/debug \
--security-opt apparmor:unconfined \
--cap-add=SYS_ADMIN \
--cap-add=SYS_RESOURCE \
--cap-add=SYS_PTRACE \
--cap-add=NET_ADMIN \
--cap-add=NET_BROADCAST \
--cap-add=NET_RAW \
--cap-add=IPC_LOCK \
--cap-add=CHOWN \
--privileged \
--restart unless-stopped \
datadog/agent:latest
#!/usr/bin/env bash
echo "Attempting to install Datadog Agent via Docker"
if [[ -z "$1" && -z "$2" ]]; then
echo "Please run with synology_dd_install.sh YOURDDAPIKEY YOURENV"
echo "Exiting..."
exit
fi
DD_API="$1"
DD_ENV="$2"
DOCKER_CONTENT_TRUST=1 docker run -d \
--name dsm-datadog \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
-v /sys/kernel/debug:/sys/kernel/debug \
-e DD_API_KEY="${DD_API}" \
-e DD_ENV="${DD_ENV}" \
-e DD_APM_ENABLED=false \
-e DD_APM_NON_LOCAL_TRAFFIC=true \
-e DD_PROCESS_AGENT_ENABLED=true \
-e DD_LOGS_ENABLED=true \
-e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true \
--security-opt apparmor:unconfined \
--privileged \
--restart unless-stopped \
datadog/agent:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment