diff --git a/plugins/docker/docker_cpu b/plugins/docker/docker_cpu index c9b7e642..63165a11 100755 --- a/plugins/docker/docker_cpu +++ b/plugins/docker/docker_cpu @@ -66,14 +66,18 @@ for my $i (1 .. $#containers) $name =~ s/[-\+*\/\.]/_/g; # truncate container name with "," character. $name =~ s/,.*//g; - open(my $file, '<', "/sys/fs/cgroup/cpuacct/docker/$id/cpuacct.usage") or die "Unable to open file, $!"; - my $total_cpu_ns = <$file>; - $total_cpu_ns =~ s/\s+$//; - close $file; - open($file, '<', "/sys/fs/cgroup/cpuacct/docker/$id/cpuacct.usage_percpu") or die "Unable to open file, $!"; - my @ncpu = split / /, <$file>; - close $file; - push @result, {'name'=>$name, 'total_cpu_ns'=>$total_cpu_ns, 'ncpu'=>$#ncpu}; + if (open(my $file, '<', "/sys/fs/cgroup/cpuacct/docker/$id/cpuacct.usage")) + { + my $total_cpu_ns = <$file>; + $total_cpu_ns =~ s/\s+$//; + close $file; + if (open($file, '<', "/sys/fs/cgroup/cpuacct/docker/$id/cpuacct.usage_percpu")) + { + my @ncpu = split / /, <$file>; + close $file; + push @result, {'name'=>$name, 'total_cpu_ns'=>$total_cpu_ns, 'ncpu'=>$#ncpu}; + } + } } if (defined $ARGV[0] and $ARGV[0] eq "config") diff --git a/plugins/docker/docker_memory b/plugins/docker/docker_memory index b4cb3cc9..1d848043 100755 --- a/plugins/docker/docker_memory +++ b/plugins/docker/docker_memory @@ -66,10 +66,12 @@ for my $i (1 .. $#containers) $name =~ s/[-\+*\/\.]/_/g; # truncate container name with "," character. $name =~ s/,.*//g; - open(my $file, '<', "/sys/fs/cgroup/memory/docker/$id/memory.usage_in_bytes") or die "Unable to open file, $!"; - my $memory_bytes = <$file>; - $memory_bytes =~ s/\s+$//; - push @result, {'name'=>$name, 'memory_bytes'=>$memory_bytes}; + if (open(my $file, '<', "/sys/fs/cgroup/memory/docker/$id/memory.usage_in_bytes")) + { + my $memory_bytes = <$file>; + $memory_bytes =~ s/\s+$//; + push @result, {'name'=>$name, 'memory_bytes'=>$memory_bytes}; + } } if (defined $ARGV[0] and $ARGV[0] eq "config")