From 0387b7a0a722f304f3aab802ffddfd64bbccb6e8 Mon Sep 17 00:00:00 2001 From: dlezcano Date: Fri, 21 Nov 2008 18:19:36 +0000 Subject: [PATCH] Add a netstat per container From: Daniel Lezcano Added the ability to do netstat from outside of the container to see network resources used by the container. Signed-off-by: Daniel Lezcano --- src/lxc/Makefile.am | 1 + src/lxc/lxc-netstat.in | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/lxc/lxc-netstat.in diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index 4ea70008e..2ab5b94c5 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -43,6 +43,7 @@ liblxc_la_LDFLAGS = -release @PACKAGE_VERSION@ bin_SCRIPTS = \ lxc-ps \ lxc-ls \ + lxc-netstat \ lxc-checkconfig bin_PROGRAMS = \ diff --git a/src/lxc/lxc-netstat.in b/src/lxc/lxc-netstat.in new file mode 100644 index 000000000..63728de14 --- /dev/null +++ b/src/lxc/lxc-netstat.in @@ -0,0 +1,39 @@ +#!/bin/bash +# set -ex + +prefix=@prefix@ +lxcpath=@localstatedir@/lxc + +if [ ! -r $lxcpath ]; then + exit 0 +fi + +if [ $# -eq 0 ]; then + echo "usage: $0 -n " + exit 1 +fi + +for i in $*; do + case $i in + -n) + name=$2; shift 2;; + esac +done + +if [ -z "$name" ]; then + echo "usage: $0 -n " + exit 1 +fi + +if [ ! -d $lxcpath/$name ]; then + echo "'$name' does not exists" + exit 1 +fi + +if [ ! -f $lxcpath/$name/init ]; then + exit 0 +fi + +initpid=$(cat $lxcpath/$name/init) + +mount --bind /proc/$initpid/net /proc/$$/net && exec netstat $* \ No newline at end of file