Browse Source

First working version.

- basic APC information implemented, all on one graph
- basic core information implementend, all on one graph
- TODO: split graphs by nature of information (eg. not nodes with users)
- licensing info clarified
FGM 13 years ago
parent
commit
a9372588cc

+ 11 - 0
modules/munin_apc/munin_apc.info

@@ -1,4 +1,15 @@
 ; $Id$
+;
+; @file
+; APC instrumentation for Munin: module manifest
+; 
+;
+; @author Frederic G. MARAND
+; 
+; @copyright (c) 2011 Ouest Systèmes Informatiques
+; 
+; Licensed under the General Public License version 2 or later.
+
 name = "Munin APC"
 description = "APC information collector for Munin"
 package = Administration

+ 57 - 35
modules/munin_apc/munin_apc.module

@@ -3,6 +3,12 @@
 /**
  * @file
  * APC instrumentation for Munin
+ *
+ * @author Frederic G. MARAND
+ *
+ * @copyright (c) 2011 Ouest Systèmes Informatiques
+ *
+ * Licensed under the General Public License version 2 or later.
  */
 
 /**
@@ -12,45 +18,53 @@
  *   An array of Munin probes informations, index by probe name.
  */
 function munin_apc_munin_api_info() {
+  $int = array(
+    '#graph_printf' => '%d',
+  );
+
   $ret = array(
     'munin_apc' => array(
       '#title' => t('PHP APC'),
-      '#description' => t('Collect cache information for the Alternative PHP Cache'),
-      'uptime'     => array(
-        '#title'     => t('Up-time of APC instance'),
-        '#type'      => MUNIN_API_GAUGE
+      '#info' => t('Collect cache information for the Alternative PHP Cache'),
+      'total_size' => $int + array(
+        '#label'     => t('Bytes allocated'),
+        '#type'      => MUNIN_API_GAUGE,
+        '#info'      => t('Number of bytes allocated to APC.')
       ),
-      'total_size' => array(
-        '#title'     => t('Number of bytes allocated to APC'),
-        '#type'      => MUNIN_API_COUNTER,
+      'used_size'  => $int + array(
+        '#label'     => t('Bytes in use'),
+        '#type'      => MUNIN_API_GAUGE,
+        '#info'      => t('Number of bytes actually used by APC, either cached or deleted'),
       ),
-      'used_size'  => array(
-        '#title'     => t('Number of bytes currently used by APC, either cached or deleted'),
-        '#type'      => MUNIN_API_COUNTER,
+      'uptime'     => $int + array(
+        '#label'     => t('Up-time of APC instance'),
+        '#type'      => MUNIN_API_GAUGE,
+        '#info'      => t('Seconds since last APC restart.'),
       ),
-      'num_hits'   => array(
-        '#title'     => t('The number of hits since the last restart'),
+      'num_hits'   => $int + array(
+        '#label'     => t('Hits since last restart'),
         '#type'      => MUNIN_API_COUNTER,
       ),
-      'num_misses' => array(
-        '#title'     => t('The number of misses since the last restart'),
+      'num_misses' => $int + array(
+        '#label'     => t('Misses since last restart'),
         '#type'      => MUNIN_API_COUNTER,
       ),
-      'hit_rate'   => array(
-        '#title'     => t('This hit/miss ratio since the last restart'),
-        '#type'      => MUNIN_API_GAUGE,
-      ),
-      'num_insertions' => array(
-        '#title'     => t('The number of insertions since the last restart'),
+      'num_inserts' => $int + array(
+        '#label'     => t('Insertions since last restart'),
         '#type'      => MUNIN_API_COUNTER,
       ),
-      'cache_entries' => array(
-        '#title'     => t('The number of cache entries'),
+//      'hit_rate'   => $int + array(
+//        '#label'     => t('Hit/miss ratio since last restart'),
+//        '#type'      => MUNIN_API_GAUGE,
+//      ),
+      'cache_entries' => $int + array(
+        '#label'     => t('Number of cache entries'),
         '#type'      => MUNIN_API_GAUGE,
       ),
-      'deleted_entries' => array(
-        '#title'     => t('The number of deleted entries lingering'),
+      'deleted_entries' => $int + array(
+        '#label'     => t('Number of deleted entries'),
         '#type'      => MUNIN_API_GAUGE,
+        '#info'      => t('Deleted entries lingering until the garbage collection TTL elapses'),
       ),
     ),
   );
@@ -62,15 +76,23 @@ function munin_apc_munin_api_info() {
  * Implements hook_munin_api_fetch().
  */
 function munin_apc_munin_api_fetch() {
-  return array(
-    'uptime' => 1,
-  );
-}
+  $info = apc_sma_info();
+  $ret = array();
 
-/**
- * Implements hook_munin_api_config().
- */
-function munin_apc_munin_api_config() {
-  return array(
-  );
-}
+  // SMA Info
+  $total = $info['num_seg'] * $info['seg_size'];
+  $ret['total_size'] = (int) $total;
+  $ret['used_size'] = (int) ($total - $info['avail_mem']);
+
+  // Cache info
+  $info = apc_cache_info();
+  $ret['uptime']      = time() - $info['start_time'];
+  foreach (array('num_hits', 'num_misses', 'num_inserts') as $field) {
+    $ret[$field] = $info[$field];
+  }
+
+  $ret['cache_entries']   = count($info['cache_list']);
+  $ret['deleted_entries'] = count($info['deleted_list']);
+
+  return $ret;
+}

+ 11 - 0
modules/munin_core/munin_core.info

@@ -1,4 +1,15 @@
 ; $Id$
+;
+; @file
+; Drupal core instrumentation for Munin: module manifest
+; 
+;
+; @author Frederic G. MARAND
+; 
+; @copyright (c) 2011 Ouest Systèmes Informatiques
+; 
+; Licensed under the General Public License version 2 or later.
+
 name = "Munin Core"
 description = "Core Drupal information collector for Munin"
 package = Administration

+ 60 - 18
modules/munin_core/munin_core.module

@@ -3,6 +3,12 @@
 /**
  * @file
  * Core Drupal instrumentation for Munin
+ *
+ * @author Frederic G. MARAND
+ *
+ * @copyright (c) 2011 Ouest Systèmes Informatiques
+ *
+ * Licensed under the General Public License version 2 or later.
  */
 
 /**
@@ -12,38 +18,74 @@
  *   An array of Munin probes informations, index by probe name.
  */
 function munin_core_munin_api_info() {
+  $int = array(
+    '#graph_printf' => '%d',
+  );
+
   $ret = array(
     'munin_core' => array(
       '#title' => t('Drupal core'),
-      '#description' => t('Collect core information from a Drupal instance'),
-      'user_current' => array(
-        '#title'    => t('Currently logged-in users'),
+      '#info' => t('Collect core information from a Drupal instance. All counters are integer-rounded.'),
+      'user_current' => $int + array(
+        '#label'    => t('Currently logged-in users'),
         '#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.'),
       ),
-      'user_count' => array(
-        '#title'    => t('Number of users'),
-        '#type'     => MUNIN_API_COUNTER,
+      'user_count' => $int + array(
+        '#label'    => t('Number of users'),
+        '#type'     => MUNIN_API_GAUGE,
+        '#info'     => t('The total number of users, whatever their status'),
       ),
-      'user_active_count' => array(
-        '#title'    => t('Number of active users'),
-        '#type'     => MUNIN_API_COUNTER,
+      'user_active_count' => $int + array(
+        '#label'    => t('Number of active users'),
+        '#type'     => MUNIN_API_GAUGE,
+        '#info'     => t('The number of users with status = 1'),
       ),
-      'user_blocked_count' => array(
-        '#title'    => t('Number of blocked users'),
-        '#type'     => MUNIN_API_COUNTER,
+      'user_blocked_count' => $int + array(
+        '#label'    => t('Number of blocked users'),
+        '#type'     => MUNIN_API_GAUGE,
+        '#info'     => t('The number of users with status = 0'),
       ),
 
-      'node_count' => array(
-        '#title'    => t('Number of nodes.'),
-        '#type'     => MUNIN_API_COUNTER,
+      'node_count' => $int + array(
+        '#label'    => t('Number of published nodes.'),
+        '#type'     => MUNIN_API_GAUGE,
       ),
 
-      'comment_count' => array(
-        '#title'    => t('Number of comments.'),
-        '#type'     => MUNIN_API_COUNTER,
+      'comment_count' => $int + array(
+        '#label'    => t('Number of published comments.'),
+        '#type'     => MUNIN_API_GAUGE,
       ),
     ),
   );
 
   return $ret;
 }
+
+/**
+ * Implements hook_munin_api_fetch().
+ */
+function munin_core_munin_api_fetch() {
+  $sq = 'SELECT COUNT(u.uid) cnt, u.status FROM {users} u GROUP BY 2';
+  $result = db_query($sq);
+  while ($row = db_fetch_object($result)) {
+    $users[$row->status] = $row->cnt;
+  }
+
+  $ret['user_active_count'] = $users[1];
+  $ret['user_blocked_count'] = $users[0];
+  $ret['user_count'] = $users[0] + $users[1];
+
+
+  $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.timestamp >= UNIX_TIMESTAMP() - 5*60';
+  $ret['user_current'] = db_result(db_query($sq));
+
+  $sq = 'SELECT COUNT(*) cnt FROM {node} n WHERE n.status = 1';
+  // No db_rewrite_sql(): this is an administrative mechanism
+  $ret['node_count'] = db_result(db_query($sq));
+
+  $sq = 'SELECT COUNT(*) cnt FROM {comments} c WHERE c.status = 0';
+  // No db_rewrite_sql(): this is an administrative mechanism
+  $ret['comment_count'] = db_result(db_query($sq));
+  return $ret;
+}

+ 12 - 1
munin_api.info

@@ -1,4 +1,15 @@
-; $Id: devel.info,v 1.5.2.1 2008/06/13 03:25:20 weitzman Exp $
+; $Id$
+;
+; @file
+; Munin API for Drupal: module manifest
+; 
+;
+; @author Frederic G. MARAND
+; 
+; @copyright (c) 2011 Ouest Systèmes Informatiques
+; 
+; Licensed under the General Public License version 2 or later.
+
 name = "Munin API"
 description = "An API to make modules instrumented for Munin stats"
 package = Administration

+ 34 - 14
munin_api.module

@@ -2,12 +2,19 @@
 // $Id$
 /**
  * @file
- * An API to help modules expose their instrumentation to Munin.
+ * Munin API for Drupal.
+ *
+ * @author Frederic G. MARAND
+ *
+ * @copyright (c) 2011 Ouest Systèmes Informatiques
+ *
+ * Licensed under the General Public License version 2 or later.
  */
 
-define('MUNIN_API_COUNTER', 'COUNTER');
-define('MUNIN_API_DERIVE',  'DERIVE');
-define('MUNIN_API_GAUGE',   'GAUGE');
+define('MUNIN_API_COUNTER',  'COUNTER');
+define('MUNIN_API_DERIVE',   'DERIVE');
+define('MUNIN_API_GAUGE',    'GAUGE');
+define('MUNIN_API_ABSOLUTE', 'ABSOLUTE'); // Counters reset upon reading (uncommon)
 
 /**
  * Finalize result pages for Munin interactions.
@@ -113,16 +120,29 @@ function munin_api_menu() {
  * Page callback for munin config fetches.
  */
 function munin_api_page_config($module) {
-  $data = module_invoke($module, 'munin_api_config');
-  if (!is_array($data)) {
-    return _munin_report_hook_error('munin_api_config', $module);
+  $module_info = module_invoke($module, 'munin_api_info');
+  if (!is_array($module_info) || count($module_info) != 1) {
+    return _munin_report_hook_error('munin_api_info', $module);
   }
+  $info = reset($module_info);
 
-  $ret = '';
-  foreach ($data as $attribute => $value) {
-    $ret .= $attribute .' = '. $value . PHP_EOL;
+  $config = array(
+    'graph_title'    => $info['#title'],
+    // 'graph_vlabel' => '',
+    'graph_info'     => $info['#info'],
+    'graph_category' => 'Drupal',
+  );
+
+  foreach (element_children($info) as $field_name) {
+    foreach (element_properties($info[$field_name]) as $property_name) {
+      $config[$field_name .'.'. drupal_substr($property_name, 1)] = $info[$field_name][$property_name];
+    }
   }
 
+  $ret = '';
+  foreach ($config as $k => $v) {
+    $ret .= $k .' '. $v . PHP_EOL;
+  }
   _munin_api_page_closure($ret);
 }
 
@@ -137,7 +157,7 @@ function munin_api_page_fetch($module) {
 
   $ret = '';
   foreach ($data as $field => $value) {
-    $ret .= $module .'.'. $field .' = '. $value . PHP_EOL;
+    $ret .= $field .'.value '. $value . PHP_EOL;
   }
 
   _munin_api_page_closure($ret);
@@ -158,10 +178,10 @@ function munin_api_page_report_global() {
   );
   $rows = array();
   foreach ($items as $name => $item) {
-    $link_title = $item['#title'] ? $item['#title'] : $name;
+    $link_title = $item['#label'] ? $item['#label'] : $name;
     $rows[] = array(
       l($link_title, 'admin/reports/munin_api/'. $name),
-      isset($item['#description']) ? $item['#description'] : t('<missing>'),
+      isset($item['#info']) ? $item['#info'] : t('<missing>'),
       count(element_children($item)),
     );
   }
@@ -189,7 +209,7 @@ function munin_api_page_report_instance($module) {
   foreach (element_children($module_info) as $name) {
     $rows[] = array(
       $name,
-      isset($module_info[$name]['#title']) ? $module_info[$name]['#title'] : t('<missing>'),
+      isset($module_info[$name]['#label']) ? $module_info[$name]['#label'] : t('<missing>'),
       $module_info[$name]['#type'],
     );
   }