2017-01-13 20:32:31 +01:00
|
|
|
#!/bin/sh
|
2016-02-07 16:09:52 +01:00
|
|
|
# wordpress-multisite plugin
|
|
|
|
: <<=cut
|
|
|
|
=head1 NAME
|
2017-01-12 15:10:54 +01:00
|
|
|
|
2016-02-07 16:09:52 +01:00
|
|
|
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.
|
|
|
|
|
2017-01-12 15:10:54 +01:00
|
|
|
Most database queries came from the wordpress-mu-plugin which was written by Andre Darafarin and Chris Bair
|
2016-02-07 16:09:52 +01:00
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
2017-01-12 15:10:54 +01:00
|
|
|
|
2016-02-07 16:09:52 +01:00
|
|
|
The plugin need access to the wordpress database
|
|
|
|
|
|
|
|
=head2 Config file
|
2017-01-12 15:10:54 +01:00
|
|
|
|
2016-02-07 16:09:52 +01:00
|
|
|
Create the config file plugin-conf.d/wordpress with the following values:
|
|
|
|
|
2017-01-12 15:10:54 +01:00
|
|
|
[wordpress*]
|
2017-01-13 20:32:31 +01:00
|
|
|
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)
|
2017-01-12 15:10:54 +01:00
|
|
|
|
|
|
|
=head1 VERSION
|
2016-02-07 16:09:52 +01:00
|
|
|
|
2017-01-13 20:32:31 +01:00
|
|
|
Version 0.4 (2017-01-13)
|
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
|
|
|
|
=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_}
|
2017-01-14 12:33:34 +01:00
|
|
|
NETWORK_SIZE=${networksize:-2}
|
2016-10-24 23:03:18 +02:00
|
|
|
|
|
|
|
MYSQL_CMD=$(which mysql)
|
2017-01-13 20:32:31 +01:00
|
|
|
|
|
|
|
# wp_get dataname [blogid]
|
2016-10-24 23:03:18 +02:00
|
|
|
wp_get() {
|
2017-01-13 20:32:31 +01:00
|
|
|
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
|
|
|
|
|
2016-10-24 23:03:18 +02:00
|
|
|
case $1 in
|
2017-01-13 20:32:31 +01:00
|
|
|
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;"
|
2016-10-24 23:03:18 +02:00
|
|
|
esac
|
|
|
|
|
2017-01-13 20:32:31 +01:00
|
|
|
"$MYSQL_CMD" $DB_CONNECTION $DB_OPTIONS "$DB_NAME" --column-names=0 -s --execute="$DB_QUERY"
|
2016-10-24 23:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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"
|
2017-02-22 04:04:04 +01:00
|
|
|
echo "graph_category cms"
|
2016-10-24 23:03:18 +02:00
|
|
|
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
|
2017-01-13 20:32:31 +01:00
|
|
|
POSTS=$((POSTS + $(wp_get posts "$n")))
|
|
|
|
COMMENTS=$((COMMENTS + $(wp_get comments "$n")))
|
|
|
|
PINGBACKS=$((PINGBACKS + $(wp_get pingbacks "$n")))
|
2017-01-12 15:10:54 +01:00
|
|
|
CNT=$((CNT + 1))
|
2016-10-24 23:03:18 +02:00
|
|
|
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
|
2017-01-13 20:32:31 +01:00
|
|
|
blogid_sortable="$(printf "%0${NETWORK_SIZE}d" "$n")"
|
2016-10-24 23:03:18 +02:00
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
2017-01-13 20:32:31 +01:00
|
|
|
echo "multigraph wordpress.site_${blogid_sortable}"
|
|
|
|
echo "graph_title $(wp_get title "$n")"
|
2016-10-24 23:03:18 +02:00
|
|
|
echo "graph_order posts comments pingbacks"
|
2017-01-13 20:32:31 +01:00
|
|
|
echo "graph_vlabel Wordpress ID ${blogid_sortable}"
|
2016-10-24 23:03:18 +02:00
|
|
|
echo "posts.label Posts"
|
|
|
|
echo "comments.label Comments"
|
|
|
|
echo "pingbacks.label Pingbacks"
|
|
|
|
else
|
2017-01-13 20:32:31 +01:00
|
|
|
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")"
|
2016-10-24 23:03:18 +02:00
|
|
|
fi
|
2016-02-07 16:09:52 +01:00
|
|
|
done
|