diff --git a/plugins/drupal/drupal_files_total.php b/plugins/drupal/drupal_files_total.php new file mode 100755 index 00000000..9b75a788 --- /dev/null +++ b/plugins/drupal/drupal_files_total.php @@ -0,0 +1,87 @@ +#!/usr/bin/php + + * @version 1.0 2013 + * + */ + + +/** + * Environment variabels are set by munin's configuration + * @see /etc/munin/plugin-conf.d/munin-node + */ +$db = getenv('db'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$port = getenv('port'); +if (!$port) + $port = 3306; + +$graph_period = getenv('graph_period'); + +if(count($argv) == 2 && $argv[1] == 'autoconf') { + echo "yes\n"; + exit(0); +} + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Drupal Total Files\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel Files Count / ${graph_period}\n"; + echo "graph_category Drupal\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the online files uploaded to your Drupal site\n"; + + echo "files_total.label total files\n"; + echo "files_total.type GAUGE\n"; + echo "files_total.min 0\n"; + + exit(0); +} + +// Connect to database +$dbh = new mysqli($host, $user, $pass, $db, $port); +if (mysqli_connect_errno()) { + echo "Connecction failed: ".mysqli_connect_error(). PHP_EOL; + exit(1); +} + +// Print out the actual values +$total_files = (int) get_all_files($dbh); +echo "files_total.value $total_files\n"; + +$dbh->close(); + + +/** + * Get count for all online users + * @return integer $count total online users + */ +function get_all_files(&$dbh = NULL) { + + $table_prefix = getenv('table_prefix'); + + $sql = "SELECT COUNT(fid) AS count FROM {$table_prefix}files"; + $result = $dbh->query($sql); + $row = $result->fetch_assoc(); + + return (int) $row['count']; + +} + diff --git a/plugins/drupal/drupal_forums_total.php b/plugins/drupal/drupal_forums_total.php new file mode 100755 index 00000000..38337149 --- /dev/null +++ b/plugins/drupal/drupal_forums_total.php @@ -0,0 +1,109 @@ +#!/usr/bin/php + + * @version 1.0 2013 + * + */ + + +/** + * Environment variabels are set by munin's configuration + * @see /etc/munin/plugin-conf.d/munin-node + */ +$db = getenv('db'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$port = getenv('port'); +if (!$port) + $port = 3306; + +$graph_period = getenv('graph_period'); + +if(count($argv) == 2 && $argv[1] == 'autoconf') { + echo "yes\n"; + exit(0); +} + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Drupal Total Forums\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel Total Forums and comments Count / ${graph_period}\n"; + echo "graph_category Drupal\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the sum of forums and comments made in your Drupal site\n"; + + echo "forums_total.label total forums\n"; + echo "forums_total.type GAUGE\n"; + + echo "comments_total.label total comments\n"; + echo "comments_total.type GAUGE\n"; + + echo "forums_total.min 0\n"; + echo "comments_total.min 0\n"; + + exit(0); +} + +// Connect to database +$dbh = new mysqli($host, $user, $pass, $db, $port); +if (mysqli_connect_errno()) { + echo "Connecction failed: ".mysqli_connect_error(). PHP_EOL; + exit(1); +} + +// Print out the actual values +$forums_total = (int) get_forums_total($dbh); +$comments_total = (int) get_comments_total($dbh); +echo "forums_total.value $forums_total\n"; +echo "comments_total.value $comments_total\n"; + +$dbh->close(); + + +/** + * Get count for all forums + * @return integer $count total forums content type nodes created + */ +function get_forums_total(&$dbh = NULL) { + + $table_prefix = getenv('table_prefix'); + + $sql = "SELECT COUNT(nid) AS count FROM {$table_prefix}node WHERE type = 'forum'"; + $result = $dbh->query($sql); + $row = $result->fetch_assoc(); + + return (int) $row['count']; + +} + +/** + * Get count for all comments made through-out the site for a 'forum' node content type + * @return integer $count all comments + */ +function get_comments_total(&$dbh = NULL) { + + $table_prefix = getenv('table_prefix'); + + $sql = "SELECT COUNT(c.cid) AS count FROM {$table_prefix}comments c JOIN {$table_prefix}node n ON c.nid = n.nid WHERE n.type = 'forum'"; + $result = $dbh->query($sql); + $row = $result->fetch_assoc(); + + return (int) $row['count']; + +} diff --git a/plugins/drupal/drupal_node_distribution_count.php b/plugins/drupal/drupal_node_distribution_count.php new file mode 100755 index 00000000..1a3e661b --- /dev/null +++ b/plugins/drupal/drupal_node_distribution_count.php @@ -0,0 +1,122 @@ +#!/usr/bin/php + + * @version 1.0 2013 + * + */ + + +/** + * Environment variabels are set by munin's configuration + * @see /etc/munin/plugin-conf.d/munin-node + */ +$db = getenv('db'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$port = getenv('port'); +if (!$port) + $port = 3306; + +$graph_period = getenv('graph_period'); + +if(count($argv) == 2 && $argv[1] == 'autoconf') { + echo "yes\n"; + exit(0); +} + +$host = $host.':'.$port; + +// Connect to database +mysql_connect($host, $user, $pass) or die ("Could not connect to database: ". + mysql_error()); +mysql_select_db($db) or die ("Could not select database: ".mysql_error()); + +// Get all node types (required for configuration information too) +$node_types = get_all_node_types_count(); + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Drupal Node Distribution Count\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel Node Distribution Count / ${graph_period}\n"; + echo "graph_category Drupal\n"; + echo "graph_scale nol\n"; + echo "graph_info Displays the nodes content type distribution count in your Drupal site\n"; + + foreach ($node_types as $node_type => $node_count) { + echo "$node_type.label $node_type\n"; + echo "$node_type.type GAUGE\n"; + echo "$node_type.draw LINE2\n"; + echo "$node_type.min 0\n"; + } + + exit(0); +} + + +// Print out the actual values for each node type and it's count +//$node_count_all = (int) get_all_node_count(); +//echo "nodes_total.value $node_count_all\n"; +foreach ($node_types as $node_type => $node_count) { + echo "$node_type.value $node_count\n"; +} + + +/** + * Get count for all nodes + * @return integer $count total nodes created + */ +function get_all_node_count() { + + $table_prefix = getenv('table_prefix'); + $node_count = 0; + + // Get all node types and their count + $result = mysql_query("SELECT COUNT(nid) AS count FROM {$table_prefix}node"); + $row = mysql_fetch_array($result, MYSQL_ASSOC); + $node_count = (int) $row['count']; + + mysql_free_result($result); + return $node_count; + +} + + +/** + * Get all node types and their count + * @return array $node_types associative array of node types and their count + */ +function get_all_node_types_count() { + + $node_types = array(); + $table_prefix = getenv('table_prefix'); + + // Get all node types and their count + $result = mysql_query("SELECT COUNT(nid) AS count, type FROM + {$table_prefix}node GROUP BY type"); + while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { + if (empty($row['type'])) + continue; + $node_types[$row['type']] = $row['count']; + } + + mysql_free_result($result); + return $node_types; + +} + diff --git a/plugins/drupal/drupal_users_online.php b/plugins/drupal/drupal_users_online.php new file mode 100755 index 00000000..dfd99a81 --- /dev/null +++ b/plugins/drupal/drupal_users_online.php @@ -0,0 +1,155 @@ +#!/usr/bin/php + + * @version 1.0 2013 + * + */ + + +/** + * Environment variabels are set by munin's configuration + * @see /etc/munin/plugin-conf.d/munin-node + */ +$db = getenv('db'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$port = getenv('port'); +if (!$port) + $port = 3306; + +$graph_period = getenv('graph_period'); + +if(count($argv) == 2 && $argv[1] == 'autoconf') { + echo "yes\n"; + exit(0); +} + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Drupal Online Users\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel Online Users Count / ${graph_period}\n"; + echo "graph_category Drupal\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the online users, members and anonymous, in your Drupal site\n"; + + echo "online_users.label online users\n"; + echo "online_members.label online members\n"; + echo "online_anonymous.label online anonymous\n"; + + echo "online_users.min 0\n"; + echo "online_members.min 0\n"; + echo "online_anonymous.min 0\n"; + + exit(0); +} + +// Connect to database +$dbh = new mysqli($host, $user, $pass, $db, $port); +if (mysqli_connect_errno()) { + echo "Connecction failed: ".mysqli_connect_error(). PHP_EOL; + exit(1); +} + +// Print out the actual values +$users_online_all = (int) get_all_online_users($dbh); +$users_members = (int) get_online_registered_users($dbh); +$users_anonymous = (int) get_online_anonymous_users($dbh); +echo "online_users.value $users_online_all\n"; +echo "online_members.value $users_members\n"; +echo "online_anonymous.value $users_anonymous\n"; + +$dbh->close(); + + +/** + * Get count for all online users + * @return integer $count total online users + */ +function get_all_online_users(&$dbh = NULL, $active_interval = 900) { + + $table_prefix = getenv('table_prefix'); + + $sql = "SELECT COUNT(DISTINCT(uid)) AS count FROM {$table_prefix}sessions + WHERE timestamp >= (UNIX_TIMESTAMP(now()) - ?)"; + $stmt = $dbh->prepare($sql); + $stmt->bind_param("i", $active_interval); + $stmt->execute(); + + $stmt->bind_result($active_interval); + $row = $stmt->fetch(); + + return (int) $row['count']; + +} + + +/** + * Get count for online users which are registered members + * @return integer $count total registered users online + */ +function get_online_registered_users(&$dbh = NULL, $active_interval = 900) { + + $table_prefix = getenv('table_prefix'); + + $sql = "SELECT COUNT(DISTINCT(uid)) AS count FROM {$table_prefix}sessions WHERE uid != 0 + AND timestamp >= (UNIX_TIMESTAMP(now()) - ?)"; + $stmt = $dbh->prepare($sql); + $stmt->bind_param("i", $active_interval); + $stmt->execute(); + + $stmt->bind_result($active_interval); + $row = $stmt->fetch(); + + return (int) $row['count']; + +} + + +/** + * Get count for anonymous users + * @param object $dbh database object + * @param integer $active_interval seconds of anonymous user activity to consider in results (defaults to 900) + * @return integer $count total anonymous users online + */ +function get_online_anonymous_users(&$dbh = NULL, $active_interval = 900) { + + $table_prefix = getenv('table_prefix'); + + /** + * Returns anonymous users count who have been active for at least one hour + */ + $sql = "SELECT COUNT(DISTINCT(hostname)) AS count FROM + {$table_prefix}sessions WHERE uid = 0 AND timestamp >= (UNIX_TIMESTAMP(now()) - ?)"; + + /** + * If interested in all anonymous users count + * + * SELECT COUNT(DISTINCT(hostname)) AS count FROM sessions WHERE uid = 0 + */ + + $stmt = $dbh->prepare($sql); + $stmt->bind_param("i", $active_interval); + $stmt->execute(); + + $stmt->bind_result($active_interval); + $row = $stmt->fetch(); + + return (int) $row['count']; + +} diff --git a/plugins/drupal/drupal_users_total.php b/plugins/drupal/drupal_users_total.php new file mode 100755 index 00000000..e2eb81a8 --- /dev/null +++ b/plugins/drupal/drupal_users_total.php @@ -0,0 +1,106 @@ +#!/usr/bin/php + + * @version 1.0 2013 + * + */ + + +/** + * Environment variabels are set by munin's configuration + * @see /etc/munin/plugin-conf.d/munin-node + */ +$db = getenv('db'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$port = getenv('port'); +if (!$port) + $port = 3306; + +$graph_period = getenv('graph_period'); + +if(count($argv) == 2 && $argv[1] == 'autoconf') { + echo "yes\n"; + exit(0); +} + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Drupal Total Users\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel Total Users Count / ${graph_period}\n"; + echo "graph_category Drupal\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the sum of users, as well as disabled count, in your Drupal site\n"; + + echo "users_total.label total users\n"; + echo "users_blocked.label blocked users\n"; + + echo "users_total.min 0\n"; + echo "users_blocked.min 0\n"; + + exit(0); +} + +// Connect to database +$dbh = new mysqli($host, $user, $pass, $db, $port); +if (mysqli_connect_errno()) { + echo "Connecction failed: ".mysqli_connect_error(). PHP_EOL; + exit(1); +} + +// Print out the actual values +$users_total = (int) get_total_users($dbh); +$users_blocked = (int) get_blocked_users($dbh); +echo "users_total.value $users_total\n"; +echo "users_blocked.value $users_blocked\n"; + +$dbh->close(); + + +/** + * Get count for all users + * @return integer $count total users + */ +function get_total_users(&$dbh = NULL) { + + $table_prefix = getenv('table_prefix'); + + $sql = "SELECT COUNT(uid) AS count FROM {$table_prefix}users"; + $result = $dbh->query($sql); + $row = $result->fetch_assoc(); + + return (int) $row['count']; + +} + +/** + * Get count for all blocked users + * @return integer $count all blocked users + */ +function get_blocked_users(&$dbh = NULL) { + + $table_prefix = getenv('table_prefix'); + + $sql = "SELECT COUNT(uid) AS count FROM {$table_prefix}users WHERE status = 0"; + $result = $dbh->query($sql); + $row = $result->fetch_assoc(); + + return (int) $row['count']; + +}