Browse Source

New drupal_core_roles feature: users by role

- new graph in drupal_core module
- ANSI SQL syntax change: <> instead of !=
- spacing, wording, CVS tags
Frederic G. MARAND 13 years ago
parent
commit
25898cf124

+ 1 - 0
modules/munin_apc/munin_apc.install

@@ -1,4 +1,5 @@
 <?php
+// $Id$
 /**
  * @file
  * Drupal APC instrumentation for Munin: installation.

+ 6 - 6
modules/munin_apc/munin_apc.module

@@ -28,9 +28,9 @@ function munin_apc_munin_api_info() {
     '#description' => t('Graphs about PHP APC memory yse'),
 
     'munin_apc' => array(
-      '#title'     => t('APC Caching'),
-      '#info'      => t('Collect memory-level information for the Alternative PHP Cache. This graph uses IEC binary sizes.'),
-      '#graph_args'=> '--base 1024 --lower-limit 0',
+      '#title'       => t('APC Caching'),
+      '#info'        => t('Collect memory-level information for the Alternative PHP Cache. This graph uses IEC binary sizes.'),
+      '#graph_args'  => '--base 1024 --lower-limit 0',
 
       'total_size' => $int + array(
         '#label'     => t('Bytes allocated'),
@@ -45,9 +45,9 @@ function munin_apc_munin_api_info() {
     ),
 
     'munin_apc_entries' => array(
-      '#title'     => t('APC Entries'),
-      '#info'      => t('Collect entries-level information for the Alternative PHP Cache.'),
-      '#graph_args'=> '--base 1000 --lower-limit 0',
+      '#title'       => t('APC Entries'),
+      '#info'        => t('Collect entries-level information for the Alternative PHP Cache.'),
+      '#graph_args'  => '--base 1000 --lower-limit 0',
 
       'num_hits'   => $int + array(
         '#label'     => t('Hits since last restart'),

+ 1 - 0
modules/munin_core/munin_core.install

@@ -1,4 +1,5 @@
 <?php
+// $Id$
 /**
  * @file
  * Core Drupal instrumentation for  Munin: installation.

+ 83 - 40
modules/munin_core/munin_core.module

@@ -22,6 +22,16 @@ function munin_core_munin_api_info() {
     '#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';
+  $q = db_query($sq);
+  $roles = array();
+  while ($o = db_fetch_object($q)) {
+    $roles[$o->rid] = $o->name;
+  }
+
   $ret = array(
     '#title'     => t('Drupal'),
     '#description'  => t('Graphs about Drupal core'),
@@ -31,60 +41,66 @@ function munin_core_munin_api_info() {
       '#info'      => t('Core statistics regarding users and sessions.'),
       '#graph_vlabel' => t('Anon/blocked (-) vs Logged/Active (+)'),
 
-      'anon_current' => $int + array(
-        '#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',
+      'anon_current'  => $int + array(
+        '#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'),
-        '#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 dispaly as negative.'),
-        '#negative'  => 'anon_current',
+      'user_current'  => $int + array(
+        '#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',
       ),
 
       'user_blocked_count' => $int + array(
-        '#label'    => t('Users, blocked'),
-        '#type'     => MUNIN_API_GAUGE,
-        '#info'     => t('The number of users with status = 0'),
-        '#graph'    => 'no',
+        '#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'),
-        '#type'     => MUNIN_API_GAUGE,
-        '#info'     => t('The number of users. Blocked users display as negative.'),
-        '#negative' => 'user_blocked_count',
+        '#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.'),
+      '#graph_vlabel' => t('Users by roles'),
+    ),
+
     'munin_core_content' => array(
       '#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'),
-        '#type'     => MUNIN_API_GAUGE,
-        '#graph'    => 'no',
+        '#label'      => t('Nodes, unpublished'),
+        '#type' => MUNIN_API_GAUGE,
+        '#graph'      => 'no',
       ),
       'node_count' => $int + array(
-        '#label'    => t('Nodes'),
-        '#info'     => t('Unpublished nodes display as negative.'),
-        '#type'     => MUNIN_API_GAUGE,
-        '#negative' => 'node_count_unpub',
+        '#label'      => t('Nodes'),
+        '#info'       => t('Unpublished nodes display as negative.'),
+        '#type' => MUNIN_API_GAUGE,
+        '#negative'   => 'node_count_unpub',
       ),
 
       'comment_count_unpub' => $int + array(
-        '#label'    => t('Comments, unpublished'),
-        '#type'     => MUNIN_API_GAUGE,
-        '#graph'    => 'no',
+        '#label'      => t('Comments, unpublished'),
+        '#type' => MUNIN_API_GAUGE,
+        '#graph'      => 'no',
       ),
       'comment_count' => $int + array(
-        '#label'    => t('Comments'),
-        '#info'     => t('Unpublished comments display as negative.'),
-        '#type'     => MUNIN_API_GAUGE,
-        '#negative' => 'comment_count_unpub',
+        '#label'      => t('Comments'),
+        '#info'       => t('Unpublished comments display as negative.'),
+        '#type' => MUNIN_API_GAUGE,
+        '#negative'   => 'comment_count_unpub',
       ),
     ),
 
@@ -94,18 +110,27 @@ function munin_core_munin_api_info() {
       '#graph_vlabel' => t('Vocabularies (-)/Terms (+)'),
 
       'vocab_count' => $int + array(
-        '#label'    => t('Vocabularies'),
-        '#info'     => t('Vocabularies'),
-        '#type'     => MUNIN_API_GAUGE,
+        '#label'      => t('Vocabularies'),
+        '#info'       => t('Vocabularies'),
+        '#type' => MUNIN_API_GAUGE,
       ),
       'term_count' => $int + array(
-        '#label'    => t('Terms'),
-        '#info'     => t('Total terms across all vocabularies'),
-        '#type'     => MUNIN_API_GAUGE,
+        '#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,
+    );
+  }
+  variable_set('munin_core_roles', $roles);
   return $ret;
 }
 
@@ -117,7 +142,7 @@ 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 = 'SELECT COUNT(u.uid) cnt, u.status FROM {users} u WHERE u.uid <> 0 GROUP BY 2';
       $result = db_query($sq);
       $users = array(0 => 0, 1 => 0);
       while ($row = db_fetch_object($result)) {
@@ -128,13 +153,31 @@ function munin_core_munin_api_fetch($graph_name) {
       $ret['user_blocked_count'] = $users[0];
 
 
-      $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.uid != 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60';
+      $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));
       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
+FROM {role} r
+  LEFT JOIN {users_roles} ur ON r.rid = ur.rid
+WHERE r.rid IN ($ph)
+GROUP BY 2, 3
+EOT;
+      $ret = array();
+      $q = db_query($sq, array_keys($roles));
+      while ($o = db_fetch_object($q)) {
+        $name = str_replace(' ', '_', $o->name);
+        $ret['role_'. $name] = empty($o->cnt) ? 0 : $o->cnt; // Can be NULL
+      }
+      break;
+
     case 'munin_core_content':
       $ret = array(
         'node_count_unpub' => 0,