root / plugins / other / wordpress-multisite @ c679de12
Historique | Voir | Annoter | Télécharger (3,33 ko)
| 1 |
#!/usr/bin/env sh |
|---|---|
| 2 |
# wordpress-multisite plugin |
| 3 |
# |
| 4 |
# Version 0.2 |
| 5 |
# Date 2016-10-24 |
| 6 |
# Code improvements |
| 7 |
# |
| 8 |
# Version 0.1 |
| 9 |
# Date 2016-02-07 |
| 10 |
# Initial release |
| 11 |
# |
| 12 |
: <<=cut |
| 13 |
=head1 NAME |
| 14 |
Wordpress-Multisite Munin Plugin |
| 15 |
|
| 16 |
A Munin plugin to monitor posts, comments and pingbacks from every multisite instance. |
| 17 |
It uses multigraphs and also shows the combined number of posts, comments, pingbacks, instances and users. |
| 18 |
|
| 19 |
Most database requests came from the wordpress-mu-plugin which was written by Andre Darafarin and Chris Bair |
| 20 |
|
| 21 |
=head1 CONFIGURATION |
| 22 |
The plugin need access to the wordpress database |
| 23 |
|
| 24 |
=head2 Config file |
| 25 |
Create the config file plugin-conf.d/wordpress with the following values: |
| 26 |
|
| 27 |
=over 4 |
| 28 |
=item * [wordpress*] |
| 29 |
=item * env.mysqlopts <ie -uroot -prootpass> |
| 30 |
=item * env.mysqlconnection <defaults to -hlocalhost> |
| 31 |
=item * env.database <ie -Dwordpress> |
| 32 |
=item * env.dbprefix <defaults to wp_> |
| 33 |
|
| 34 |
=back |
| 35 |
|
| 36 |
=head1 VERSION |
| 37 |
Version 0.2 (2016-02-07) |
| 38 |
|
| 39 |
=head1 AUTHOR |
| 40 |
|
| 41 |
Jonas Palm <jonaspalm . posteo . de> |
| 42 |
|
| 43 |
=head1 LICENSE |
| 44 |
|
| 45 |
GPLv3 or higher |
| 46 |
|
| 47 |
=cut |
| 48 |
|
| 49 |
# fill vars |
| 50 |
DB_OPTIONS=${mysqlopts}
|
| 51 |
DB_CONNECTION=${mysqlconnection:--hlocalhost}
|
| 52 |
DB_NAME=${database}
|
| 53 |
DB_PREFIX=${dbprefix:-wp_}
|
| 54 |
|
| 55 |
MYSQL_CMD=$(which mysql) |
| 56 |
wp_get() {
|
| 57 |
case $1 in |
| 58 |
comments) QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${2}comments WHERE comment_approved = '1' AND comment_type = '';" ;;
|
| 59 |
ids) QUERY="SELECT blog_id FROM ${DB_PREFIX}blogs;" ;;
|
| 60 |
pingbacks) QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${2}comments WHERE comment_approved = '1' AND comment_type = 'pingback';" ;;
|
| 61 |
posts) QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${2}posts WHERE post_status = 'publish' AND post_password = '' AND post_type = 'post';" ;;
|
| 62 |
title) QUERY="SELECT option_value FROM ${DB_PREFIX}${2}options WHERE option_name = 'siteurl';" ;;
|
| 63 |
users) QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}users;"
|
| 64 |
esac |
| 65 |
|
| 66 |
$MYSQL_CMD $DB_CONNECTION $DB_OPTIONS $DB_NAME --column-names=0 -s --execute="$QUERY" |
| 67 |
} |
| 68 |
|
| 69 |
# whole network |
| 70 |
if [ "$1" = "config" ]; then |
| 71 |
echo "multigraph wordpress" |
| 72 |
echo "graph_title Wordpress Mulitsite" |
| 73 |
echo "graph_order instances users posts comments pingbacks" |
| 74 |
echo "graph_vlabel Wordpress" |
| 75 |
echo "graph_category Wordpress" |
| 76 |
echo "graph_info Some Statistics of Wordpress" |
| 77 |
echo "instances.label Instances" |
| 78 |
echo "users.label Users" |
| 79 |
echo "posts.label Posts" |
| 80 |
echo "comments.label Comments" |
| 81 |
echo "pingbacks.label Pingbacks" |
| 82 |
else |
| 83 |
for n in $(wp_get ids); do |
| 84 |
i= |
| 85 |
test "$n" -gt "1" && i=${n}_
|
| 86 |
|
| 87 |
POSTS=$(expr $POSTS + $(wp_get posts $i)) |
| 88 |
COMMENTS=$(expr $COMMENTS + $(wp_get comments $i)) |
| 89 |
PINGBACKS=$(expr $PINGBACKS + $(wp_get pingbacks $i)) |
| 90 |
CNT=$(expr $CNT + 1) |
| 91 |
done |
| 92 |
|
| 93 |
echo "multigraph wordpress" |
| 94 |
echo "posts.value $POSTS" |
| 95 |
echo "comments.value $COMMENTS" |
| 96 |
echo "pingbacks.value $PINGBACKS" |
| 97 |
echo "instances.value $CNT" |
| 98 |
echo "users.value $(wp_get users)" |
| 99 |
fi |
| 100 |
|
| 101 |
# single blogs |
| 102 |
for n in $(wp_get ids); do |
| 103 |
i= |
| 104 |
test "$n" -gt "1" && i=${n}_
|
| 105 |
test "$n" -le "9" && n=0${n}
|
| 106 |
|
| 107 |
if [ "$1" = "config" ]; then |
| 108 |
echo "multigraph wordpress.site_${n}"
|
| 109 |
echo "graph_title $(wp_get title $i)" |
| 110 |
echo "graph_order posts comments pingbacks" |
| 111 |
echo "graph_vlabel Wordpress ID ${n}"
|
| 112 |
echo "posts.label Posts" |
| 113 |
echo "comments.label Comments" |
| 114 |
echo "pingbacks.label Pingbacks" |
| 115 |
else |
| 116 |
echo "multigraph wordpress.site_${n}"
|
| 117 |
echo "posts.value $(wp_get posts $i)" |
| 118 |
echo "comments.value $(wp_get comments $i)" |
| 119 |
echo "pingbacks.value $(wp_get pingbacks $i)" |
| 120 |
fi |
| 121 |
done |
