Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / wordpress / wordpress-multisite @ 84c28707

Historique | Voir | Annoter | Télécharger (3,8 ko)

1
#!/bin/sh
2
# wordpress-multisite plugin
3
: <<=cut
4
=head1 NAME
5

    
6
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
Most database queries came from the wordpress-mu-plugin which was written by Andre Darafarin and Chris Bair
12

    
13
=head1 CONFIGURATION
14

    
15
The plugin need access to the wordpress database
16

    
17
=head2 Config file
18

    
19
Create the config file plugin-conf.d/wordpress with the following values:
20

    
21
  [wordpress*]
22
  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

    
31
=head1 VERSION
32

    
33
Version 0.4 (2017-01-13)
34

    
35
=head1 AUTHOR
36

    
37
Jonas Palm <jonaspalm . posteo . de>
38

    
39
=head1 LICENSE
40

    
41
GPLv3 or higher
42
=cut
43

    
44
# fill vars
45
DB_OPTIONS=${mysqlopts}
46
DB_CONNECTION=${mysqlconnection:--hlocalhost}
47
DB_NAME=${database}
48
DB_PREFIX=${dbprefix:-wp_}
49
NETWORK_SIZE=${networksize:-2}
50

    
51
MYSQL_CMD=$(which mysql)
52

    
53
# wp_get dataname [blogid]
54
wp_get() {
55
	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
	case $1 in
64
		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
	esac
71

    
72
	"$MYSQL_CMD" $DB_CONNECTION $DB_OPTIONS "$DB_NAME" --column-names=0 -s --execute="$DB_QUERY"
73
}
74

    
75
# whole network
76
if [ "$1" = "config" ]; then
77
	echo "multigraph wordpress"
78
	echo "graph_title Wordpress Mulitsite"
79
	echo "graph_order instances users posts comments pingbacks"
80
	echo "graph_vlabel Wordpress"
81
	echo "graph_category cms"
82
	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
else
89
	for n in $(wp_get ids); do
90
		POSTS=$((POSTS + $(wp_get posts "$n")))
91
		COMMENTS=$((COMMENTS + $(wp_get comments "$n")))
92
		PINGBACKS=$((PINGBACKS + $(wp_get pingbacks "$n")))
93
		CNT=$((CNT + 1))
94
	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
fi
103

    
104
# single blogs
105
for n in $(wp_get ids); do
106
	blogid_sortable="$(printf "%0${NETWORK_SIZE}d" "$n")"
107

    
108
	if [ "$1" = "config" ]; then
109
		echo "multigraph wordpress.site_${blogid_sortable}"
110
		echo "graph_title $(wp_get title "$n")"
111
		echo "graph_order posts comments pingbacks"
112
		echo "graph_vlabel Wordpress ID ${blogid_sortable}"
113
		echo "posts.label Posts"
114
		echo "comments.label Comments"
115
		echo "pingbacks.label Pingbacks"
116
	else
117
		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
	fi
122
done