Subversion Repositories ezmunin

[/] [trunk/] [ezpublish_cache] - Rev 8

Compare with Previous | Blame | View Log

#!/bin/sh
# 
# Plugin to monitor useful contents informations for an eZ Publish instance
#
# Usage: Link or copy into /etc/munin/<plugin-directory>/
# After that you can configure the plugin by editing
# your munin configuration file located here (on Debian)
#
# /etc/munin/plugin-conf.d/munin-node
# 
# and add the following lines : 
#
# [ezpublish_*]
# env.dbusername <dbusername>
# env.dbpassword <dbpassword>
# env.dbname <ezpublishdbname>
# env.vardir /path/to/ezpublish/var
# env.ezpublishcluster enabled|disabled
#
# and restart munin-node after that :
#
# sudo /etc/init.d/munin-node restart
#
#

MYSQL_BIN="$(which mysql)"
MYSQL_USER=$dbusername
MYSQL_PASSWORD=$dbpassword
EZPUBLISH_DATABASENAME=$dbname
EZPUBLISH_INSTANCE="$(basename "$0")"

MYSQL="${MYSQL_BIN} -u "${MYSQL_USER}" -p"${MYSQL_PASSWORD}" "${EZPUBLISH_DATABASENAME}""

EZPUBLISH_VAR_DIR=$vardir
EZPUBLISH_CACHE_DIR='cache'

# {{{ variable declaration

monitor_list[0]='templateblocks'   # cache-blocks
monitor_list[1]='ezcontentcache'     # view-cache

label_list[0]='Cache-blocks'
label_list[1]='View cache'

info_list[0]='eZ Publish cache-blocks'
info_list[1]='eZ Publish view cache'

find_list[0]='template-block'
find_list[1]='content'

query_list[0]="SELECT COUNT(name_hash) FROM ezdbfile WHERE scope = 'template-block'"
query_list[1]="SELECT COUNT(name_hash) FROM ezdbfile WHERE scope = 'viewcache'"

# }}}

# {{{ autoconf
# testing if everything is OK
# in the configuration of this plugin
if [ "$1" = "autoconf" ]; then
    echo "yes"
    exit 0
fi
# }}}

# {{{ config
# If run with the "config"-parameter, give out information on how the
# graphs should look. 
if [ "$1" = "config" ]; then

    echo "graph_title ${EZPUBLISH_INSTANCE} : cache statistics"

    echo 'graph_args --base 1000'
    echo 'graph_vlabel Values'
    echo 'graph_scale no'

    echo 'graph_category eZ Publish'

    for ((i=0; i < ${#monitor_list[*]}; i++))
    do
        echo "${monitor_list[$i]}.label ${label_list[$i]}" 
        echo "${monitor_list[$i]}.info ${info_list[$i]}"
    done

    echo 'graph_info Cache statistics for an eZ Publish instance'

    exit 0
fi
# }}}

# {{{ real work
for ((i=0; i< ${#find_list[*]}; i++))
do
    echo -n "${monitor_list[$i]}.value "

    if [ $ezpublishcluster = "enabled" ]
    then
        sql_result="$(${MYSQL} -e "${query_list[$i]}")"
        echo ${sql_result} | cut -d' ' -f 2
    else
        echo `find "${EZPUBLISH_VAR_DIR}/${EZPUBLISH_CACHE_DIR}/${find_list[$i]}" -type 'f' -print | wc -l`
    fi
done
# }}}

# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker:

Compare with Previous | Blame | View Log