You are here

function _prod_check_apc_opc in Production check & Production monitor 7

Same name and namespace in other branches
  1. 6 prod_check.module \_prod_check_apc_opc()

File

./prod_check.module, line 820

Code

function _prod_check_apc_opc($caller = 'internal') {
  $check = array();
  $desc_ok = $desc_nok = '';
  $title = 'APC/OPcache';
  $path = 'admin/reports/status/apc-opc';
  if ($caller != 'internal') {
    $path = PRODCHECK_BASEURL . $path;
  }
  $cache = array();
  if (!function_exists('apc_cache_info') && !function_exists('opcache_get_status')) {
    $desc_nok = t('!link does not appear to be running.', prod_check_link_array($title, $path));
    $val_nok = t('Disabled');
    $error = TRUE;
  }
  elseif (function_exists('opcache_get_status')) {
    $opc_cache = @opcache_get_status();
    if ($opc_cache && $opc_cache['opcache_enabled']) {
      $cache['num_hits'] = $opc_cache['opcache_statistics']['hits'];
      $cache['num_misses'] = $opc_cache['opcache_statistics']['misses'];

      // TODO: Should we make the sum of these two or check separately?
      $cache['expunges'] = $opc_cache['opcache_statistics']['oom_restarts'] + $opc_cache['opcache_statistics']['hash_restarts'];
    }
    else {
      $desc_nok = t('!link does not appear to be running.', prod_check_link_array($title, $path));
      $val_nok = t('Disabled');
      $error = TRUE;
    }
  }
  elseif (function_exists('apc_cache_info')) {
    $cache = @apc_cache_info('opcode');
  }
  if (!empty($cache)) {
    $apc_expunge = variable_get('prod_check_apc_expunge', 0);
    $detailed_info = ': ' . t('hits') . ': ' . $cache['num_hits'] . ', ' . t('misses') . ': ' . $cache['num_misses'] . ', ' . t('cache full count') . ': ' . $cache['expunges'] . '.';
    if ($cache['num_misses'] >= $cache['num_hits']) {
      $desc_nok = t('!link not properly configured, too many misses', prod_check_link_array($title, $path)) . $detailed_info;
      $val_nok = t('Not functioning properly.');
      $error = TRUE;
    }
    elseif ($cache['expunges'] > $apc_expunge) {
      $desc_nok = t('!link not properly configured, cache size too small', prod_check_link_array($title, $path)) . $detailed_info;
      $val_nok = t('Not functioning properly.');
      $error = TRUE;
    }
    else {
      $desc_ok = t('!link running fine', prod_check_link_array($title, $path)) . $detailed_info;
      $val_ok = t('Enabled');
      $error = FALSE;
    }
  }
  else {
    $desc_nok = t('Could not retrieve !link cache data.', prod_check_link_array($title, $path));
    $val_nok = t('Not functioning properly.');
    $error = TRUE;
  }
  $check['prod_check_apc_opc'] = array(
    '#title' => t($title),
    '#state' => !$error,
    '#severity' => $caller == 'nagios' ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
    '#value_ok' => t('Enabled'),
    '#value_nok' => t('Disabled'),
    '#description_ok' => $desc_ok,
    '#description_nok' => $desc_nok,
    '#nagios_key' => 'APC',
    '#nagios_type' => 'state',
  );
  return prod_check_execute_check($check, $caller);
}