Browse Source

Sample API implementation for APC

- created munin_apc submodule
- implemented hook_munin_api_info()
- global api report page
- per-module report page
- %munin_api_instance_load() menu loader
FGM 13 years ago
parent
commit
5e1894933f
4 changed files with 156 additions and 3 deletions
  1. 11 0
      modules/munin_apc/munin_apc.info
  2. 55 0
      modules/munin_apc/munin_apc.module
  3. 1 1
      munin_api.info
  4. 89 2
      munin_api.module

+ 11 - 0
modules/munin_apc/munin_apc.info

@@ -0,0 +1,11 @@
+; $Id$
+name = "Munin APC"
+description = "APC information collector for Munin"
+package = Administration
+
+core = 6.x
+
+project = "munin_api"
+datestamp = "1295949238"
+project status url = http://features.osinet.eu/fserver
+version = "6.x-1.x-dev"

+ 55 - 0
modules/munin_apc/munin_apc.module

@@ -0,0 +1,55 @@
+<?php
+// $Id$
+/**
+ * @file
+ * APC instrumentation for Munin
+ */
+
+/**
+ * Implements hook_munin_api_info().
+ *
+ * @return
+ *   An array of Munin probes informations, index by probe name.
+ */
+function munin_apc_munin_api_info() {
+  $ret = array(
+    'munin_apc' => array(
+      '#title' => t('PHP APC'),
+      '#description' => t('Collect cache information for the Alternative PHP Cache'),
+      'total_size' => array(
+        '#title'    => t('Number of bytes allocated to APC'),
+        '#type'     => MUNIN_API_COUNTER,
+      ),
+      'used_size' => array(
+        '#title'    => t('Number of bytes currently used by APC, either cached or deleted'),
+        '#type'     => MUNIN_API_COUNTER,
+      ),
+      'num_hits' => array(
+        '#title'    => t('The number of hits since the last restart'),
+        '#type'     => MUNIN_API_COUNTER,
+      ),
+      'num_misses' => array(
+        '#title'    => t('The number of misses since the last restart'),
+        '#type'     => MUNIN_API_COUNTER,
+      ),
+      'hit_rate'   => array(
+        '#title'    => t('This hit/miss ration since the last restart'),
+        '#type'     => MUNIN_API_GAUGE,
+      ),
+      'num_insertions' => array(
+        '#title'    => t('The number of insertions since the last restart'),
+        '#type'     => MUNIN_API_COUNTER,
+      ),
+      'cache_entries' => array(
+        '#title'    => t('The number of cache entries'),
+        '#type'     => MUNIN_API_GAUGE,
+      ),
+      'deleted_entries' => array(
+        '#title'    => t('The number of deleted entries lingering'),
+        '#type'     => MUNIN_API_GAUGE,
+      ),
+    ),
+  );
+
+  return $ret;
+}

+ 1 - 1
munin_api.info

@@ -6,6 +6,6 @@ package = Administration
 core = 6.x
 
 project = "munin_api"
-datestamp = "1295945332"
+datestamp = "1295949238"
 project status url = http://features.osinet.eu/fserver
 version = "6.x-1.x-dev"

+ 89 - 2
munin_api.module

@@ -1,4 +1,91 @@
 <?php
-function munin_api_help() {
+// $Id$
+/**
+ * @file
+ * An API to help modules expose their instrumentation to Munin.
+ */
+
+define('MUNIN_API_COUNTER', 'counter');
+define('MUNIN_API_GAUGE', 'gauge');
+
+
+/**
+ * Menu loader for %menu_api_instance.
+ */
+function munin_api_instance_load($name) {
+  $module = module_invoke($name, 'munin_api_info');
+  $module = empty($module)
+    ? FALSE
+    : $module[$name];
+
+  return $module;
+}
+
+function munin_api_menu() {
+  $items = array();
+
+  $items['admin/reports/munin_api'] = array(
+    'title' => 'Munin',
+    'description' => 'Reports about Munin data collectors and their probes',
+    'page callback' => 'munin_api_page_report_global',
+    'access arguments' => array('access site reports'),
+  );
+
+  $items['admin/reports/munin_api/list'] = array(
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'title' => 'General',
+  );
+
+  $items['admin/reports/munin_api/list/%munin_api_instance'] = array(
+    'type' => MENU_CALLBACK,
+    'page callback' => 'munin_api_page_report_instance',
+    'page arguments' => array(4),
+    'access arguments' => array('access site reports'),
+  );
+
+  return $items;
+}
+
+/**
+ * Page callback for Munin report
+ *
+ * @return string
+ */
+function munin_api_page_report_global() {
+  $items = module_invoke_all('munin_api_info');
+
+  $header = array(
+    t('Module'),
+    t('Description'),
+    t('Stats'),
+  );
+  $rows = array();
+  foreach ($items as $name => $item) {
+    $link_title = $item['#title'] ? $item['#title'] : $name;
+    $rows[] = array(
+      l($link_title, 'admin/reports/munin_api/list/'. $name),
+      isset($item['#description']) ? $item['#description'] : t('&lt;missing&gt;'),
+      count(element_children($item)),
+    );
+  }
+  $ret = theme('table', $header, $rows);
+  return $ret;
+}
+
+function munin_api_page_report_instance($module) {
+  $title = isset($module['#title']) ? $module['#title'] : t('Info');
+  drupal_set_title($title);
+
+  $header = array(t('Name'), t('Description'), t('Type'));
+  $rows = array();
+  foreach (element_children($module) as $name) {
+    $rows[] = array(
+      $name,
+      isset($module[$name]['#title']) ? $module[$name]['#title'] : t('&lt;missing&gt;'),
+      $module[$name]['#type'],
+    );
+  }
+  $ret = theme('table', $header, $rows);
+  return $ret;
+}
 
-}