/[monit]/monit/http/cervlet.c
ViewVC logotype

Diff of /monit/http/cervlet.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.20 by chopp, Fri Sep 6 08:28:50 2002 UTC revision 1.21 by hauk, Fri Sep 6 09:54:52 2002 UTC
# Line 71  static void not_found(HttpRequest, HttpR Line 71  static void not_found(HttpRequest, HttpR
71  static void do_runtime(HttpRequest, HttpResponse);  static void do_runtime(HttpRequest, HttpResponse);
72  static void do_viewlog(HttpRequest, HttpResponse);  static void do_viewlog(HttpRequest, HttpResponse);
73  static void handle_action(HttpRequest, HttpResponse);  static void handle_action(HttpRequest, HttpResponse);
74    static void print_status(Process_T, HttpResponse res);
75  static void is_monit_running(HttpRequest, HttpResponse);  static void is_monit_running(HttpRequest, HttpResponse);
76  static void do_process(HttpRequest, HttpResponse, char *);  static void do_process(HttpRequest, HttpResponse, char *);
77    
# Line 231  static void do_home(HttpRequest req, Htt Line 232  static void do_home(HttpRequest req, Htt
232  "<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">"  "<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">"
233  "<tr><td><h3><b>Server</b></h3></td>"  "<tr><td><h3><b>Server</b></h3></td>"
234  "<td align=\"right\"><h3><b>Status</b></h3></td>"  "<td align=\"right\"><h3><b>Status</b></h3></td>"
235  "<td align=\"center\"><h3><b>Uptime</b></h3></td>"  "<td align=\"right\"><h3><b>Uptime</b></h3></td>"
236  "<td align=\"center\"><h3><b>CPU</b></h3></td>"  "<td align=\"right\"><h3><b>CPU</b></h3></td>"
237  "<td align=\"center\"><h3><b>Memory</b></h3></td>"  "<td align=\"right\"><h3><b>Memory</b></h3></td>"
238  "</tr>"  "</tr>"
239  "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>", Run.localhostname, uptime);  "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>", Run.localhostname, uptime);
240    } else {    } else {
# Line 318  static void do_home(HttpRequest req, Htt Line 319  static void do_home(HttpRequest req, Htt
319    }    }
320    out_print(res, "</table>");    out_print(res, "</table>");
321    FOOT    FOOT
   
322                
323  }  }
324    
# Line 500  static void handle_action(HttpRequest re Line 500  static void handle_action(HttpRequest re
500    char *name= req->url;    char *name= req->url;
501    char *action= get_parameter(req, "action");    char *action= get_parameter(req, "action");
502        
503    if ( exist_process(++name) ) {    if(exist_process(++name)) {
504            
505      if ( action ) {      if(action) {
506                
507        struct myprocess *p= get_process(name);        struct myprocess *p= get_process(name);
508                
509        if ( strstr(action, "start") ) {        if(is(action, "start")) {
510                    
511          LOCK(Run.mutex)          LOCK(Run.mutex)
512              p->do_validate= TRUE;              p->do_validate= TRUE;
# Line 515  static void handle_action(HttpRequest re Line 515  static void handle_action(HttpRequest re
515                    
516        }        }
517                
518        if ( strstr(action, "stop") ) {        if(is(action, "stop")) {
519                    
520          LOCK(Run.mutex)          LOCK(Run.mutex)
521              p->do_validate= FALSE;              p->do_validate= FALSE;
# Line 524  static void handle_action(HttpRequest re Line 524  static void handle_action(HttpRequest re
524                    
525        }        }
526    
527        if ( strstr(action, "status") ) {        if(is(action, "status")) {
   
         FILE *out= res->outputstream;  
         pid_t  pid= -1;  
       
         res->is_committed= TRUE;  
   
     
         if ( (pid= is_process_running(p)) ) {  
528    
529            char *uptime= get_process_uptime(p->pidfile);          print_status(p, res);
530            ProcInfo_T pi= p->procinfo;          goto quit;
531                      
           fprintf(out,  
                   "Process '%s' is running with pid [%d] Uptime: %s "  
                   "CPU: %.1f%% Memory: %.1f%% [%ldkB]\n",  
                   p->name, (int)pid, uptime,  
                   pi->cpu_percent/10.0,  
                   pi->mem_percent/10.0,pi->mem_kbyte);  
             
           free(uptime);  
             
         } else {  
             
           fprintf(out, "Process '%s' is not running\n",  p->name);  
       
         }  
   
         fputc(0,out);  
         free(action);  
   
         return;  
532        }        }
533                
534        sleep(2);        sleep(2);
# Line 572  static void handle_action(HttpRequest re Line 545  static void handle_action(HttpRequest re
545            
546    }    }
547    
548      quit:
549    free(action);    free(action);
550        
551  }  }
# Line 766  static void do_process(HttpRequest req, Line 740  static void do_process(HttpRequest req,
740        
741  }  }
742    
743    
744    static void print_status(Process_T p, HttpResponse res) {
745    
746      FILE *out= res->outputstream;
747      pid_t  pid= -1;
748      
749      res->is_committed= TRUE;
750      
751      if((pid= is_process_running(p))) {
752        
753        char *uptime= get_process_uptime(p->pidfile);
754        ProcInfo_T pi= p->procinfo;
755        
756        fprintf(out,
757                "Process '%s' is running with pid [%d] \n\tUptime: %s "
758                "CPU: %.1f%% Memory: %.1f%% [%ldkB]\n",
759                p->name, (int)pid, uptime,
760                pi->cpu_percent/10.0,
761                pi->mem_percent/10.0,pi->mem_kbyte);
762        
763        free(uptime);
764        
765      } else {
766        
767        fprintf(out, "Process '%s' is not running\n",  p->name);
768        
769      }
770      
771    }
772    
773    
774  static void printPixel(HttpResponse res) {  static void printPixel(HttpResponse res) {
775    

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26