root / plugins / wordpress / wordpress-multisite @ 84c28707
Historique | Voir | Annoter | Télécharger (3,8 ko)
| 1 | 820ef5b0 | null-git | #!/bin/sh |
|---|---|---|---|
| 2 | 26cf15aa | Jonas Palm | # wordpress-multisite plugin |
| 3 | : <<=cut |
||
| 4 | =head1 NAME |
||
| 5 | d3de1a48 | null-git | |
| 6 | 26cf15aa | Jonas Palm | Wordpress-Multisite Munin Plugin |
| 7 | |||
| 8 | A Munin plugin to monitor posts, comments and pingbacks from every multisite instance. |
||
| 9 | It uses multigraphs and also shows the combined number of posts, comments, pingbacks, instances and users. |
||
| 10 | |||
| 11 | d3de1a48 | null-git | Most database queries came from the wordpress-mu-plugin which was written by Andre Darafarin and Chris Bair |
| 12 | 26cf15aa | Jonas Palm | |
| 13 | =head1 CONFIGURATION |
||
| 14 | d3de1a48 | null-git | |
| 15 | 26cf15aa | Jonas Palm | The plugin need access to the wordpress database |
| 16 | |||
| 17 | =head2 Config file |
||
| 18 | d3de1a48 | null-git | |
| 19 | 26cf15aa | Jonas Palm | Create the config file plugin-conf.d/wordpress with the following values: |
| 20 | |||
| 21 | d3de1a48 | null-git | [wordpress*] |
| 22 | 820ef5b0 | null-git | env.mysqlopts # I.e. -uroot -prootpass |
| 23 | env.mysqlconnection # Defaults to -hlocalhost |
||
| 24 | env.database # I.e. wordpress |
||
| 25 | env.dbprefix # Defaults to wp_ |
||
| 26 | env.networksize # Blogs are ordered by id in multigraph view. This value should contain the numbers |
||
| 27 | # of digits that are needed to fit all the blog id's in. This value influences the |
||
| 28 | # designation of data to munin and it will start collecting fresh data if you change |
||
| 29 | # this number. Defaults to 2, (so networks with <= 99 blogs will be sorted correctly) |
||
| 30 | d3de1a48 | null-git | |
| 31 | =head1 VERSION |
||
| 32 | 26cf15aa | Jonas Palm | |
| 33 | 820ef5b0 | null-git | Version 0.4 (2017-01-13) |
| 34 | 26cf15aa | Jonas Palm | |
| 35 | =head1 AUTHOR |
||
| 36 | |||
| 37 | Jonas Palm <jonaspalm . posteo . de> |
||
| 38 | |||
| 39 | c679de12 | Jonas Palm | =head1 LICENSE |
| 40 | 26cf15aa | Jonas Palm | |
| 41 | c679de12 | Jonas Palm | GPLv3 or higher |
| 42 | =cut |
||
| 43 | 26cf15aa | Jonas Palm | |
| 44 | c679de12 | Jonas Palm | # fill vars |
| 45 | DB_OPTIONS=${mysqlopts}
|
||
| 46 | DB_CONNECTION=${mysqlconnection:--hlocalhost}
|
||
| 47 | DB_NAME=${database}
|
||
| 48 | DB_PREFIX=${dbprefix:-wp_}
|
||
| 49 | 130466f1 | null-git | NETWORK_SIZE=${networksize:-2}
|
| 50 | c679de12 | Jonas Palm | |
| 51 | MYSQL_CMD=$(which mysql) |
||
| 52 | 820ef5b0 | null-git | |
| 53 | # wp_get dataname [blogid] |
||
| 54 | c679de12 | Jonas Palm | wp_get() {
|
| 55 | 820ef5b0 | null-git | local DB_QUERY= |
| 56 | local BLOGID= |
||
| 57 | if [ -n "$2" ] && [ "$2" -gt "1" ]; then |
||
| 58 | # DB prefix for every wordpress instance in the network |
||
| 59 | # Nr 1 is the main network blog and doesn't has a prefix |
||
| 60 | BLOGID=${2}_
|
||
| 61 | fi |
||
| 62 | |||
| 63 | c679de12 | Jonas Palm | case $1 in |
| 64 | 820ef5b0 | null-git | comments) DB_QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${BLOGID}comments WHERE comment_approved = '1' AND comment_type = '';" ;;
|
| 65 | ids) DB_QUERY="SELECT blog_id FROM ${DB_PREFIX}blogs;" ;;
|
||
| 66 | pingbacks) DB_QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${BLOGID}comments WHERE comment_approved = '1' AND comment_type = 'pingback';" ;;
|
||
| 67 | posts) DB_QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}${BLOGID}posts WHERE post_status = 'publish' AND post_password = '' AND post_type = 'post';" ;;
|
||
| 68 | title) DB_QUERY="SELECT option_value FROM ${DB_PREFIX}${BLOGID}options WHERE option_name = 'siteurl';" ;;
|
||
| 69 | users) DB_QUERY="SELECT COUNT(*) FROM ${DB_PREFIX}users;"
|
||
| 70 | c679de12 | Jonas Palm | esac |
| 71 | |||
| 72 | 820ef5b0 | null-git | "$MYSQL_CMD" $DB_CONNECTION $DB_OPTIONS "$DB_NAME" --column-names=0 -s --execute="$DB_QUERY" |
| 73 | c679de12 | Jonas Palm | } |
| 74 | |||
| 75 | # whole network |
||
| 76 | 26cf15aa | Jonas Palm | if [ "$1" = "config" ]; then |
| 77 | c679de12 | Jonas Palm | echo "multigraph wordpress" |
| 78 | echo "graph_title Wordpress Mulitsite" |
||
| 79 | echo "graph_order instances users posts comments pingbacks" |
||
| 80 | echo "graph_vlabel Wordpress" |
||
| 81 | 84c28707 | dipohl | echo "graph_category cms" |
| 82 | c679de12 | Jonas Palm | echo "graph_info Some Statistics of Wordpress" |
| 83 | echo "instances.label Instances" |
||
| 84 | echo "users.label Users" |
||
| 85 | echo "posts.label Posts" |
||
| 86 | echo "comments.label Comments" |
||
| 87 | echo "pingbacks.label Pingbacks" |
||
| 88 | 26cf15aa | Jonas Palm | else |
| 89 | c679de12 | Jonas Palm | for n in $(wp_get ids); do |
| 90 | 820ef5b0 | null-git | POSTS=$((POSTS + $(wp_get posts "$n"))) |
| 91 | COMMENTS=$((COMMENTS + $(wp_get comments "$n"))) |
||
| 92 | PINGBACKS=$((PINGBACKS + $(wp_get pingbacks "$n"))) |
||
| 93 | d3de1a48 | null-git | CNT=$((CNT + 1)) |
| 94 | c679de12 | Jonas Palm | done |
| 95 | |||
| 96 | echo "multigraph wordpress" |
||
| 97 | echo "posts.value $POSTS" |
||
| 98 | echo "comments.value $COMMENTS" |
||
| 99 | echo "pingbacks.value $PINGBACKS" |
||
| 100 | echo "instances.value $CNT" |
||
| 101 | echo "users.value $(wp_get users)" |
||
| 102 | 26cf15aa | Jonas Palm | fi |
| 103 | |||
| 104 | # single blogs |
||
| 105 | c679de12 | Jonas Palm | for n in $(wp_get ids); do |
| 106 | 820ef5b0 | null-git | blogid_sortable="$(printf "%0${NETWORK_SIZE}d" "$n")"
|
| 107 | c679de12 | Jonas Palm | |
| 108 | if [ "$1" = "config" ]; then |
||
| 109 | 820ef5b0 | null-git | echo "multigraph wordpress.site_${blogid_sortable}"
|
| 110 | echo "graph_title $(wp_get title "$n")" |
||
| 111 | c679de12 | Jonas Palm | echo "graph_order posts comments pingbacks" |
| 112 | 820ef5b0 | null-git | echo "graph_vlabel Wordpress ID ${blogid_sortable}"
|
| 113 | c679de12 | Jonas Palm | echo "posts.label Posts" |
| 114 | echo "comments.label Comments" |
||
| 115 | echo "pingbacks.label Pingbacks" |
||
| 116 | else |
||
| 117 | 820ef5b0 | null-git | echo "multigraph wordpress.site_${blogid_sortable}"
|
| 118 | echo "posts.value $(wp_get posts "$n")" |
||
| 119 | echo "comments.value $(wp_get comments "$n")" |
||
| 120 | echo "pingbacks.value $(wp_get pingbacks "$n")" |
||
| 121 | c679de12 | Jonas Palm | fi |
| 122 | 26cf15aa | Jonas Palm | done |
