root / plugins / wordpress / wordpress2 @ 17f78427
Historique | Voir | Annoter | Télécharger (3,52 ko)
| 1 |
#!/usr/bin/php |
|---|---|
| 2 |
<?php |
| 3 |
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); |
| 4 |
/* |
| 5 |
** REQUIRES PHP5-CLI ** |
| 6 |
---- DESCRIPTION ---- |
| 7 |
wordpress plugin for munin |
| 8 |
it's a simple plugin to monitor users, comments, pingbacks |
| 9 |
and your posts from your wordpress homepage. |
| 10 |
|
| 11 |
Simply put your path of wp-config.php in your munin-node |
| 12 |
configuration and this plugin does the rest for you. |
| 13 |
Happy monitoring! :) |
| 14 |
|
| 15 |
This plugin was inspired by the existing wordpress plugin in bash/sh: |
| 16 |
https://github.com/munin-monitoring/contrib/blob/master/plugins/other/wordpress |
| 17 |
|
| 18 |
|
| 19 |
---- CONFIGURATION ---- |
| 20 |
You just need to provide the path to your |
| 21 |
wp-config.php of your wordpress installation. |
| 22 |
|
| 23 |
The configuration for munin-node is by default |
| 24 |
at: /etc/munin/plugin-conf.d/munin-node |
| 25 |
|
| 26 |
Example configuration: |
| 27 |
[wordpress] |
| 28 |
env.NAME Blog of Chuck Norris |
| 29 |
env.CONF /var/www/wordpress/wp-config.php |
| 30 |
|
| 31 |
or you can use: |
| 32 |
|
| 33 |
[wordpress] |
| 34 |
env.NAME Blog of Chuck Norris |
| 35 |
env.HOST 127.0.0.1 |
| 36 |
env.USER blog |
| 37 |
env.PASS password |
| 38 |
env.DBNM wordpress |
| 39 |
env.TBPF wp_ |
| 40 |
|
| 41 |
|
| 42 |
---- More details ---- |
| 43 |
@Author...: Patrik Kernstock |
| 44 |
@Version..: v1.1 |
| 45 |
@Date.....: 26 November 2012 |
| 46 |
@Web......: http://pkern.at |
| 47 |
@Support..: support@pkern.at |
| 48 |
@GitHub...: https://github.com/patschi/munin-plugins |
| 49 |
@License..: http://creativecommons.org/licenses/by-nc-sa/3.0/ |
| 50 |
|
| 51 |
*/ |
| 52 |
#%# family=auto |
| 53 |
#%# capabilities=autoconf |
| 54 |
|
| 55 |
// Get configuration variables |
| 56 |
$d["name"] = getenv("NAME");
|
| 57 |
$d["conf"] = getenv("CONF");
|
| 58 |
$d["host"] = getenv("HOST");
|
| 59 |
$d["user"] = getenv("USER");
|
| 60 |
$d["pass"] = getenv("PASS");
|
| 61 |
$d["tbpf"] = getenv("TBPF");
|
| 62 |
$d["dbnm"] = getenv("DBNM");
|
| 63 |
|
| 64 |
if(!empty($d["conf"]) && !empty($d["name"])) {
|
| 65 |
// INCLUDE wp-config.php |
| 66 |
define("ABSPATH", str_replace("wp-config.php", "", $d["conf"]));
|
| 67 |
require_once($d["conf"]); |
| 68 |
$d["host"] = DB_HOST; |
| 69 |
$d["user"] = DB_USER; |
| 70 |
$d["pass"] = DB_PASSWORD; |
| 71 |
$d["dbnm"] = DB_NAME; |
| 72 |
$d["tbpf"] = $table_prefix; |
| 73 |
} |
| 74 |
|
| 75 |
if($argv[1] == "config") {
|
| 76 |
echo 'graph_title wordpress statistic of '.$d["name"]."\n"; |
| 77 |
echo 'graph_order users posts comments pingbacks'."\n"; |
| 78 |
echo 'graph_vlabel Wordpress'."\n"; |
| 79 |
echo 'graph_info some wordpress statistics of '.$d["name"]."\n"; |
| 80 |
echo 'graph_category cms'."\n"; |
| 81 |
echo 'users.label Users'."\n"; |
| 82 |
echo 'posts.label Posts'."\n"; |
| 83 |
echo 'posts.draw LINE3'."\n"; |
| 84 |
echo 'comments.label Comments'."\n"; |
| 85 |
echo 'pingbacks.label Pingbacks'."\n"; |
| 86 |
exit(0); |
| 87 |
|
| 88 |
}else if($argv[1] == "autoconf") {
|
| 89 |
if(file_exists($d["conf"])) {
|
| 90 |
echo "yes"; |
| 91 |
exit(0); |
| 92 |
}else{
|
| 93 |
echo "no (config does not exist)"; |
| 94 |
exit(1); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
if(!empty($d["conf"])) {
|
| 99 |
if(!file_exists($d["conf"])) {
|
| 100 |
echo "Error: config does not exist!"; |
| 101 |
exit(1); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
// INIT VARIABLES |
| 106 |
$users = 0; |
| 107 |
$posts = 0; |
| 108 |
$comments = 0; |
| 109 |
$pingbacks = 0; |
| 110 |
|
| 111 |
// GET DATA |
| 112 |
mysql_connect($d["host"], $d["user"], $d["pass"]) or die("Error: Failed to connect to the MySQL database!");
|
| 113 |
mysql_select_db($d["dbnm"]) or die("Error: Failed to select database!");
|
| 114 |
|
| 115 |
$users = mysql_result(mysql_query("SELECT COUNT(*) FROM ".$d["tbpf"]."users;"), 0);
|
| 116 |
$posts = mysql_result(mysql_query("SELECT COUNT(*) FROM ".$d["tbpf"]."posts WHERE post_status='publish' AND post_password='' AND post_type='post';"), 0);
|
| 117 |
$comments = mysql_result(mysql_query("SELECT COUNT(*) FROM ".$d["tbpf"]."comments WHERE comment_approved='1' AND comment_type='';"), 0);
|
| 118 |
$pingbacks = mysql_result(mysql_query("SELECT COUNT(*) FROM ".$d["tbpf"]."comments WHERE comment_approved='1' AND comment_type='pingback';"), 0);
|
| 119 |
|
| 120 |
// OUTPUT DATA |
| 121 |
echo "users.value ".$users ."\n"; |
| 122 |
echo "posts.value ".$posts ."\n"; |
| 123 |
echo "comments.value ".$comments ."\n"; |
| 124 |
echo "pingbacks.value ".$pingbacks."\n"; |
| 125 |
|
| 126 |
?> |
