|
@@ -1,12 +1,10 @@
|
|
|
<?php
|
|
|
-// $Id$
|
|
|
+
|
|
|
/**
|
|
|
* @file
|
|
|
- * Core Drupal instrumentation for Munin
|
|
|
- *
|
|
|
- * @author Frederic G. MARAND
|
|
|
+ * Core Drupal instrumentation for Munin.
|
|
|
*
|
|
|
- * @copyright (c) 2011 Ouest Systèmes Informatiques
|
|
|
+ * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
|
|
|
*
|
|
|
* Licensed under the General Public License version 2 or later.
|
|
|
*/
|
|
@@ -14,121 +12,127 @@
|
|
|
/**
|
|
|
* Implements hook_munin_api_info().
|
|
|
*
|
|
|
- * @return
|
|
|
- * An array of Munin probes informations, index by probe name.
|
|
|
+ * Returns an array of Munin probes informations, index by probe name.
|
|
|
*/
|
|
|
function munin_core_munin_api_info() {
|
|
|
- $int = array(
|
|
|
+ $int = [
|
|
|
'#graph_printf' => "'%d'",
|
|
|
- );
|
|
|
+ ];
|
|
|
|
|
|
- /**
|
|
|
- * Ignore anon and auth roles: no user carries them in users_roles anyway.
|
|
|
- */
|
|
|
- $sq = 'SELECT r.rid, r.name FROM {role} r WHERE r.rid > 2 ORDER BY 2';
|
|
|
+ /* Ignore anon and auth roles: no user carries them in users_roles anyway. */
|
|
|
+ $sq = <<<SQL
|
|
|
+SELECT r.rid, r.name
|
|
|
+FROM {role} r
|
|
|
+WHERE r.rid > 2
|
|
|
+ORDER BY 2
|
|
|
+SQL;
|
|
|
$q = db_query($sq);
|
|
|
- $roles = array();
|
|
|
- while ($o = db_fetch_object($q)) {
|
|
|
+ $roles = [];
|
|
|
+ foreach ($q as $o) {
|
|
|
$roles[$o->rid] = $o->name;
|
|
|
}
|
|
|
|
|
|
- $ret = array(
|
|
|
- '#title' => t('Drupal'),
|
|
|
- '#description' => t('Graphs about Drupal core'),
|
|
|
+ $ret = [
|
|
|
+ '#title' => t('Drupal'),
|
|
|
+ '#description' => t('Graphs about Drupal core'),
|
|
|
|
|
|
- 'munin_core' => array(
|
|
|
- '#title' => t('Core user-related statistics'),
|
|
|
- '#info' => t('Core statistics regarding users and sessions.'),
|
|
|
+ 'munin_core' => [
|
|
|
+ '#title' => t('Core user-related statistics'),
|
|
|
+ '#info' => t('Core statistics regarding users and sessions.'),
|
|
|
'#graph_vlabel' => t('Anon/blocked (-) vs Logged/Active (+)'),
|
|
|
|
|
|
- 'anon_current' => $int + array(
|
|
|
- '#label' => t('Sessions, anon'),
|
|
|
+ 'anon_current' => $int + [
|
|
|
+ '#label' => t('Sessions, anon'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- '#info' => t('The number of anonymous sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table.'),
|
|
|
- '#graph' => 'no',
|
|
|
- ),
|
|
|
- 'user_current' => $int + array(
|
|
|
- '#label' => t('Sessions'),
|
|
|
+ '#info' => t('The number of anonymous sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table.'),
|
|
|
+ '#graph' => 'no',
|
|
|
+ ],
|
|
|
+
|
|
|
+ 'user_current' => $int + [
|
|
|
+ '#label' => t('Sessions'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- '#info' => t('The number of sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table. Anonymous sessions display as negative.'),
|
|
|
- '#negative' => 'anon_current',
|
|
|
- ),
|
|
|
+ '#info' => t('The number of sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table. Anonymous sessions display as negative.'),
|
|
|
+ '#negative' => 'anon_current',
|
|
|
+ ],
|
|
|
|
|
|
- 'user_blocked_count' => $int + array(
|
|
|
- '#label' => t('Users, blocked'),
|
|
|
+ 'user_blocked_count' => $int + [
|
|
|
+ '#label' => t('Users, blocked'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- '#info' => t('The number of users with status = 0'),
|
|
|
- '#graph' => 'no',
|
|
|
- ),
|
|
|
- 'user_active_count' => $int + array(
|
|
|
- '#label' => t('Users'),
|
|
|
+ '#info' => t('The number of users with status = 0'),
|
|
|
+ '#graph' => 'no',
|
|
|
+ ],
|
|
|
+
|
|
|
+ 'user_active_count' => $int + [
|
|
|
+ '#label' => t('Users'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- '#info' => t('The number of users. Blocked users display as negative.'),
|
|
|
- '#negative' => 'user_blocked_count',
|
|
|
- ),
|
|
|
- ),
|
|
|
-
|
|
|
- 'munin_core_roles' => array(
|
|
|
- '#title' => t('Core role statistics'),
|
|
|
- '#info' => t('Information about users roles.'),
|
|
|
+ '#info' => t('The number of users. Blocked users display as negative.'),
|
|
|
+ '#negative' => 'user_blocked_count',
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+
|
|
|
+ 'munin_core_roles' => [
|
|
|
+ '#title' => t('Core role statistics'),
|
|
|
+ '#info' => t('Information about users roles.'),
|
|
|
'#graph_vlabel' => t('Users by roles'),
|
|
|
- ),
|
|
|
+ ],
|
|
|
|
|
|
- 'munin_core_content' => array(
|
|
|
- '#title' => t('Core content statistics'),
|
|
|
- '#info' => t('Information about nodes, comments and terms.'),
|
|
|
+ 'munin_core_content' => [
|
|
|
+ '#title' => t('Core content statistics'),
|
|
|
+ '#info' => t('Information about nodes, comments and terms.'),
|
|
|
'#graph_vlabel' => t('Entries unpub(-)/pub(+)'),
|
|
|
|
|
|
- 'node_count_unpub' => $int + array(
|
|
|
- '#label' => t('Nodes, unpublished'),
|
|
|
+ 'node_count_unpub' => $int + [
|
|
|
+ '#label' => t('Nodes, unpublished'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- '#graph' => 'no',
|
|
|
- ),
|
|
|
- 'node_count' => $int + array(
|
|
|
- '#label' => t('Nodes'),
|
|
|
- '#info' => t('Unpublished nodes display as negative.'),
|
|
|
+ '#graph' => 'no',
|
|
|
+ ],
|
|
|
+
|
|
|
+ 'node_count' => $int + [
|
|
|
+ '#label' => t('Nodes'),
|
|
|
+ '#info' => t('Unpublished nodes display as negative.'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- '#negative' => 'node_count_unpub',
|
|
|
- ),
|
|
|
+ '#negative' => 'node_count_unpub',
|
|
|
+ ],
|
|
|
|
|
|
- 'comment_count_unpub' => $int + array(
|
|
|
- '#label' => t('Comments, unpublished'),
|
|
|
+ 'comment_count_unpub' => $int + [
|
|
|
+ '#label' => t('Comments, unpublished'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- '#graph' => 'no',
|
|
|
- ),
|
|
|
- 'comment_count' => $int + array(
|
|
|
- '#label' => t('Comments'),
|
|
|
- '#info' => t('Unpublished comments display as negative.'),
|
|
|
+ '#graph' => 'no',
|
|
|
+ ],
|
|
|
+
|
|
|
+ 'comment_count' => $int + [
|
|
|
+ '#label' => t('Comments'),
|
|
|
+ '#info' => t('Unpublished comments display as negative.'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- '#negative' => 'comment_count_unpub',
|
|
|
- ),
|
|
|
- ),
|
|
|
+ '#negative' => 'comment_count_unpub',
|
|
|
+ ],
|
|
|
+ ],
|
|
|
|
|
|
- 'munin_core_taxonomy' => array(
|
|
|
- '#title' => t('Core taxonomy statistics'),
|
|
|
- '#info' => t('Core statistics regarding taxonomy.'),
|
|
|
+ 'munin_core_taxonomy' => [
|
|
|
+ '#title' => t('Core taxonomy statistics'),
|
|
|
+ '#info' => t('Core statistics regarding taxonomy.'),
|
|
|
'#graph_vlabel' => t('Vocabularies (-)/Terms (+)'),
|
|
|
|
|
|
- 'vocab_count' => $int + array(
|
|
|
- '#label' => t('Vocabularies'),
|
|
|
- '#info' => t('Vocabularies'),
|
|
|
+ 'vocab_count' => $int + [
|
|
|
+ '#label' => t('Vocabularies'),
|
|
|
+ '#info' => t('Vocabularies'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- ),
|
|
|
- 'term_count' => $int + array(
|
|
|
- '#label' => t('Terms'),
|
|
|
- '#info' => t('Total terms across all vocabularies'),
|
|
|
+ ],
|
|
|
+ 'term_count' => $int + [
|
|
|
+ '#label' => t('Terms'),
|
|
|
+ '#info' => t('Total terms across all vocabularies'),
|
|
|
'#type' => MUNIN_API_GAUGE,
|
|
|
- ),
|
|
|
- ),
|
|
|
- );
|
|
|
-
|
|
|
- foreach ($roles as $rid => $name) {
|
|
|
- $machine_name = str_replace(' ', '_', $name);
|
|
|
- $ret['munin_core_roles']['role_'. $machine_name] = $int + array(
|
|
|
- '#label' => $name,
|
|
|
- '#info' => t('Number of users with the @role role', array('@role' => $name)),
|
|
|
- '#type' => MUNIN_API_GAUGE,
|
|
|
- );
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($roles as $role) {
|
|
|
+ $machine_name = str_replace(' ', '_', $role);
|
|
|
+ $ret['munin_core_roles']['role_' . $machine_name] = $int + [
|
|
|
+ '#label' => $role,
|
|
|
+ '#info' => t('Number of users with the @role role', ['@role' => $role]),
|
|
|
+ '#type' => MUNIN_API_GAUGE,
|
|
|
+ ];
|
|
|
}
|
|
|
variable_set('munin_core_roles', $roles);
|
|
|
return $ret;
|
|
@@ -142,39 +146,54 @@ function munin_core_munin_api_info() {
|
|
|
function munin_core_munin_api_fetch($graph_name) {
|
|
|
switch ($graph_name) {
|
|
|
case 'munin_core':
|
|
|
- $sq = 'SELECT COUNT(u.uid) cnt, u.status FROM {users} u WHERE u.uid <> 0 GROUP BY 2';
|
|
|
+ $sq = <<<SQL
|
|
|
+SELECT COUNT(u.uid) cnt, u.status
|
|
|
+FROM {users} u
|
|
|
+WHERE u.uid <> 0
|
|
|
+GROUP BY 2
|
|
|
+SQL;
|
|
|
$result = db_query($sq);
|
|
|
- $users = array(0 => 0, 1 => 0);
|
|
|
- while ($row = db_fetch_object($result)) {
|
|
|
+ $users = [0 => 0, 1 => 0];
|
|
|
+ foreach ($result as $row) {
|
|
|
$users[$row->status] = $row->cnt;
|
|
|
}
|
|
|
|
|
|
$ret['user_active_count'] = $users[1];
|
|
|
$ret['user_blocked_count'] = $users[0];
|
|
|
|
|
|
+ $sq = <<<SQL
|
|
|
+SELECT COUNT(*) cnt
|
|
|
+FROM {sessions} s
|
|
|
+WHERE s.uid <> 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60
|
|
|
+SQL;
|
|
|
+ $ret['user_current'] = db_query($sq)
|
|
|
+ ->fetchField();
|
|
|
|
|
|
- $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.uid <> 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60';
|
|
|
- $ret['user_current'] = db_result(db_query($sq));
|
|
|
-
|
|
|
- $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.uid = 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60';
|
|
|
- $ret['anon_current'] = db_result(db_query($sq));
|
|
|
+ $sq = <<<SQL
|
|
|
+SELECT COUNT(*) cnt
|
|
|
+FROM {sessions} s
|
|
|
+WHERE s.uid = 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60
|
|
|
+SQL;
|
|
|
+ $ret['anon_current'] = db_query($sq)
|
|
|
+ ->fetchField();
|
|
|
break;
|
|
|
|
|
|
case 'munin_core_roles':
|
|
|
- $roles = variable_get('munin_core_roles', array());
|
|
|
- $ph = db_placeholders($roles);
|
|
|
- $sq = <<<EOT
|
|
|
-SELECT COUNT(ur.uid) cnt, r.rid, r.name
|
|
|
+ $roles = variable_get('munin_core_roles', []);
|
|
|
+ $sq = <<<SQL
|
|
|
+SELECT COUNT(ur.uid) cnt,
|
|
|
+ r.rid, r.name
|
|
|
FROM {role} r
|
|
|
LEFT JOIN {users_roles} ur ON r.rid = ur.rid
|
|
|
-WHERE r.rid IN ($ph)
|
|
|
+WHERE r.rid IN (:roles)
|
|
|
GROUP BY 2, 3
|
|
|
-EOT;
|
|
|
- $ret = array();
|
|
|
- $q = db_query($sq, array_keys($roles));
|
|
|
- while ($o = db_fetch_object($q)) {
|
|
|
+SQL;
|
|
|
+ $ret = [];
|
|
|
+ $q = db_query($sq, [':roles' => array_keys($roles)]);
|
|
|
+ foreach ($q as $o) {
|
|
|
$name = str_replace(' ', '_', $o->name);
|
|
|
- $ret['role_'. $name] = empty($o->cnt) ? 0 : $o->cnt; // Can be NULL
|
|
|
+ // Can be NULL.
|
|
|
+ $ret['role_' . $name] = empty($o->cnt) ? 0 : $o->cnt;
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -186,10 +205,15 @@ EOT;
|
|
|
'comment_count' => 0,
|
|
|
);
|
|
|
|
|
|
- $sq = 'SELECT COUNT(*) cnt, n.status FROM {node} n GROUP BY n.status';
|
|
|
- // No db_rewrite_sql(): this is an administrative mechanism
|
|
|
+ $sq = <<<SQL
|
|
|
+SELECT COUNT(*) cnt, n.status
|
|
|
+FROM {node} n
|
|
|
+GROUP BY n.status
|
|
|
+SQL;
|
|
|
+ // No dynamic-query addTag('node_access'): this is an administrative
|
|
|
+ // mechanism, which needs to count all nodes.
|
|
|
$q = db_query($sq);
|
|
|
- while ($o = db_fetch_object($q)) {
|
|
|
+ foreach ($q as $o) {
|
|
|
switch ($o->status) {
|
|
|
case 0:
|
|
|
$ret['node_count_unpub'] = $o->cnt;
|
|
@@ -202,39 +226,53 @@ EOT;
|
|
|
default:
|
|
|
watchdog('munin_core', 'Nodes with status @status reported: @count', array(
|
|
|
'@status' => $o->status,
|
|
|
- '@count' => $o->cnt,
|
|
|
+ '@count' => $o->cnt,
|
|
|
), WATCHDOG_NOTICE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $sq = 'SELECT COUNT(*) cnt, c.status FROM {comments} c GROUP BY c.status';
|
|
|
- $q = db_query($sq);
|
|
|
- // No db_rewrite_sql(): this is an administrative mechanism
|
|
|
- while ($o = db_fetch_object($q)) {
|
|
|
- switch ($o->status) {
|
|
|
- case 1:
|
|
|
- $ret['comment_count_unpub'] = $o->cnt;
|
|
|
- break;
|
|
|
+ // Unlike node, comment may be disabled.
|
|
|
+ if (module_exists('comment')) {
|
|
|
+ $sq = <<<SQL
|
|
|
+SELECT COUNT(*) cnt, c.status
|
|
|
+FROM {comments} c
|
|
|
+GROUP BY c.status
|
|
|
+SQL;
|
|
|
+ $q = db_query($sq);
|
|
|
+ // No dynamic-query addTag('node_access'): this is an administrative
|
|
|
+ // mechanism, which needs to count all nodes.
|
|
|
+ foreach ($q as $o) {
|
|
|
+ switch ($o->status) {
|
|
|
+ case 1:
|
|
|
+ $ret['comment_count_unpub'] = $o->cnt;
|
|
|
+ break;
|
|
|
|
|
|
- case 0:
|
|
|
- $ret['comment_count'] = $o->cnt;
|
|
|
- break;
|
|
|
+ case 0:
|
|
|
+ $ret['comment_count'] = $o->cnt;
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
- watchdog('munin_core', 'Comments with status @status reported: @count', array(
|
|
|
- '@status' => $o->status,
|
|
|
- '@count' => $o->cnt,
|
|
|
- ), WATCHDOG_NOTICE);
|
|
|
+ default:
|
|
|
+ watchdog('munin_core', 'Comments with status @status reported: @count', array(
|
|
|
+ '@status' => $o->status,
|
|
|
+ '@count' => $o->cnt,
|
|
|
+ ), WATCHDOG_NOTICE);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case 'munin_core_taxonomy':
|
|
|
- $sq = 'SELECT COUNT(*) FROM {term_data}';
|
|
|
- $ret['term_count'] = db_result(db_query($sq));
|
|
|
+ if (!module_exists('taxonomy')) {
|
|
|
+ $ret['term_count'] = 0;
|
|
|
+ $ret['vocab_count'] = 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $sq = 'SELECT COUNT(*) FROM {taxonomy_term_data}';
|
|
|
+ $ret['term_count'] = db_query($sq)->fetchField();
|
|
|
|
|
|
- $sq = 'SELECT COUNT(*) FROM {vocabulary}';
|
|
|
- $ret['vocab_count'] = db_result(db_query($sq));
|
|
|
+ $sq = 'SELECT COUNT(*) FROM {taxonomy_vocabulary}';
|
|
|
+ $ret['vocab_count'] = db_query($sq)->fetchField();
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
|