コード例 #1
0
ファイル: validate.c プロジェクト: bumper-app/nicad
/**
 *  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();

}
コード例 #2
0
ファイル: gc.c プロジェクト: andreax79/monit
void gc() {

  destroy_hosts_allow();

  gc_protocols();

  if(Run.doprocess) {
    delprocesstree(&oldptree, oldptreesize);
    delprocesstree(&ptree, ptreesize);
  }
  
  if(servicelist)
    _gc_service_list(&servicelist);
  
  if(servicegrouplist)
    _gc_servicegroup(&servicegrouplist);
  
  if(Run.credentials)
    _gcath(&Run.credentials);

  if(Run.maillist)
    gc_mail_list(&Run.maillist);
  
  if(Run.mailservers)
    _gc_mail_server(&Run.mailservers);

  if(Run.mmonits)
    _gc_mmonit(&Run.mmonits);

  if(Run.eventlist)
    gc_event(&Run.eventlist);
  
  FREE(Run.eventlist_dir);
  FREE(Run.mygroup);
  FREE(Run.localhostname);
  FREE(Run.httpsslpem);
  FREE(Run.httpsslclientpem);
  FREE(Run.bind_addr);
  FREE(Run.MailFormat.from);
  FREE(Run.MailFormat.subject);
  FREE(Run.MailFormat.message);
  FREE(Run.mail_hostname);
  
}
コード例 #3
0
ファイル: process.c プロジェクト: KISSMonX/monit
/**
 * Initialize the process tree 
 * @return treesize >= 0 if succeeded otherwise < 0
 */
int initprocesstree(ProcessTree_T **pt_r, int *size_r, ProcessTree_T **oldpt_r, int *oldsize_r) {
  int i;
  int oldentry;
  ProcessTree_T *pt;
  ProcessTree_T *oldpt;
  int root = -1;

  if (*pt_r != NULL) {  
    if (oldpt_r && *oldpt_r != NULL)
      delprocesstree(oldpt_r, oldsize_r);
    *oldpt_r   = *pt_r; 
    *oldsize_r = *size_r; 
  }
  
  if ((*size_r = initprocesstree_sysdep(pt_r)) <= 0) {
    DEBUG("system statistic error -- cannot initialize the process tree => process resource monitoring disabled\n");
    Run.doprocess = FALSE;
    return -1;
  } else if (Run.doprocess == FALSE) {
    DEBUG("system statistic -- initialization of the process tree succeeded => process resource monitoring enabled\n");
    Run.doprocess = TRUE;
  }

  pt    = *pt_r;
  oldpt = *oldpt_r;

  if (pt == NULL)
    return 0;

  for (i = 0; i < (volatile int)*size_r; i ++) {
    if (oldpt && ((oldentry = findprocess(pt[i].pid, oldpt, *oldsize_r)) != -1)) {
      pt[i].cputime_prev = oldpt[oldentry].cputime;
      pt[i].time_prev    = oldpt[oldentry].time;
 
      /* The cpu_percent may be set already (for example by HPUX module) */
      if (pt[i].cpu_percent  == 0 && pt[i].cputime_prev != 0 && pt[i].cputime != 0 && pt[i].cputime > pt[i].cputime_prev) {
        pt[i].cpu_percent = (int)((1000 * (double)(pt[i].cputime - pt[i].cputime_prev) / (pt[i].time - pt[i].time_prev)) / systeminfo.cpus);
        if (pt[i].cpu_percent > 1000 / systeminfo.cpus)
          pt[i].cpu_percent = 1000 / systeminfo.cpus;
      }
    } else {
      pt[i].cputime_prev = 0;
      pt[i].time_prev    = 0.0;
      pt[i].cpu_percent  = 0;
    }
        
    if (pt[i].pid == pt[i].ppid) {
      pt[i].parent = i;
      continue;
    }

    if ((pt[i].parent = findprocess(pt[i].ppid, pt, *size_r)) == -1) {
      /* Parent process wasn't found - on Linux this is normal: main process with PID 0 is not listed, similarly in FreeBSD jail.
       * We create virtual process entry for missing parent so we can have full tree-like structure with root. */
      int j = (*size_r)++;

      pt = *pt_r = xresize(*pt_r, *size_r * sizeof(ProcessTree_T));
      memset(&pt[j], 0, sizeof(ProcessTree_T));
      pt[j].ppid = pt[j].pid  = pt[i].ppid;
      pt[i].parent = j;
    }
    
    if (! connectchild(pt, pt[i].parent, i)) {
      /* connection to parent process has failed, this is usually caused in the part above */
      DEBUG("system statistic error -- cannot connect process id %d to its parent %d\n", pt[i].pid, pt[i].ppid);
      pt[i].pid = 0;
      continue;
    }
  }

  /* The main process in Solaris zones and FreeBSD host doesn't have pid 1, so try to find process which is parent of itself */
  for (i = 0; i < *size_r; i++) {
    if (pt[i].pid == pt[i].ppid) {
      root = i;
      break;
    }
  }

  if (root == -1) {
    DEBUG("system statistic error -- cannot find root process id\n");
    return -1;
  }

  fillprocesstree(pt, root);
  update_system_load(*pt_r, *size_r);

  return *size_r;
}