2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

better variable names, added option for length of blogid to sort multigraphs

This commit is contained in:
null-git 2017-01-13 20:32:31 +01:00
parent d3de1a48de
commit 820ef5b009

View File

@ -1,18 +1,5 @@
#!/usr/bin/env sh
#!/bin/sh
# wordpress-multisite plugin
#
# Version 0.3
# Date 2017-01-12
# Some last minor fixes
#
# Version 0.2
# Date 2016-10-24
# Code improvements
#
# Version 0.1
# Date 2016-02-07
# Initial release
#
: <<=cut
=head1 NAME
@ -32,20 +19,18 @@ The plugin need access to the wordpress database
Create the config file plugin-conf.d/wordpress with the following values:
[wordpress*]
env.mysqlopts # i.e. -uroot -prootpass
env.mysqlconnection # defaults to -hlocalhost
env.database # i.e. -Dwordpress
env.dbprefix # defaults to wp_
env.mysqlopts # I.e. -uroot -prootpass
env.mysqlconnection # Defaults to -hlocalhost
env.database # I.e. wordpress
env.dbprefix # Defaults to wp_
env.networksize # Blogs are ordered by id in multigraph view. This value should contain the numbers
# of digits that are needed to fit all the blog id's in. This value influences the
# designation of data to munin and it will start collecting fresh data if you change
# this number. Defaults to 2, (so networks with <= 99 blogs will be sorted correctly)
=head1 VERSION
Version 0.3 (2017-01-12)
=head2 Some minor fixes:
* fixed perldoc
* fixed some syntax warnings from shellcheck
* replaced expr by $(( ))
Version 0.4 (2017-01-13)
=head1 AUTHOR
@ -61,19 +46,30 @@ DB_OPTIONS=${mysqlopts}
DB_CONNECTION=${mysqlconnection:--hlocalhost}
DB_NAME=${database}
DB_PREFIX=${dbprefix:-wp_}
NETWORK_SIZE=${network_size:-2}
MYSQL_CMD=$(which mysql)
# wp_get dataname [blogid]
wp_get() {
local DB_QUERY=
local BLOGID=
if [ -n "$2" ] && [ "$2" -gt "1" ]; then
# DB prefix for every wordpress instance in the network
# Nr 1 is the main network blog and doesn't has a prefix
BLOGID=${2}_
fi
case $1 in
comments) QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${2}comments WHERE comment_approved = '1' AND comment_type = '';" ;;
ids) QUERY="SELECT blog_id FROM ${DB_PREFIX}blogs;" ;;
pingbacks) QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${2}comments WHERE comment_approved = '1' AND comment_type = 'pingback';" ;;
posts) QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${2}posts WHERE post_status = 'publish' AND post_password = '' AND post_type = 'post';" ;;
title) QUERY="SELECT option_value FROM ${DB_PREFIX}${2}options WHERE option_name = 'siteurl';" ;;
users) QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}users;"
comments) DB_QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${BLOGID}comments WHERE comment_approved = '1' AND comment_type = '';" ;;
ids) DB_QUERY="SELECT blog_id FROM ${DB_PREFIX}blogs;" ;;
pingbacks) DB_QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${BLOGID}comments WHERE comment_approved = '1' AND comment_type = 'pingback';" ;;
posts) DB_QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${BLOGID}posts WHERE post_status = 'publish' AND post_password = '' AND post_type = 'post';" ;;
title) DB_QUERY="SELECT option_value FROM ${DB_PREFIX}${BLOGID}options WHERE option_name = 'siteurl';" ;;
users) DB_QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}users;"
esac
$MYSQL_CMD $DB_CONNECTION $DB_OPTIONS $DB_NAME --column-names=0 -s --execute="$QUERY"
"$MYSQL_CMD" $DB_CONNECTION $DB_OPTIONS "$DB_NAME" --column-names=0 -s --execute="$DB_QUERY"
}
# whole network
@ -91,12 +87,9 @@ if [ "$1" = "config" ]; then
echo "pingbacks.label Pingbacks"
else
for n in $(wp_get ids); do
i=
test "$n" -gt "1" && i=${n}_
POSTS=$((POSTS + $(wp_get posts "$i")))
COMMENTS=$((COMMENTS + $(wp_get comments "$i")))
PINGBACKS=$((PINGBACKS + $(wp_get pingbacks "$i")))
POSTS=$((POSTS + $(wp_get posts "$n")))
COMMENTS=$((COMMENTS + $(wp_get comments "$n")))
PINGBACKS=$((PINGBACKS + $(wp_get pingbacks "$n")))
CNT=$((CNT + 1))
done
@ -110,22 +103,20 @@ fi
# single blogs
for n in $(wp_get ids); do
i=
test "$n" -gt "1" && i=${n}_
test "$n" -le "9" && n=0${n}
blogid_sortable="$(printf "%0${NETWORK_SIZE}d" "$n")"
if [ "$1" = "config" ]; then
echo "multigraph wordpress.site_${n}"
echo "graph_title $(wp_get title "$i")"
echo "multigraph wordpress.site_${blogid_sortable}"
echo "graph_title $(wp_get title "$n")"
echo "graph_order posts comments pingbacks"
echo "graph_vlabel Wordpress ID ${n}"
echo "graph_vlabel Wordpress ID ${blogid_sortable}"
echo "posts.label Posts"
echo "comments.label Comments"
echo "pingbacks.label Pingbacks"
else
echo "multigraph wordpress.site_${n}"
echo "posts.value $(wp_get posts "$i")"
echo "comments.value $(wp_get comments "$i")"
echo "pingbacks.value $(wp_get pingbacks "$i")"
echo "multigraph wordpress.site_${blogid_sortable}"
echo "posts.value $(wp_get posts "$n")"
echo "comments.value $(wp_get comments "$n")"
echo "pingbacks.value $(wp_get pingbacks "$n")"
fi
done