Add a new utility script, gmetasnap which manages tarball snapshots of
the gmetad rrd databases. Add support for ganglia.sh for saving and restoring these snapshots at shutdown and startup respectivly. This makes it easier to use a ramdisk for rrddir which is necessicary for large clusters as the load of updating the databases rapidly consumes all available CPU.
This commit is contained in:
parent
5a033a05f0
commit
c37ee5c260
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=134272
4 changed files with 243 additions and 1 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
PORTNAME= monitor-core
|
||||
PORTVERSION= 3.0.1
|
||||
PORTREVISION= 0
|
||||
PORTREVISION= 1
|
||||
CATEGORIES= sysutils net parallel
|
||||
.if !defined(PORTDEV)
|
||||
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE}
|
||||
|
@ -109,6 +109,7 @@ post-build:
|
|||
do-install:
|
||||
.if defined (WITH_GMETAD)
|
||||
cd ${WRKSRC}/gmetad && make install
|
||||
${INSTALL_SCRIPT} ${FILESDIR}/gmetasnap.sh ${PREFIX}/sbin/gmetasnap
|
||||
${INSTALL_MAN} ${WRKSRC}/mans/gmetad.1 ${MANPREFIX}/man/man1
|
||||
${INSTALL_DATA} ${GMETAD_CONF} ${PREFIX}/etc/gmetad.conf.sample
|
||||
.endif
|
||||
|
|
|
@ -5,10 +5,23 @@
|
|||
# REQIORE: DAEMON
|
||||
# KEYWORD: FreeBSD shutdown
|
||||
|
||||
# XXX: This should really be two seperate scripts with rcorder
|
||||
# dependencies, but we can't do that at the moment and gmetad doesn't
|
||||
# work without a running gmond.
|
||||
|
||||
gmond_enable="NO"
|
||||
gmond_conf="%%PREFIX%%/etc/gmond.conf"
|
||||
|
||||
gmetad_enable="NO"
|
||||
gmetad_conf="%%PREFIX%%/etc/gmetad.conf"
|
||||
gmetasnap_enable="NO"
|
||||
gmetasnap_rrddir="/var/db/ganglia/rrds"
|
||||
gmetasnap_snapdir="/var/db/ganglia/snaps"
|
||||
gmetasnap_snapname="snap"
|
||||
gmetasnap_flags=""
|
||||
gmetasnap_command="%%PREFIX%%/sbin/gmetasnap"
|
||||
|
||||
### gmond ###
|
||||
|
||||
. %%RC_SUBR%%
|
||||
|
||||
|
@ -24,6 +37,8 @@ required_files=${gmond_conf}
|
|||
|
||||
run_rc_command $*
|
||||
|
||||
### gmetad ###
|
||||
|
||||
# Don't continue if we didn't run gmond
|
||||
if ! checkyesno ${rcvar}; then
|
||||
return 0
|
||||
|
@ -32,6 +47,36 @@ fi
|
|||
name=gmetad
|
||||
rcvar=`set_rcvar`
|
||||
command="%%PREFIX%%/sbin/${name}"
|
||||
start_precmd="gmetad_prestart"
|
||||
stop_postcmd="gmetad_poststop"
|
||||
|
||||
gmetad_prestart()
|
||||
{
|
||||
if [ ! -d ${gmetasnap_rrddir} ]; then
|
||||
mkdir -p ${gmetasnap_rrddir}
|
||||
fi
|
||||
chown ganglia:ganglia ${gmetasnap_rrddir}
|
||||
if checkyesno gmetasnap_enable; then
|
||||
if [ ! -d ${gmetasnap_snapdir} ]; then
|
||||
mkdir -p ${gmetasnap_snapdir}
|
||||
chown ganglia:ganglia ${gmetasnap_snapdir}
|
||||
fi
|
||||
if [ `ls ${gmetasnap_rrddir} | egrep -v ^.snap | wc -l` -eq 0 ]; then
|
||||
${gmetasnap_command} -r ${gmetasnap_rrddir} \
|
||||
-s ${gmetasnap_snapdir} ${gmetasnap_flags} \
|
||||
restore ${gmetasnap_snapname}
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
gmetad_poststop()
|
||||
{
|
||||
if checkyesno gmetasnap_enable; then
|
||||
${gmetasnap_command} -r ${gmetasnap_rrddir} \
|
||||
-s ${gmetasnap_snapdir} ${gmetasnap_flags} \
|
||||
save ${gmetasnap_snapname}
|
||||
fi
|
||||
}
|
||||
|
||||
load_rc_config $name
|
||||
command_args="-c ${gmetad_conf}"
|
||||
|
|
195
sysutils/ganglia-monitor-core/files/gmetasnap.sh
Normal file
195
sysutils/ganglia-monitor-core/files/gmetasnap.sh
Normal file
|
@ -0,0 +1,195 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# gmetasnapshot - Ganglia gmetad snapshot manager
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
||||
command=`basename $0`
|
||||
|
||||
def_rrddir=/var/db/ganglia/rrds
|
||||
def_snapdir=/var/db/ganglia/snaps
|
||||
def_snapname=snap
|
||||
def_comp=gzip
|
||||
|
||||
rrddir=$def_rrddir
|
||||
snapdir=$def_snapdir
|
||||
snapname=$def_snapname
|
||||
comp=$def_comp
|
||||
delete_old=0
|
||||
|
||||
usage()
|
||||
{
|
||||
exitcode=$1
|
||||
shift
|
||||
if [ -n "$*" ]; then
|
||||
warn $*
|
||||
fi
|
||||
cat <<EOU
|
||||
usage:
|
||||
${command} [<options>] save [<snapname>]
|
||||
${command} [<options>] restore [<snapname>]
|
||||
|
||||
options:
|
||||
-D Delete .old file after creating snapshot.
|
||||
-h Display this message
|
||||
-r <rrddir> Set the rrddir [default: ${def_rrddir}]
|
||||
-s <snapdir> Set the snapdir [default: ${def_snapdir}]
|
||||
-z <comptype> Set the compression type. Valid values are
|
||||
gzip, bzip2, and none. [default: ${def_comp}]
|
||||
|
||||
notes:
|
||||
- The default snapname is: ${def_snapname}
|
||||
- ${command} will not create rrddir or snapdir.
|
||||
EOU
|
||||
exit $1
|
||||
}
|
||||
|
||||
err()
|
||||
{
|
||||
exitcode=$1
|
||||
shift
|
||||
echo ${command} $* >&2
|
||||
exit $exitcode
|
||||
}
|
||||
|
||||
warn()
|
||||
{
|
||||
echo ${command} $* >&2
|
||||
}
|
||||
|
||||
compsuffix()
|
||||
{
|
||||
case "$1" in
|
||||
gzip)
|
||||
echo ".gz"
|
||||
;;
|
||||
bzip2)
|
||||
echo ".bz2"
|
||||
;;
|
||||
none)
|
||||
echo ""
|
||||
;;
|
||||
*)
|
||||
echo "Unsupposed compression type ignored: $1" >&2
|
||||
echo ""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
compflag()
|
||||
{
|
||||
case "$1" in
|
||||
gzip)
|
||||
echo "z"
|
||||
;;
|
||||
bzip2)
|
||||
echo "y"
|
||||
;;
|
||||
none)
|
||||
echo ""
|
||||
;;
|
||||
*)
|
||||
echo "Unsupposed compression type ignored: $1" >&2
|
||||
echo ""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
case "$1" in
|
||||
-D)
|
||||
shift;
|
||||
delete_old=1
|
||||
;;
|
||||
-h)
|
||||
shift;
|
||||
usage 0
|
||||
;;
|
||||
-r)
|
||||
shift;
|
||||
if [ -z "$1" ]; then
|
||||
usage 1 "-r requires an argument"
|
||||
fi
|
||||
rrddir=$1
|
||||
shift
|
||||
;;
|
||||
-s)
|
||||
shift;
|
||||
if [ -z "$1" ]; then
|
||||
usage 1 "-s requires an argument"
|
||||
fi
|
||||
snapdir=$1
|
||||
shift
|
||||
;;
|
||||
-z)
|
||||
shift;
|
||||
if [ -z "$1" ]; then
|
||||
usage 1 "-z requires an argument"
|
||||
fi
|
||||
rrddir=$1
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
usage 1 "unknown argument $1"
|
||||
;;
|
||||
*)
|
||||
break
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -n "$2" ]; then
|
||||
snapname=$2
|
||||
fi
|
||||
|
||||
basefile=${snapdir}/${snapname}.tar`compsuffix ${comp}`
|
||||
tarcmd="tar `compflag ${comp}`"
|
||||
|
||||
case "$1" in
|
||||
save)
|
||||
if [ ! -d ${rrddir} ]; then
|
||||
err 2 "rrddir ${rrddir} does not exist"
|
||||
fi
|
||||
if [ ! -d ${snapdir} ]; then
|
||||
err 2 "snapdir ${snapdir} does not exist"
|
||||
fi
|
||||
echo "saving ${rrddir} to ${basefile}"
|
||||
cd ${rrddir}
|
||||
if ! ${tarcmd}cf ${basefile}.new .; then
|
||||
err 2 "Failed to create ${basefile}.new"
|
||||
fi
|
||||
if [ -e ${basefile} ]; then
|
||||
mv ${basefile} ${basefile}.old
|
||||
sync
|
||||
fi
|
||||
mv ${basefile}.new ${basefile}
|
||||
sync
|
||||
if [ $delete_old -ne 0 ]; then
|
||||
rm ${basefile}.old
|
||||
fi
|
||||
sync
|
||||
;;
|
||||
restore)
|
||||
for file in ${basefile} ${basefile}.new ${basefile}.old; do
|
||||
if [ -e ${file} ]; then
|
||||
if ${tarcmd}tf ${file} >/dev/null 2>&1 ; then
|
||||
sourcefile=${file}
|
||||
break
|
||||
else
|
||||
warn "${file} exists but is not a valid tarball. Ignoring."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [ -z "$sourcefile" ]; then
|
||||
err 1 "no snapshot found in ${snapdir}."
|
||||
fi
|
||||
echo "restoring ${rrddir} from ${sourcefile}"
|
||||
if [ ! -d "${rrddir}" ]; then
|
||||
err 1 "${rrddir} does not exist"
|
||||
fi
|
||||
cd ${rrddir}
|
||||
${tarcmd}xpf ${sourcefile}
|
||||
;;
|
||||
*)
|
||||
usage 1 "unknown command: $1"
|
||||
;;
|
||||
esac
|
|
@ -13,6 +13,7 @@ etc/gmond.conf.sample
|
|||
%%LIBGANGLIA%%lib/libganglia.la
|
||||
%%LIBGANGLIA%%lib/libganglia.a
|
||||
%%GMETAD%%sbin/gmetad
|
||||
%%GMETAD%%sbin/gmetasnap
|
||||
sbin/gmond
|
||||
@unexec rmdir %D/var/db/ganglia/rrds 2>/dev/null || true
|
||||
@unexec rmdir %D/var/db/ganglia 2>/dev/null || true
|
||||
|
|
Loading…
Reference in a new issue