Skip to content

Commit

Permalink
Better container views
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-lang committed Jul 31, 2023
1 parent 6a5d40c commit fdb7bdf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docker/container.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ our (%in);
my $container = $in{'container'};
my $tab = $in{'tab'};

ui_print_header(undef, text('view_container_title', $container), "", undef, undef, $in{'nonavlinks'});
my ($code, $container_name) = get_container_attr($container, 'Name');
if ($code) { # Bad container id
ui_print_header(undef, text('view_container_title', "not found"), "", undef, undef, $in{'nonavlinks'});
&ui_print_endpage(ui_alert_box($code, 'danger'), "Back", "/");
}

# Trim leading /
$container_name = substr $container_name, 1;
ui_print_header(undef, text('view_container_title', $container_name), "", undef, undef, $in{'nonavlinks'});

my @tabs = ( [ 'log', &text('tab_log') ],
[ 'inspect', &text('tab_inspect') ] );
Expand Down
12 changes: 12 additions & 0 deletions docker/docker-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ sub get_containers
return 0, @results;
}

sub get_container_attr
{
my($container, $attr) = @_;
my ($code, $result) = docker_command('inspect --type=container ' . $container, '{{.' . $attr . '}}');
if ($code != 0) {
print "Bang";
return $result;
}

return 0, $result;
}

sub get_stats
{
my ($code, $result) = docker_command('stats --all --no-stream', '{{.ID}},{{.CPUPerc}},{{.MemPerc}},{{.MemUsage}}');
Expand Down

0 comments on commit fdb7bdf

Please sign in to comment.