Skip to content

Commit

Permalink
docker_memory: add total memory used
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-wtioit committed Apr 14, 2023
1 parent e5f366d commit a928b81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugins/docker/docker_memory
Expand Up @@ -55,6 +55,7 @@ $docker =~ s/\s+$//;

my @containers = split "\n" , `$docker ps --no-trunc=true`;
my $result;
my $total = 0;

for my $i (1 .. $#containers)
{
Expand Down Expand Up @@ -82,6 +83,7 @@ for my $i (1 .. $#containers)
my $memory_bytes = <$file>;
$memory_bytes =~ s/\s+$//;
push @result, {'name'=>$name, 'memory_bytes'=>$memory_bytes};
$total = $total + $memory_bytes;
}
}

Expand All @@ -93,17 +95,26 @@ if (defined $ARGV[0] and $ARGV[0] eq "config")
print "graph_category virtualization\n";
print "graph_info This graph shows docker container memory usage.\n";

my $first = 1;
foreach(@result)
{
print "$$_{'name'}.label $$_{'name'}\n";
print "$$_{'name'}.draw LINE2\n";
if ($first) {
print "$$_{'name'}.draw AREA\n";
$first = 0
} else {
print "$$_{'name'}.draw STACK\n";
}
}
print "total.label Total Memory\n";
print "total.draw LINE2\n";
exit 0;
}

foreach(@result)
{
print "$$_{'name'}.value $$_{'memory_bytes'}\n";
}
print "total.value $total\n";

# vim:syntax=perl
Binary file modified plugins/docker/example-graphs/docker_memory-day.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a928b81

Please sign in to comment.