Docker container for the Server Density monitoring agent
10K+
Server Density Agent Dockerfile. https://github.com/serverdensity/docker-sd-agent
The default image is ready-to-go. You just need to set your AGENT_KEY and ACCOUNT in the environment.
docker run -d --name sd-agent -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e AGENT_KEY=$AGENT_KEY -e ACCOUNT=$ACCOUNT serverdensity/sd-agent
You can also enable DEBUG mode and set the hostname in your sd-agent config.cfg
docker run -d --name sd-agent -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e AGENT_KEY=$AGENT_KEY -e ACCOUNT=$ACCOUNT -e LOG_LEVEL=$LOG_LEVEL serverdensity/sd-agent
The following environment variables can be used when running the container:
AGENT_KEY - Your agent key, can be found in your UI RequiredACCOUNT - Your account name RequiredLOG_LEVEL - The log level of the agent running in the containerSD_HOSTNAME - The hostname specified in your containered agent's config.cfg (Note that this does not set the container hostname)PROXY_HOST - Configures a proxy host for the agentPROXY_PORT - Configures a proxy port for the agentPROXY_USER - Configures a proxy user for the agentPROXY_PASSWORD - Configures a proxy password for the agentNON_LOCAL_TRAFFIC - Enable non local traffic supportCONTAINER_SIZE - Set to TRUE to enable container size metricsIMAGE_STATS - Set to TRUE to enable image stat metricsIMAGE_SIZE - Set to TRUE to enable image size metricsDISK_STATS - Set to TRUE to enable disk stat metricsTIMEOUT - Set the timeout for the docker_daemon check in secondsSDSTATSD - Set to TRUE to enable sd-agent-sdstatsdSDSTATSD_NAMESPACE - Set a namespace for SDStatsD metrics. This will change custom.metric into namespace.custom.metricSDSTATSD_UTF8 - Enables UTF8 decoding for SDStatsDSDSTATSD_SO_RCVBUF - The number of bytes allocated to the statsd socket receive bufferDownload the Dockerfile and entrypoint.sh script, and build the image.
docker build -t sd-agent .
Get info regarding the sd-agent service:
docker exec sd-agent service sd-agent info
SDStatsD is available in the container but is disabled by default.
To enable SDStatsD pass the env variable SDSTATSD to the container. The value does not matter, the container simply checks for the presence of this variable. NON_LOCAL_TRAFFIC is also required to allow the agent to receive metrics from any IP address (NOTE: This is a potential security risk as it allows metrics to be posted from any IP address. Please ensure that your host configuration does not allow external access to this port to prevent this). For example:
docker run -d --name sd-agent \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
-e AGENT_KEY=$AGENT_KEY \
-e ACCOUNT=$ACCOUNT \
-e SDSTATSD="TRUE" \
-e NON_LOCAL_TRAFFIC="TRUE" \
serverdensity/sd-agent
Note that you will need to publish the port to make use of SDStatsD:
docker run -d --name sd-agent \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
-e AGENT_KEY=$AGENT_KEY \
-e ACCOUNT=$ACCOUNT \
-e SDSTATSD="TRUE" \
-e NON_LOCAL_TRAFFIC="TRUE" \
-p 127.0.0.1:8125:8125/udp \
serverdensity/sd-agent
The above example will make the port available on the host only. If you want the port to be available from anywhere you should use the following instead:
-p 8125:8125/udp
You can enable official plugins by creating a Dockerfile, using serverdensity/sd-agent:latest as a base image, and installing the plugin and copying the config to the container.
For example:
FROM serverdensity/sd-agent
# Install the MySQL plugin
RUN apt-get update && apt-get install sd-agent-mysql -y
# Add MySQL check configuration
ADD mysql.yaml /etc/sd-agent/conf.d/mysql.yaml
# Cleanup apt
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Please see the examples directory for more examples.
You can enable official plugins by mounting the conf.d & checks.d folders which will be copied to the correct locations for the agent when the container starts. Checks and config files can be found at the sd-agent-core-plugins repo.
The example below is for MySQL, however any plugin can be used.
Create a a configuration directory on your host and download the conf.yaml.example YAML configuration file to the new directory, with the correct name (the name used should be the same as the directory of the check in the sd-agent-core-plugins repo repository):
mkdir -p /opt/sd-agent/conf.d
wget https://raw.githubusercontent.com/serverdensity/sd-agent-core-plugins/master/mysql/conf.yaml.example -O /opt/sd-agent/conf.d/mysql.yaml
Edit the configuration file for your chosen plugin.
Create a checks directory and download the check.py file to the new directory, with the correct name (the name used should be the same as the directory of the check in the sd-agent-core-plugins repo repository):
mkdir -p /opt/sd-agent/checks.d
wget https://raw.githubusercontent.com/serverdensity/sd-agent-core-plugins/master/mysql/check.py -P /opt/sd-agent/checks.d/mysql.py
When creating the container mount the check and conf directories:
docker run -d --name sd-agent \
-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 /opt/sd-agent/conf.d:/conf.d:ro \
-v /opt/sd-agent/checks.d:/checks.d:ro \
-e AGENT_KEY=$AGENT_KEY \
-e ACCOUNT=$ACCOUNT \
serverdensity/sd-agent
It's important to note the addition of -v /opt/conf.d:/conf.d:ro -v /opt/checks.d:/checks.d:ro
Now when the container starts the checks and their configs will be copied to the correct directories.
You can enable official plugins by creating a Dockerfile, using serverdensity/sd-agent:latest as a base image, and copying the plugin and config to the container.
Create a custom plugin as per the Information about Custom Plugins - v2 document.
Create a Dockerfile using serverdensity/sd-agent:latest as a base image, copying the plugin and config to the container
FROM serverdensity/sd-agent
# Add Custom check configuration
ADD custom.yaml /etc/sd-agent/conf.d/custom.yaml
# Add Custom check code
ADD custom.py /usr/share/python/sd-agent/checks.d/custom.py
Please see the examples directory for more examples.
Create a custom plugin as per the Information about Custom Plugins - v2 document.
Create a configuration directory (if you're using official plugins too you may already have this) and copy your custom plugin conf.yaml files to the new directory:
mkdir -p /opt/sd-agent/conf.d
cp ~/Example.yaml /opt/sd-agent/conf.d/Example.yaml
Edit the configuration file for your custom plugin.
Create a checks directory and copy your custom plugin check.py file to the new directory:
mkdir -p /opt/sd-agent/checks.d
cp ~/Example.py /opt/sd-agent/checks.d/Example.py
When creating the container mount the check and conf directories:
docker run -d --name sd-agent \
-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 /opt/sd-agent/conf.d:/conf.d:ro \
-v /opt/sd-agent/checks.d:/checks.d:ro \
-e AGENT_KEY=$AGENT_KEY \
-e ACCOUNT=$ACCOUNT \
serverdensity/sd-agent
It's important to note the addition of -v /opt/conf.d:/conf.d:ro -v /opt/checks.d:/checks.d:ro
Now when the container starts your v2 custom plugins will be copied to the correct directories for the agent.
| WARNING: This method will soon be deprecated. If you have v1 custom plugins, we recommend converting them to v2 Custom plugins instead |
|---|
Create a plugins directory and copy your check.py files to the new directory:
mkdir /opt/plugins
touch /opt/plugins/Plugin.py
When creating the container mount the directories:
docker run -d --name sd-agent \
-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 /opt/plugins:/plugins:ro \
-e AGENT_KEY=$AGENT_KEY \
-e ACCOUNT=$ACCOUNT \
serverdensity/sd-agent
It's important to note the addition of -v /opt/plugins:/plugins:ro
Now when the container starts your v1 custom plugins will be copied to the correct directories for the agent.
Use the following to copy the sd-agent logs from the container to your host:
docker cp sd-agent:/var/log/sd-agent /tmp/log-sd-agent
Basic information about the Agent execution is available via dockers logs command.
docker logs sd-agent
You can also exec a shell on the container and tail the logs from there for debugging. (Note that the following logs are availabe: collector.log, forwarder.log and supervisord.log)
$ docker exec -it sd-agent bash
# tail -f /var/log/sd-agent/collector.log
2016-09-22 14:49:52 UTC | DEBUG | sd.collector | checks.collector(emitter.py:52) | payload_size=41161, compressed_size=41161, compression_ratio=1.000
2016-09-22 14:49:53 UTC | DEBUG | sd.collector | checks.check_status(check_status.py:136) | Persisting status to /run/sd-agent/CollectorStatus.pickle
2016-09-22 14:49:53 UTC | DEBUG | sd.collector | checks.collector(collector.py:561) | Finished run #22. Collection time: 9.0s. Emit time: 0.79s
The Agent cannot collect disk metrics from volumes that are not mounted to the Agent container. If you want to monitor additional partitions, make sure to share them to the container when executing the docker run command (e.g. -v /data:/data:ro)
As docker isolates containers from the host the Agent cannot access all host metrics.
Known missing/incorrect metrics:
These limitations can be worked around by telling docker not to containerize the network and by using the host's PID namespace inside the container.
To enable host network metrics run the container with --net=host
docker run -d --name sd-agent --net=host -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e AGENT_KEY=$AGENT_KEY -e ACCOUNT=$ACCOUNT serverdensity/sd-agent
To enable host process list metrics run the container with --pid=host
docker run -d --name sd-agent --pid=host -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e AGENT_KEY=$AGENT_KEY -e ACCOUNT=$ACCOUNT serverdensity/sd-agent
Both options can be combined:
docker run -d --name sd-agent --net=host --pid=host -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e AGENT_KEY=$AGENT_KEY -e ACCOUNT=$ACCOUNT serverdensity/sd-agent
Content type
Image
Digest
Size
97.5 MB
Last updated
over 4 years ago
docker pull serverdensity/sd-agent