Re: monitorare utilizzo di RAM
- To: debian-italian@lists.debian.org
- Subject: Re: monitorare utilizzo di RAM
- From: Piviul <piviul@riminilug.it>
- Date: Mon, 2 May 2016 08:46:04 +0200
- Message-id: <[🔎] 5726F7AC.9080801@riminilug.it>
- In-reply-to: <5724E30D.9070902@gmail.com>
- References: <5721B005.2070809@riminilug.it> <572254D2.90702@gmail.com> <572315A2.7030001@riminilug.it> <57239522.8040008@gmail.com> <CAFp8AucQQ9bYYZJjBnk=8B+r6S3CsW3QOmFZhK7ZtO5h=xKzSw@mail.gmail.com> <5724E30D.9070902@gmail.com>
Mille grazie a tutti quanti; se qualcuno fosse interessato posto lo script:
#!/bin/bash
pname=dar
logger=$(which logger)
[ -z $logger ] && echo "E: logger not found" && exit 1
logger="$logger -t $(basename $0 .sh)"
while [ 1 = 1 ]; do
pid=$(pidof $pname | cut -f1 -d\ )
maxram=0
if [ -n "$pid" ]; then
$logger "I find a process with name $pname (pid $pid): I begin
to monitor the max RAM used by the process"
while [ "$(pidof $pname)" = "$pid" ]; do
str="[[:space:]]*[^[:space:]]*"
cmd="ps aux -p $pid | tail -n1 | sed 's/^"
for i in {1..4}; do cmd=$cmd$str; done # I skip first 4
(USER,PID,%CPU,%MEM,VSZ)
cmd="$cmd[[:space:]]*\([^[:space:]]*\).*$/\1/'"
curram=$(eval $cmd)
# echo "$(date --rfc-3339=seconds) ($pid): $curram"
if [ -z "$(echo $curram | grep ^[0-9]*$)" ]; then
$logger "E: error finding the RAM amount used by $pname:
$curram doesn't seems to be numeric"
elif [ $curram -gt $maxram ]; then
maxram=$curram
fi
sleep 1
done
$logger "the process $pname ($pid) has used $maxram Kib"
fi
sleep 10
done
Reply to: