@version:3.6
source s_monitor {
monitor(
monitor-script("/etc/syslog-ng/docker.lua")
monitor-func("docker")
monitor-freq(5)
);
};
source s_containers {
log {
source {
file("/var/lib/docker/containers/<container_id>/<container_id>-json.log"
flags(no-parse)
);
};
rewrite { set("<container_id>" value("docker.container_id") ); };
};
};
parser p_json {
json-parser( prefix("docker.") template("$MESSAGE") );
};
destination d_elastic {
elasticsearch(
host("es_cluster.mydomain.gtld") port("9200")
index("docker")
);
};
destination d_graphite {
tcp( "172.16.177.139"
port(2003)
template("$(graphite-output --key docker.* )")
);
};
log {
source(s_monitor);
destination(d_graphite);
};
log {
source(s_containers);
parser(p_json);
destination(d_elastic);
};
function _get_image_list()
local popen = io.popen
local result = {}
for image in popen('docker ps -q --no-trunc'):lines() do
table.insert(result, image)
end
return result
end
function docker()
result = {}
local images = _get_image_list()
for i,image in ipairs(images) do
local f = io.open("/sys/fs/cgroup/memory/docker/"..image.."/memory.usage_in_bytes")
bytes = f:read("*l")
result["docker."..image..".memory"] = bytes
end
return result
end
tusavik@gmail.com
www.syslog-ng.org