Example #1
0
/**
 *  This function contains the main check machinery for  monit. The
 *  validate function check services in the service list to see if
 *  they will pass all defined tests.
 */
void validate() {

  Service_T s;
  sigset_t ns, os;

  if(! update_loadavg())
    log("Update of loadavg has failed!\n");

  if(Run.doprocess)
    initprocesstree();

  for(s= servicelist; s; s= s->next) {
    if(s->visited)
      continue;
    LOCK(s->mutex)
      set_signal_block(&ns, &os);
      if(s->do_monitor && !check_skip(s) && !check_timeout(s))
        s->check(s);
      unset_signal_block(&os);
    END_LOCK;
  }

  if(Run.doprocess)
    delprocesstree();

  reset_depend();

}
// stats_on_add should be called after writing sval with the value
static void stats_on_add(const StringData* key, const StoreValue* sval,
                         int64 ttl, bool prime, bool file) {
  if (RuntimeOption::EnableAPCSizeStats && !check_skip(key->data())) {
    int32 size = sval->var->getSpaceUsage();
    SharedStoreStats::addDirect(key->size(), size, prime, file);
    sval->size = size;
  }
  if (RuntimeOption::EnableAPCSizeStats &&
      (RuntimeOption::EnableAPCSizeGroup ||
       RuntimeOption::EnableAPCSizeDetail)) {
    SharedStoreStats::onStore(key, sval->var, ttl, prime);
  }
}
// stats_on_update should be called before updating sval with new value
static void stats_on_update(const StringData* key, const StoreValue* sval,
                            const SharedVariant* svar, int64 ttl) {
  if (RuntimeOption::EnableAPCSizeStats && !check_skip(key->data())) {
    int32 newSize = svar->getSpaceUsage();
    SharedStoreStats::updateDirect(sval->size, newSize);
    sval->size = newSize;
  }
  if (RuntimeOption::EnableAPCSizeStats &&
      (RuntimeOption::EnableAPCSizeGroup ||
       RuntimeOption::EnableAPCSizeDetail)) {
    SharedStoreStats::onDelete(key, sval->var, true, sval->expiry == 0);
    SharedStoreStats::onStore(key, svar, ttl, false);
  }
}
Example #4
0
/**
 *  This function contains the main check machinery for  monit. The
 *  validate function check services in the service list to see if
 *  they will pass all defined tests.
 */
int validate() {
  int errors = 0;
  Service_T s;

  Run.handler_flag = HANDLER_SUCCEEDED;
  Event_queue_process();

  initprocesstree(&ptree, &ptreesize, &oldptree, &oldptreesize);
  gettimeofday(&systeminfo.collected, NULL);

  /* In the case that at least one action is pending, perform quick
   * loop to handle the actions ASAP */
  if (Run.doaction) {
    Run.doaction = 0;
    for (s = servicelist; s; s = s->next)
      do_scheduled_action(s);
  }

  /* Check the services */
  for (s = servicelist; s && !Run.stopped; s = s->next) {
    if (! do_scheduled_action(s) && s->monitor && ! check_skip(s)) {
      check_timeout(s); // Can disable monitoring => need to check s->monitor again
      if (s->monitor) {
        if (! s->check(s))
          errors++;
        /* The monitoring may be disabled by some matching rule in s->check
         * so we have to check again before setting to MONITOR_YES */
        if (s->monitor != MONITOR_NOT)
          s->monitor = MONITOR_YES;
      }
    }
    gettimeofday(&s->collected, NULL);
  }

  reset_depend();

  return errors;
}
bool ConcurrentTableSharedStore::store(CStrRef key, CVarRef val, int64 ttl,
                                       bool overwrite /* = true */) {
  bool stats = RuntimeOption::EnableStats && RuntimeOption::EnableAPCStats;
  bool statsDetail = RuntimeOption::EnableAPCSizeStats &&
                     RuntimeOption::EnableAPCSizeGroup;
  StoreValue *sval;
  SharedVariant* var = construct(key, val);
  ReadLock l(m_lock);

  const char *kcp = strdup(key.data());
  bool present;
  time_t expiry;
  {
    Map::accessor acc;
    present = !m_vars.insert(acc, kcp);
    sval = &acc->second;
    if (present) {
      free((void *)kcp);
      if (overwrite || sval->expired()) {
        if (statsDetail) {
          SharedStoreStats::onDelete(key.get(), sval->var, true);
        }
        sval->var->decRef();
        if (RuntimeOption::EnableAPCSizeStats && !check_skip(key.data())) {
          int32 size = var->getSpaceUsage();
          SharedStoreStats::updateDirect(sval->size, size);
          sval->size = size;
        }
      } else {
        var->decRef();
        return false;
      }
    } else {
      if (RuntimeOption::EnableAPCSizeStats) {
        int32 size = var->getSpaceUsage();
        SharedStoreStats::addDirect(key.size(), size);
        sval->size = size;
      }
    }
    sval->set(var, ttl);
    expiry = sval->expiry;
    if (statsDetail) {
      SharedStoreStats::onStore(key.get(), var, ttl, false);
    }
  }
  if (RuntimeOption::ApcExpireOnSets) {
    if (ttl) {
      addToExpirationQueue(key.data(), expiry);
    }
    purgeExpired();
  }
  if (stats) {
    if (present) {
      ServerStats::Log("apc.update", 1);
    } else {
      ServerStats::Log("apc.new", 1);
      if (RuntimeOption::EnableStats && RuntimeOption::EnableAPCKeyStats) {
        string prefix = "apc.new.";
        prefix += GetSkeleton(key);
        ServerStats::Log(prefix, 1);
      }
    }
  }

  return true;
}