mirror of
https://github.com/SCST-project/scst.git
synced 2026-08-25 00:26:43 +00:00
Reject zero and nonnumeric sampling intervals before entering the monitor loops, avoiding division errors and repeated failed sleep calls.
83 lines
1.8 KiB
Bash
Executable File
83 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
############################################################################
|
|
#
|
|
# Script for monitoring system-wide memory usage.
|
|
#
|
|
# Copyright (C) 2009 Bart Van Assche <bvanassche@acm.org>.
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation, version 2
|
|
# of the License.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
############################################################################
|
|
|
|
#########################
|
|
# Function definitions #
|
|
#########################
|
|
|
|
function usage {
|
|
echo "Usage: $0 [-h] [-i <interval>]"
|
|
echo " -h - display this information."
|
|
echo " -i - monitoring interval in seconds."
|
|
}
|
|
|
|
|
|
#########################
|
|
# Default settings #
|
|
#########################
|
|
|
|
interval=10
|
|
|
|
|
|
#########################
|
|
# Argument processing #
|
|
#########################
|
|
|
|
set -- $(/usr/bin/getopt "hi:" "$@")
|
|
while [ "$1" != "${1#-}" ]
|
|
do
|
|
case "$1" in
|
|
'-i') interval="$2"; shift; shift;;
|
|
'--') shift;;
|
|
*) usage; exit 1;;
|
|
esac
|
|
done
|
|
|
|
if [ "$#" != 0 ] || ! [[ "${interval}" =~ ^0*[1-9][0-9]*$ ]]; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
interval="${interval#"${interval%%[!0]*}"}"
|
|
|
|
|
|
####################
|
|
# Performance test #
|
|
####################
|
|
|
|
printf "%-10s " "Time"
|
|
cat /proc/meminfo |
|
|
while read -r label number unit
|
|
do
|
|
printf " %10s" "${label%:}"
|
|
done
|
|
echo
|
|
|
|
while true
|
|
do
|
|
printf "%-10d" "$(date +%s)"
|
|
cat /proc/meminfo |
|
|
while read -r label number unit
|
|
do
|
|
printf " %10d" "${number}"
|
|
done
|
|
echo
|
|
sleep "${interval}"
|
|
done
|