Monitor rootless docker

I’m trying to monitor my docker containers, I have followed the instructions at Applications - LibreNMS Docs yet it seems it’s meant to be used with docker run by root and doesn’t seem to be able to gather any info about docker containers in rootless mode.

I tried to run /etc/snmp/docker-stats.sh as root and returns an error:

{“version”:“1”,“data”:[],“error”:“1”,“errorString”:“Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?”}

which makes sense, and seems to be the reason I don’t see any info in librenms web gui, if I run the same script as the docker user I do get info, so maybe some tweaking or changes are needed to be able to gather info on those containers running in rootless mode.

Has anyone tried this and/or have an idea on how to solve it?

Thank you very much for your time.

Have a look at this thread, it might help.

Have a look at using sudo for the extend call to run as the correct user:

Thank you for your hint, it was indeed useful, after reading that figured I need to add ‘docker context use rootless’ at the beginning of /etc/snmp/docker-stats.sh for it to run properly under the docker user with sudo, then changed the last line of ‘/etc/snmp/snmpd.conf’ to ‘extend docker /usr/bin/sudo /etc/snmp/docker-stats.sh’.
Now ‘sudo -u docker /etc/snmp/docker-stats.sh’ returns info properly, restarted the docker server just in case and waited a couple of hours, yet librenms still shows nothing:


Do I need to wait some more or am I missing something else?

I thank you for answering, but I fail to see the connection beetween that post and my problem.

I had similar issues but can’t recall exactly which sequence of moves fixed it. There are a couple of threads around targeting different issues - php-pear or jq maybe missing, SNMP timeouts etc.

Check this one where I showed how to debug the output of the SNMP extend call so you can see what LibreNMS is truly receiving and it might send you in the right direction: No graphs or rrd files for Docker containers

Thank you! Your answer sent me in the right direction, it took me a while and some tweaking but it works now, here’s what I had to do to make it work:

  • If using Debian, Debian-snmp user MUST be in docker group (sudo usermod -a -G docker Debian-snmp)

  • your docker-stats.sh file MUST have “export DOCKER_HOST=unix:///run/user/1000/docker.sock” or the same line you put in .bashrc when you first set up rootless docker

  • your snmpd.conf file MUST have “extend docker /usr/bin/sudo /etc/snmp/docker-stats.sh” as per librenms documentation

  • you MUST have a sudoer file in “/etc/sudoers.d” with “ALL ALL = NOPASSWD:/etc/snmp/docker-stats.sh” probably “Debian-snmp ALL = NOPASSWD:/etc/snmp/docker-stats.sh” would be enough, I didn’t test it, this is used exclusively internally so I don’t care having permissions a bit relaxed.

And I think that’s it, the detail that made all this possible for me was that “Capture button” that I didn’t even remember existed, the documentation is huge and daunting and that seems to have slipped through the cracks in my head years ago when I first read it.

I believe that those details sould be in the docs, I’m willing to add them myself if the devs allow it or someone tells me where to send the modifications to be added.

Glad you got it working.

For simple documentation changes, if you have/create a github account, you can submit doc changes directly in your browser with preview etc. so you can get used to markdown.

Click the pencil icon top right of a page at docs.librenms.org then you can edit, fill in some pull request details and it will go in for review/approval.

Thank you! I’ll sure do that asap, since those small details would have saved me a lot of time and headache, hopfuly it’ll save the hassle to someone else, the documentation is indeed extensive, but some parts are, how can I say it… worded poorly, or copy/pasted from ancient man pages…

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.