2016-10-24 23:03:18 +02:00
|
|
|
#!/usr/bin/env sh
|
2016-02-07 16:09:52 +01:00
|
|
|
# wordpress-multisite plugin
|
|
|
|
#
|
2016-10-24 23:03:18 +02:00
|
|
|
# Version 0.2
|
|
|
|
# Date 2016-10-24
|
|
|
|
# Code improvements
|
|
|
|
#
|
2016-02-07 16:09:52 +01:00
|
|
|
# Version 0.1
|
|
|
|
# Date 2016-02-07
|
2016-10-24 23:03:18 +02:00
|
|
|
# Initial release
|
|
|
|
#
|
2016-02-07 16:09:52 +01:00
|
|
|
: <<=cut
|
|
|
|
=head1 NAME
|
|
|
|
Wordpress-Multisite Munin Plugin
|
|
|
|
|
|
|
|
A Munin plugin to monitor posts, comments and pingbacks from every multisite instance.
|
|
|
|
It uses multigraphs and also shows the combined number of posts, comments, pingbacks, instances and users.
|
|
|
|
|
|
|
|
Most database requests came from the wordpress-mu-plugin which was written by Andre Darafarin and Chris Bair
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
The plugin need access to the wordpress database
|
|
|
|
|
|
|
|
=head2 Config file
|
|
|
|
Create the config file plugin-conf.d/wordpress with the following values:
|
|
|
|
|
2016-10-24 23:03:18 +02:00
|
|
|
=over 4
|
2016-02-07 16:09:52 +01:00
|
|
|
=item * [wordpress*]
|
2016-10-24 23:03:18 +02:00
|
|
|
=item * env.mysqlopts <ie -uroot -prootpass>
|
|
|
|
=item * env.mysqlconnection <defaults to -hlocalhost>
|
|
|
|
=item * env.database <ie -Dwordpress>
|
|
|
|
=item * env.dbprefix <defaults to wp_>
|
2016-02-07 16:09:52 +01:00
|
|
|
|
|
|
|
=back
|
|
|
|
|
2016-10-24 23:03:18 +02:00
|
|
|
=head1 VERSION
|
|
|
|
Version 0.2 (2016-02-07)
|
2016-02-07 16:09:52 +01:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Jonas Palm <jonaspalm . posteo . de>
|
|
|
|
|
2016-10-24 23:03:18 +02:00
|
|
|
=head1 LICENSE
|
2016-02-07 16:09:52 +01:00
|
|
|
|
2016-10-24 23:03:18 +02:00
|
|
|
GPLv3 or higher
|
2016-02-07 16:09:52 +01:00
|
|
|
|
2016-10-24 23:03:18 +02:00
|
|
|
=cut
|
2016-02-07 16:09:52 +01:00
|
|
|
|
2016-10-24 23:03:18 +02:00
|
|
|
# fill vars
|
|
|
|
DB_OPTIONS=${mysqlopts}
|
|
|
|
DB_CONNECTION=${mysqlconnection:--hlocalhost}
|
|
|
|
DB_NAME=${database}
|
|
|
|
DB_PREFIX=${dbprefix:-wp_}
|
|
|
|
|
|
|
|
MYSQL_CMD=$(which mysql)
|
|
|
|
wp_get() {
|
|
|
|
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;"
|
|
|
|
esac
|
|
|
|
|
|
|
|
$MYSQL_CMD $DB_CONNECTION $DB_OPTIONS $DB_NAME --column-names=0 -s --execute="$QUERY"
|
|
|
|
}
|
|
|
|
|
|
|
|
# whole network
|
2016-02-07 16:09:52 +01:00
|
|
|
if [ "$1" = "config" ]; then
|
2016-10-24 23:03:18 +02:00
|
|
|
echo "multigraph wordpress"
|
|
|
|
echo "graph_title Wordpress Mulitsite"
|
|
|
|
echo "graph_order instances users posts comments pingbacks"
|
|
|
|
echo "graph_vlabel Wordpress"
|
|
|
|
echo "graph_category Wordpress"
|
|
|
|
echo "graph_info Some Statistics of Wordpress"
|
|
|
|
echo "instances.label Instances"
|
|
|
|
echo "users.label Users"
|
|
|
|
echo "posts.label Posts"
|
|
|
|
echo "comments.label Comments"
|
|
|
|
echo "pingbacks.label Pingbacks"
|
2016-02-07 16:09:52 +01:00
|
|
|
else
|
2016-10-24 23:03:18 +02:00
|
|
|
for n in $(wp_get ids); do
|
|
|
|
i=
|
|
|
|
test "$n" -gt "1" && i=${n}_
|
|
|
|
|
|
|
|
POSTS=$(expr $POSTS + $(wp_get posts $i))
|
|
|
|
COMMENTS=$(expr $COMMENTS + $(wp_get comments $i))
|
|
|
|
PINGBACKS=$(expr $PINGBACKS + $(wp_get pingbacks $i))
|
|
|
|
CNT=$(expr $CNT + 1)
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "multigraph wordpress"
|
|
|
|
echo "posts.value $POSTS"
|
|
|
|
echo "comments.value $COMMENTS"
|
|
|
|
echo "pingbacks.value $PINGBACKS"
|
|
|
|
echo "instances.value $CNT"
|
|
|
|
echo "users.value $(wp_get users)"
|
2016-02-07 16:09:52 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# single blogs
|
2016-10-24 23:03:18 +02:00
|
|
|
for n in $(wp_get ids); do
|
|
|
|
i=
|
|
|
|
test "$n" -gt "1" && i=${n}_
|
|
|
|
test "$n" -le "9" && n=0${n}
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
echo "multigraph wordpress.site_${n}"
|
|
|
|
echo "graph_title $(wp_get title $i)"
|
|
|
|
echo "graph_order posts comments pingbacks"
|
|
|
|
echo "graph_vlabel Wordpress ID ${n}"
|
|
|
|
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)"
|
|
|
|
fi
|
2016-02-07 16:09:52 +01:00
|
|
|
done
|