This is collectd plugin and docker image to collect resource usage from docker
containers. Resource usage collected from docker stats API and sent to
graphite installation. Containers can be added and removed on the fly, no need
to restart collectd.
This plugin treats containers as tasks that run as parts of apps.
- Set the label
collectd_docker_appdirectly on the container - Set
collectd_docker_app_labelon the container that points to which actual label to use. e.g.collectd_docker_app_label=app_idwill useapp_idlabel on the container - Set environment variable
COLLECTD_DOCKER_APPon the container - Set
COLLECTD_DOCKER_APP_ENVon the container that points to which actual environment variable to use. For example, marathon setsMARATHON_APP_IDand by settingCOLLECTD_DOCKER_APP_ENVtoMARATHON_APP_IDyou would get the marathon app id.
These keys can be changed globally by setting APP_LABEL_KEY or APP_ENV_KEY
when running the collectd container. For example, if you set APP_ENV_KEY to
MARATHON_APP_ID on the collectd container, then this will use
MARATHON_APP_ID on all running containers.
- Set the label
collectd_docker_taskdirectly on the container - Set
collectd_docker_task_labelon the container that points to which actual label to use. e.g.collectd_docker_task_label=task_idwill usetask_idlabel on the container - Set environment variable
COLLECTD_DOCKER_TASKon the container - Set
COLLECTD_DOCKER_TASK_ENVon the container that points to which actual environment variable to use. For example, mesos setsMESOS_TASK_IDand by settingCOLLECTD_DOCKER_TASK_ENVtoMESOS_TASK_IDyou would get the mesos task id.
These keys can be changed globally by setting TASK_LABEL_KEY or TASK_ENV_KEY
when running the collectd container. For example, if you set TASK_ENV_KEY to
MESOS_TASK_ID on the collectd container, then this will use MESOS_TASK_ID on
all running containers.
- If a container's app name cannot be identified, it will be not monitored. So if you are not seeing metrics, then it means you must check whether the app name is configured correctly.
- The string
<app>.<task>is limited by 63 characters. So it is also useful to setCOLLECTD_DOCKER_APP_ENV_TRIM_PREFIXand/orCOLLECTD_DOCKER_TASK_ENV_TRIM_PREFIXon the containers.
Metric names look line this:
collectd.<host>.docker_stats.<app>.<task>.<type>.<metric>
Gauges:
-
CPU
cpu.usercpu.systemcpu.total
-
Memory overview
memory.limitmemory.maxmemory.usage
-
Memory breakdown
memory.active_anonmemory.active_filememory.cachememory.inactive_anonmemory.inactive_filememory.mapped_filememory.pg_faultmemory.pg_inmemory.pg_outmemory.rssmemory.rss_hugememory.unevictablememory.writeback
-
Network (bridge mode only)
net.rx_bytesnet.rx_droppednet.rx_errorsnet.rx_packetsnet.tx_bytesnet.tx_droppednet.tx_errorsnet.tx_packets
Percent:
- CPU
cpu.percent
Grafana 2 dashboard is included.
- CPU usage per second
aliasByNode(scaleToSeconds(nonNegativeDerivative(collectd.$host.docker_stats.$app.$task.gauge.cpu.total), 1), 3, 4, 1)
- Memory limit
alias(averageSeries(collectd.$host.docker_stats.$app.$task.gauge.memory.limit), 'limit')
- Memory usage
aliasByNode(collectd.$host.docker_stats.$app.$task.gauge.memory.usage, 3, 4, 1)
- Network bytes per second tx
aliasByNode(scaleToSeconds(nonNegativeDerivative(collectd.$host.docker_stats.$app.$task.gauge.net.tx_bytes), 1), 3, 4, 1, 7)
- Network bytes per second rx
aliasByNode(scaleToSeconds(nonNegativeDerivative(collectd.$host.docker_stats.$app.$task.gauge.net.rx_bytes), 1), 3, 4, 1, 7)
- Network packets per second tx
aliasByNode(scaleToSeconds(nonNegativeDerivative(collectd.$host.docker_stats.$app.$task.gauge.net.tx_packets), 1), 3, 4, 1, 7)
- Network packets per second rx
aliasByNode(scaleToSeconds(nonNegativeDerivative(collectd.$host.docker_stats.$app.$task.gauge.net.rx_packets), 1), 3, 4, 1, 7)
Minimal command:
docker run -d -v /var/run/docker.sock:/var/run/docker.sock \
-e GRAPHITE_HOST=<graphite host> -e COLLECTD_HOST=<colllectd host> \
bobrik/collectd-docker
COLLECTD_HOST- host to use in metric name, defaults toMESOS_HOSTif defined.COLLECTD_INTERVAL- metric update interval in seconds, defaults to10.GRAPHITE_HOST- host where carbon is listening for data.GRAPHITE_PORT- port where carbon is listening for data,2003by default.GRAPHITE_PREFIX- prefix for metrics in graphite,collectd.by default.APP_LABEL_KEY- container label to use for app name,collectd_docker_appby default.APP_ENV_KEY- container environment variable to use for app name,COLLECTD_DOCKER_APPby default.TASK_LABEL_KEY- container label to use for task name,collectd_docker_taskby default.TASK_ENV_KEY- container environment variable to use for task name,COLLECTD_DOCKER_TASKby default.
Note that this docker image is very minimal and libc inside does not support
search directive in /etc/resolv.conf. You have to supply full hostname in
GRAPHITE_HOST that can be resolved with nameserver.
MIT
