RRD: сбор статистики по использованию памяти

Материал из Linux Wiki
Перейти к навигацииПерейти к поиску
#!/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)