Browse Source

Added a built-in munin control plugin

- check the time elapsed between succesive munin queries
Frederic G. MARAND 13 years ago
parent
commit
061f0912c0
2 changed files with 83 additions and 16 deletions
  1. 29 15
      munin_api.install
  2. 54 1
      munin_api.module

+ 29 - 15
munin_api.install

@@ -18,21 +18,35 @@ function munin_api_requirements($phase) {
   $ret = array();
   if ($phase == 'runtime') {
     $count = count(module_implements('munin_api_info'));
-    if ($count == 0) {
-      $req = array(
-        'title' => t('Munin plugin modules'),
-        'value' => t('No Munin plugin module enabled'),
-        'description' => t('Munin API is enabled, but no plugin module is enabled to report to it. In this situation, Munin API consumes resources but does not actually report anything. You should either enable some plugin modules or disable and uninstall Munin API.'),
-        'severity' => REQUIREMENT_WARNING,
-      );
-    }
-    else {
-      $req = array(
-        'title' => t('Munin plugin modules'),
-        'value' => format_plural($count, '1 Munin plugin enabled.',
-          '@count Munin plugins enabled.'),
-        'severity' => REQUIREMENT_OK,
-      );
+    switch ($count) {
+      case 0:
+        $req = array(
+          'title' => t('Munin plugin modules'),
+          'value' => t('No plugin found'),
+          'description' => t('Munin API is enabled, but does not find any plugin, including the one built into the API.'),
+          'severity' => REQUIREMENT_ERROR,
+          );
+        break;
+
+      case 1:
+        $req = array(
+          'title' => t('Munin plugin modules'),
+          'value' => t('No Munin plugin module enabled beyond API'),
+          'description' => t('Munin API is enabled, but no plugin module is enabled to report to it except the one built within the API. You should either <a href="!link">enable some plugin modules</a> or <a href="!link">disable and uninstall Munin API</a>.', array(
+            '!link' => url('admin/build/modules'),
+          )),
+          'severity' => REQUIREMENT_INFO,
+        );
+        break;
+
+      default:
+        $req = array(
+          'title' => t('Munin plugin modules'),
+          // format plural although $count >= 2 because some languages have several plural forms
+          'value' => t($count, '1 Munin plugin enabled.',
+            '<a href="!link">@count Munin plugins</a> enabled.', array('!link' => url('admin/reports/munin_api'))),
+          'severity' => REQUIREMENT_OK,
+        );
     }
     $ret[] = $req;
   }

+ 54 - 1
munin_api.module

@@ -9,6 +9,9 @@
  * @copyright (c) 2011 Ouest Systèmes Informatiques
  *
  * Licensed under the General Public License version 2 or later.
+ *
+ * TODO Field name should be sanitized by "s/[^A-Za-z0-9_]/_/g"
+ * @link http://munin-monitoring.org/wiki/notes_on_datasource_names @endlink
  */
 
 define('MUNIN_API_COUNTER',          'COUNTER');
@@ -132,6 +135,56 @@ function munin_api_menu() {
   return $items;
 }
 
+/**
+ * Implements hook_munin_api_info().
+ *
+ * @return
+ *   An array of Munin probes informations, index by probe name.
+ */
+function munin_api_munin_api_info() {
+  $int = array(
+    '#graph_printf' => "'%d'",
+  );
+
+  $ret = array(
+    '#title'     => t('Munin'),
+    '#description'  => t('Munin monitoring'),
+
+    'munin_munin' => array(
+      '#title'     => t('Munin-node'),
+      '#info'      => t('Monitor the monitoring solution.'),
+      '#graph_vlabel' => t('Seconds since last probe'),
+
+      'munin_seconds' => $int + array(
+        '#label'     => t('Seconds since last probe'),
+        '#type'      => MUNIN_API_GAUGE,
+        '#info'      => t('Seconds since last probe should hover around 300. 0 means no probe found.'),
+      ),
+    ),
+  );
+
+  return $ret;
+}
+
+/**
+ * Implements hook_munin_api_fetch().
+ */
+function munin_api_munin_api_fetch($graph_name, $log = TRUE) {
+  switch ($graph_name) {
+    case 'munin_munin':
+      $request_time = time();
+      $last = variable_get('munin_api_last', 0);
+      $ret['munin_seconds'] = $last ? $request_time - $last : 0;
+
+      if ($log) {
+        variable_set('munin_api_last', $request_time);
+      }
+      break;
+  }
+
+  return $ret;
+}
+
 /**
  * Page callback for munin config fetches.
  */
@@ -243,7 +296,7 @@ function munin_api_page_report_instance($module_name, $module_info) {
   $error = array('class' => 'error');
   $rows = array();
   foreach (element_children($module_info) as $graph_name) {
-    $data = module_invoke($module_name, 'munin_api_fetch', $graph_name);
+    $data = module_invoke($module_name, 'munin_api_fetch', $graph_name, FALSE);
     if (!is_array($data)) {
       return _munin_report_hook_error('munin_api_fetch', $module_name);
     }