Tools to calculate memory usage per jail
Miroslav Lachman
000.fbsd at quip.cz
Wed Jun 3 10:40:15 UTC 2009
Marc G. Fournier wrote:
>
> Subject says it all ... does anyone know of / have such a tool?
I am using some modified shell script - jps. It is based on Oliver
Fromme http://www.secnetix.de/~olli/scripts/jps
My version is attached. If jps is called with JID param, you get list of
processes of given jail and summary like this:
==============================
summary for JID 6 / tester1.example.com
%MEM RSS VSZ %CPU
5 221064 1034648 0
It is far from perfect tool, but it is enough to my needs.
Or you can ask on freebsd-jail at freebsd.org list, where are more skilled
peoples around jails :)
[Stef Walter is working on bsnmp-jails, maybe he is able to extend it
for memory usage too]
Miroslav Lachman
-------------- next part --------------
#!/bin/sh -
#
# Copyright (C) 2007 Oliver Fromme <olli at fromme.com> <olli at secnetix.de>
# All rights reserverd. Standard 2-clause BSD license and disclaimer apply.
#
# List processes that are running inside a jail.
# This is intended to complement the standard jls(8) command.
#
# Usage:
# jps list all jailed processes
# jps <JID> list only processes in jail <JID>.
#
# Run the jls(8) command to get a list of jails and JIDs.
#
# Note: This script works for FreeBSD >= 6 only!
# For FreeBSD 4.x, please use jailstat instead:
# http://www.secnetix.de/~olli/scripts/jailstat
#
ME="${0##*/}"
Usage()
{
cat <<-tac
$ME -- List processes that are running inside a jail.
This is intended to complement the standard jls(8) command.
Usage:
$ME list all jailed processes
$ME <JID> list only processes in jail <JID>
Run the jls(8) command to get a list of jails and JIDs.
tac
exit 1
}
if [ $# -gt 2 ]; then
Usage
fi
if [ $# -eq 1 ]; then
case "$1" in
""|*[!0-9]*) Usage ;;
esac
FILTER='$1=="'$1'"'
sum_jid="$1"
jname=`jls | awk "$FILTER"'{ print $3 }'`
else
FILTER='$1!="0"'
sum_jid="all"
jname="-"
fi
ps -axww -o jid,pid,%mem,rss,user,command | awk '$1!~/[0-9]/||'"$FILTER" | sort -n
echo
echo "=============================="
echo " summary for JID $sum_jid / $jname"
echo " %MEM RSS VSZ %CPU "
## NOTE: jail processes can be swapped (%mem & rss are zero, but vsz not)
ps -axww -o jid,%mem,rss,vsz,%cpu | awk '$1!~/[0-9]/||'"$FILTER" | awk '{ sm += $2; sp += $3; sv += $4; sc += $5 } END { printf(" %3d %9i %9i %3d \n", sm, sp, sv, sc) }'
#--
More information about the freebsd-isp
mailing list