RRD: сбор статистики по использованию памяти: различия между версиями

Материал из Linux Wiki
Перейти к навигацииПерейти к поиску
(Новая: <source lang=bash> #!/bin/bash dbfile="$1" if [ -z "${1}" ]; then echo -e " \e[32mUsage: \e[31m$0 \e[33mRRDBFILE \e[32mExample: \e[31m$0 \e[33m/home/$USER/myups.rrd \e[0m" exit 2...)
 
Строка 1: Строка 1:
<source lang=bash>
<source lang=bash>
#!/bin/bash
#!/bin/bash
Строка 8: Строка 7:
\e[32mUsage: \e[31m$0 \e[33mRRDBFILE
\e[32mUsage: \e[31m$0 \e[33mRRDBFILE


\e[32mExample: \e[31m$0 \e[33m/home/$USER/myups.rrd
\e[32mExample: \e[31m$0 \e[33m/home/$USER/mymemory.rrd
\e[0m"
\e[0m"
exit 2
exit 2

Версия 16:34, 3 декабря 2008

#!/bin/bash

dbfile="$1"
if [ -z "${1}" ]; then
	echo -e "
	\e[32mUsage: \e[31m$0 \e[33mRRDBFILE

	\e[32mExample: \e[31m$0 \e[33m/home/$USER/mymemory.rrd
	\e[0m"
	exit 2
fi
if [ ! -e "${dbfile}" ]; then
	echo -e "\e[31mError: Database \e[33m\"${dbfile}\" \e[31mnot exist\e[0m"
	exit 1
fi
if [ ! -r /proc/meminfo ]; then
	echo -e "\e[31mError: \e[35m/proc/meminfo:\e[31mcan't get info\e[0m"
	exit 3
fi

rrdtool update "${dbfile}" $(awk '
/^MemTotal:/{all=$2}
/^MemFree:/{free=$2}
/^Buffers:/{buf=$2}
/^Cached:/{cache=$2}
END {print systime()":"all":"buf":"cache":"all-free-buf-cache":"free}
' /proc/meminfo)