---
title: Docker swarm monitoring
author: james
type: post
date: 2017-10-03T08:09:04+00:00
url: /2017/10/swarm-monitoring/
snap_isAutoPosted:
  - 1
snapEdIT:
  - 1
snapFB:
  - 's:382:"a:1:{i:0;a:11:{s:2:"do";s:1:"1";s:9:"msgFormat";s:22:"New blog post: %TITLE%";s:8:"postType";s:1:"A";s:9:"isAutoImg";s:1:"A";s:8:"imgToUse";s:0:"";s:9:"isAutoURL";s:1:"A";s:8:"urlToUse";s:0:"";s:8:"isPosted";s:1:"1";s:4:"pgID";s:27:"658281334_10155506578631335";s:7:"postURL";s:57:"http://www.facebook.com/658281334/posts/10155506578631335";s:5:"pDate";s:19:"2017-10-03 08:15:31";}}";'
snapTW:
  - 's:376:"a:1:{i:0;a:11:{s:2:"do";s:1:"1";s:9:"msgFormat";s:30:"New blog post: %TITLE% - %URL%";s:8:"attchImg";s:1:"0";s:9:"isAutoImg";s:1:"A";s:8:"imgToUse";s:0:"";s:9:"isAutoURL";s:1:"A";s:8:"urlToUse";s:0:"";s:8:"isPosted";s:1:"1";s:4:"pgID";s:18:"915126845124816897";s:7:"postURL";s:52:"https://twitter.com/0xfce2/status/915126845124816897";s:5:"pDate";s:19:"2017-10-03 08:10:16";}}";'
categories:
  - Tech

---
I&#8217;ve seen a bunch of posts lately about how to set up Docker swarm monitoring with tools like cAdvisor and node_exporter which advise running them like this:

`docker service create --mode global -p 9100:9100 ...`

That will indeed run one container on each swarm node, but it has a subtle problem. When you connect to host:9100, the ingress network routing will connect you to a _random_ instance each connection (for swarm routing values of random). You will indeed get some metrics returned, but they will be for whichever host you happened to be routed to this time.

You can demonstrate this problem quite simply with something like:

`docker service create --name hello --mode global -p 8080:80 dockercloud/hello-world`

Then just reload the page and you&#8217;ll see that the hostname (container ID) changes sometimes. You might see it more readily with curl than a browser.

A simple solution is to just run these containers on each node as normal docker containers outside swarm management. In the setup I&#8217;m working on just now, we used the same Puppet automation that provisions the swarm to start the containers.

`docker run -d -p 9100:9100 ...`