aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2005-04-28 01:52:41 +0800
committerbrooks <brooks@FreeBSD.org>2005-04-28 01:52:41 +0800
commitb4befb6b45388a4ad72f0dc811e254e004d6ea1f (patch)
tree373a8b4fa280dc499b2f3e42bf15a06e578003c8 /sysutils
parenteb4f75b349f91fdca4e1de4168d5031cd21bf191 (diff)
downloadfreebsd-ports-gnome-b4befb6b45388a4ad72f0dc811e254e004d6ea1f.tar.gz
freebsd-ports-gnome-b4befb6b45388a4ad72f0dc811e254e004d6ea1f.tar.zst
freebsd-ports-gnome-b4befb6b45388a4ad72f0dc811e254e004d6ea1f.zip
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.
Diffstat (limited to 'sysutils')
-rw-r--r--sysutils/ganglia-monitor-core/Makefile3
-rw-r--r--sysutils/ganglia-monitor-core/files/ganglia.sh.in45
-rw-r--r--sysutils/ganglia-monitor-core/files/gmetasnap.sh195
-rw-r--r--sysutils/ganglia-monitor-core/pkg-plist1
4 files changed, 243 insertions, 1 deletions
diff --git a/sysutils/ganglia-monitor-core/Makefile b/sysutils/ganglia-monitor-core/Makefile
index be090e25b5d8..70c689b03be0 100644
--- a/sysutils/ganglia-monitor-core/Makefile
+++ b/sysutils/ganglia-monitor-core/Makefile
@@ -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
diff --git a/sysutils/ganglia-monitor-core/files/ganglia.sh.in b/sysutils/ganglia-monitor-core/files/ganglia.sh.in
index 964c748d9017..2876a8f22846 100644
--- a/sysutils/ganglia-monitor-core/files/ganglia.sh.in
+++ b/sysutils/ganglia-monitor-core/files/ganglia.sh.in
@@ -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}"
diff --git a/sysutils/ganglia-monitor-core/files/gmetasnap.sh b/sysutils/ganglia-monitor-core/files/gmetasnap.sh
new file mode 100644
index 000000000000..ed7f9f92a44f
--- /dev/null
+++ b/sysutils/ganglia-monitor-core/files/gmetasnap.sh
@@ -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
diff --git a/sysutils/ganglia-monitor-core/pkg-plist b/sysutils/ganglia-monitor-core/pkg-plist
index 94cf3339b3fc..64836c856217 100644
--- a/sysutils/ganglia-monitor-core/pkg-plist
+++ b/sysutils/ganglia-monitor-core/pkg-plist
@@ -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