datadir: "/var/lib/collectd/rrd/"
libdir: "/usr/lib/collectd/"
+docker/
+-------
+Sample docker setup using an LD_PRELOAD wrapper to redirect system calls
+accessing /proc and /sys to prefixed bind-mounts inside the container.
+
+Drop your collectd configuration snippets in the
+contrib/docker/collectd.conf.d/ directory, and build an image including them:
+ $ docker build -t my_collectd ./contrib/docker/
+
+Then run it with the required bind-mounts:
+ $ docker run -it --rm \
+ -v /proc:/rootfs/proc:ro -v /sys:/rootfs/sys:ro \
+ --name collectd my_collectd
+ $ docker exec -it collectd collectdctl listval
+
exec-munin.px
-------------
Script to be used with the exec-plugin (see collectd-exec(5) for details)
--- /dev/null
+FROM debian:stable
+
+ENV DEBIAN_FRONTEND noninteractive
+COPY 50docker-apt-conf /etc/apt/apt.conf.d/
+
+COPY rootfs_prefix/ /usr/src/rootfs_prefix/
+
+RUN apt-get update \
+ && apt-get upgrade \
+ && apt-get install \
+ collectd-core \
+ collectd-utils \
+ build-essential \
+ && make -C /usr/src/rootfs_prefix/ \
+ && apt-get --purge remove build-essential \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/*
+
+COPY collectd.conf /etc/collectd/collectd.conf
+COPY collectd.conf.d /etc/collectd/collectd.conf.d
+
+ENV LD_PRELOAD /usr/src/rootfs_prefix/rootfs_prefix.so
+
+CMD [ "/usr/sbin/collectd", "-f"]
--- /dev/null
+#define _GNU_SOURCE
+
+#include <dirent.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <error.h>
+#include <stdio.h>
+#include <string.h>
+
+#define PREFIX "/rootfs"
+#define BUFSIZE 256
+
+const char *add_prefix(const char *orig, char *prefixed) {
+ int status;
+ int errno;
+
+ if ((strncmp(orig, "/proc", 5) == 0) || (strncmp(orig, "/sys", 4) == 0)) {
+
+ status = snprintf(prefixed, BUFSIZE, "%s%s", PREFIX, orig);
+ if ((unsigned int)status >= BUFSIZE) {
+ error(status, ENAMETOOLONG,
+ "'%s' got truncated when adding '%s' prefix: '%s'", orig, PREFIX,
+ prefixed);
+ return orig;
+ } else if (status < 1) {
+ error(status, errno,
+ "adding '%s' prefix to file path failed: '%s' -> '%s'", PREFIX,
+ orig, prefixed);
+ return orig;
+ } else {
+ return (const char *)prefixed;
+ }
+
+ } else {
+ return orig;
+ }
+}
+
+FILE *fopen(const char *path, const char *mode) {
+ char filename[BUFSIZE] = "\0";
+
+ FILE *(*original_fopen)(const char *, const char *);
+ original_fopen = dlsym(RTLD_NEXT, "fopen");
+
+ return (*original_fopen)(add_prefix(path, filename), mode);
+}
+
+DIR *opendir(const char *name) {
+ char filename[BUFSIZE] = "\0";
+
+ DIR *(*original_opendir)(const char *);
+ original_opendir = dlsym(RTLD_NEXT, "opendir");
+
+ return (*original_opendir)(add_prefix(name, filename));
+}
+
+int *open(const char *pathname, int flags) {
+ char filename[BUFSIZE] = "\0";
+
+ int *(*original_open)(const char *, int);
+ original_open = dlsym(RTLD_NEXT, "open");
+
+ return (*original_open)(add_prefix(pathname, filename), flags);
+}