|
@@ -84,9 +84,76 @@ function munin_api_access_fetch($module) {
|
|
|
return TRUE; // For now, protect at the web server level
|
|
|
}
|
|
|
|
|
|
+function munin_api_admin_settings($form_state) {
|
|
|
+
|
|
|
+ $form = array();
|
|
|
+
|
|
|
+ $form['munin_api_watchdog'] = array(
|
|
|
+ '#title' => t('Munin API Watchdog'),
|
|
|
+ '#description' => t('Enables Drupal-level monitoring of Munin. If enabled, it will regularly make sure the time interval between Munin probes is within the expected range and raise watchdog alerts accordingly. Init should only be used on pages with a low-occurrence rate, and will not work properly if caching mode is set to "aggressive" or "external" (Pressflow).'),
|
|
|
+ '#type' => 'radios',
|
|
|
+ '#options' => array(
|
|
|
+ 'none' => t('Disabled'),
|
|
|
+ 'cron' => t('On cron runs'),
|
|
|
+ 'init' => t('On page init'),
|
|
|
+ ),
|
|
|
+ '#default_value' => variable_get('munin_api_watchdog', 'cron'),
|
|
|
+ );
|
|
|
+
|
|
|
+ $default_path = variable_get('munin_api_init_path', '/^$/');
|
|
|
+ $form['munin_api_init_path'] = array(
|
|
|
+ '#title' => t('Init path'),
|
|
|
+ '#description' => t('For page init watchdog mode, specify the regular expression for the paths that should trigger a watchdog check'),
|
|
|
+ '#type' => 'textfield',
|
|
|
+ '#default_value' => $default_path,
|
|
|
+ );
|
|
|
+
|
|
|
+ drupal_add_js(drupal_get_path('module', 'munin_api') .'/munin_api.js');
|
|
|
+ drupal_add_js(array(
|
|
|
+ 'munin_api' => array(
|
|
|
+ 'path' => $default_path,
|
|
|
+ )), 'setting');
|
|
|
+
|
|
|
+ $form = system_settings_form($form);
|
|
|
+ return $form;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_cron().
|
|
|
+ */
|
|
|
+function munin_api_cron() {
|
|
|
+ if (variable_get('munin_api_watchdog', 'cron') == 'cron') {
|
|
|
+ _munin_api_watchdog_munin();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_init().
|
|
|
+ *
|
|
|
+ * Only trigger Munin API watchdog on selected pages.
|
|
|
+ */
|
|
|
+function munin_api_init() {
|
|
|
+ if (variable_get('munin_api_watchdog', 'cron') == 'init') {
|
|
|
+ $path = $_GET['q'];
|
|
|
+ $regex = variable_get('munin_api_init_path', '/^$/');
|
|
|
+ $sts = preg_match($regex, $path);
|
|
|
+ if ($sts) {
|
|
|
+ _munin_api_watchdog_munin();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
function munin_api_menu() {
|
|
|
$items = array();
|
|
|
|
|
|
+ $items['admin/settings/munin_api'] = array(
|
|
|
+ 'title' => 'Munin',
|
|
|
+ 'description' => 'Munin API settings',
|
|
|
+ 'page callback' => 'drupal_get_form',
|
|
|
+ 'page arguments' => array('munin_api_admin_settings'),
|
|
|
+ 'access arguments' => array('administer site configuration'),
|
|
|
+ );
|
|
|
+
|
|
|
$items['admin/reports/munin_api'] = array(
|
|
|
'title' => 'Munin',
|
|
|
'description' => 'Reports about Munin data collectors and their probes',
|
|
@@ -159,6 +226,8 @@ function munin_api_munin_api_info() {
|
|
|
'#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.'),
|
|
|
+ '#warning' => '290:310',
|
|
|
+ '#critical' => '1:600',
|
|
|
),
|
|
|
),
|
|
|
);
|
|
@@ -331,3 +400,33 @@ function munin_api_page_report_instance($module_name, $module_info) {
|
|
|
$ret = theme('table', $header, $rows);
|
|
|
return $ret;
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Munin API watchdog implementation.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+function _munin_api_watchdog_munin() {
|
|
|
+ $seconds = munin_api_munin_api_fetch('munin_munin', FALSE);
|
|
|
+ $seconds = reset($seconds);
|
|
|
+
|
|
|
+ $info = munin_api_munin_api_info();
|
|
|
+ $info = $info['munin_munin']['munin_seconds'];
|
|
|
+ $warning = explode(':', $info['#warning']);
|
|
|
+ $critical = explode(':', $info['#critical']);
|
|
|
+ if (/* $seconds < $critical[0] || */ $seconds > $critical[1]) {
|
|
|
+ $level = WATCHDOG_CRITICAL;
|
|
|
+ }
|
|
|
+ elseif (/* $seconds < $warning[0] || */ $seconds > $warning[1]) {
|
|
|
+ $level = WATCHDOG_WARNING;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $level = WATCHDOG_DEBUG;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($level < WATCHDOG_DEBUG) { // meaning MORE urgent
|
|
|
+ watchdog('munin_api', 'Munin last probe came @last seconds ago.', array(
|
|
|
+ '@last' => $seconds,
|
|
|
+ ), $level);
|
|
|
+ }
|
|
|
+}
|