tools/riemann-docker/lib/riemann/tools/docker.rb in riemann-tools-1.10.0 vs tools/riemann-docker/lib/riemann/tools/docker.rb in riemann-tools-1.11.0
- old
+ new
@@ -29,10 +29,12 @@
def get_container_name(container)
container.json['Name'][1..]
end
def initialize
+ super
+
Docker.url = opts[:docker_host] unless opts[:docker_host].nil?
@hostname = opts[:host_hostname]
@hostname = Socket.gethostname if @hostname.nil? || !(@hostname.is_a? String) || @hostname.empty?
@@ -119,11 +121,11 @@
report_pct name, :memory, fraction, "#{usage} / #{total}"
end
def disk
- `df -P`.split(/\n/).each do |r|
+ `df -P`.split("\n").each do |r|
f = r.split(/\s+/)
next if f[0] == 'Filesystem'
next unless f[0] =~ %r{/} # Needs at least one slash in the mount path
# Calculate capacity
@@ -169,13 +171,11 @@
def tick
# Disk is the same in every container
disk if @disk_enabled
# Get CPU, Memory and Load of each container
- threads = []
-
- containers.each do |ctr|
- threads << Thread.new(ctr) do |container|
+ threads = containers.map do |ctr|
+ Thread.new(ctr) do |container|
id = container.id
name = get_container_name(container)
stats = Docker::Util.parse_json(container.connection.get("/containers/#{id}/stats", { stream: false }))