/[monit]/monit/status.c
ViewVC logotype

Diff of /monit/status.c

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

revision 1.32 by hauk, Thu Jul 24 00:35:25 2003 UTC revision 1.33 by hauk, Sat Aug 2 00:05:54 2003 UTC
# Line 47  Line 47 
47  #include "monit_device.h"  #include "monit_device.h"
48    
49    
   
50  /* Private Prototypes */  /* Private Prototypes */
51  static void local_status(Service_T);  static void local_status(Service_T);
52  static int remote_status(Service_T);  static int remote_status(Service_T);
53    
54    
55  /**  /**
56   *  Print the status of services in the service list.   *  Print the status of services in the service list.
57   *   *
# Line 72  static int remote_status(Service_T); Line 72  static int remote_status(Service_T);
72  void status() {  void status() {
73    
74    Service_T s;    Service_T s;
   int remote= TRUE;  
75    char *uptime= get_process_uptime(Run.pidfile);    char *uptime= get_process_uptime(Run.pidfile);
76    
77    fprintf(stdout, "monit daemon uptime: %s\n", uptime);    if(IS(uptime, "")) {
78        fprintf(stdout, "The monit daemon is not running\n");
79      } else {
80        fprintf(stdout, "The monit daemon uptime: %s\n",uptime);
81      }
82    free(uptime);    free(uptime);
83        
84    for(s= servicelist; s; s= s->next) {    for(s= servicelist; s; s= s->next) {
85        remote_status(s);
     if(remote) {  
   
       remote= remote_status(s);  
         
     } else {  
         
       local_status(s);  
         
     }  
       
86    }    }
87    
88  }  }
89    
90    
91  /**  /**
92   * Show all services in the group   * Show all services in the group
93   * @param G  group name   * @param G  group name
# Line 101  void status() { Line 95  void status() {
95  void status_group(char *G) {  void status_group(char *G) {
96    
97    Service_T s;    Service_T s;
   int remote= TRUE;  
98    
99    ASSERT(G);    ASSERT(G);
100        
101    for(s= servicelist; s; s= s->next) {    for(s= servicelist; s; s= s->next) {
   
102      if(IS(s->group, G)) {      if(IS(s->group, G)) {
103                remote_status(s);
       if(remote) {  
           
         remote= remote_status(s);  
   
       } else {  
           
         local_status(s);  
   
       }  
   
104      }      }
       
105    }    }
106        
107  }  }
# Line 147  static void local_status(Service_T s) { Line 128  static void local_status(Service_T s) {
128    
129        char *uptime= get_process_uptime(s->path);        char *uptime= get_process_uptime(s->path);
130    
131        fprintf(stdout, "Process '%s' is running with pid [%d]\n\t"        fprintf(stdout, "Process '%s' is running with pid [%d]\t"
132                "Uptime: %s\n\tMonitoring status: %s\n",                "Uptime: %s\n", s->name, (int)pid, uptime);
               s->name, (int)pid, uptime, statusnames[s->do_monitor]);  
133            
134        free(uptime);        free(uptime);
135    
# Line 163  static void local_status(Service_T s) { Line 143  static void local_status(Service_T s) {
143    case TASK_DEVICE:    case TASK_DEVICE:
144      if(!DeviceInfo_Usage(s->devinfo, s->path)) {      if(!DeviceInfo_Usage(s->devinfo, s->path)) {
145        fprintf(stdout, "Device '%s' is not accessible\n\t"        fprintf(stdout, "Device '%s' is not accessible\n\t"
146          "Space: - Inodes: -\n\tMonitoring status: %s\n",                "Space: - Inodes: -\n", s->name);
         s->name, statusnames[s->do_monitor]);  
147      } else {      } else {
148    
149        if(s->devinfo->f_files > 0) {        if(s->devinfo->f_files > 0) {
150    
151          fprintf(stdout, "Device '%s' is accessible\n\t"          fprintf(stdout, "Device '%s' is accessible\n\t"
152            "Space: %.1f%% [%.1f MB] Inodes: %.1f%% [%ld objects]\n\t"                  "Space: %.1f%% [%.1f MB] Inodes: %.1f%% [%ld objects]\n",
153            "Monitoring status: %s\n",                  s->name,
154            s->name,                  (float) 100 * (s->devinfo->f_blocks -
155            (float) 100 * (s->devinfo->f_blocks - s->devinfo->f_blocksfree) / s->devinfo->f_blocks,                                 s->devinfo->f_blocksfree) /
156            (float) (s->devinfo->f_blocks - s->devinfo->f_blocksfree) / 1048576 * s->devinfo->f_bsize,                  s->devinfo->f_blocks,
157            (float) 100 * (s->devinfo->f_files - s->devinfo->f_filesfree) / s->devinfo->f_files,                  (float) (s->devinfo->f_blocks - s->devinfo->f_blocksfree) /
158            s->devinfo->f_files - s->devinfo->f_filesfree,                  1048576 * s->devinfo->f_bsize,
159            statusnames[s->do_monitor]);                  (float) 100 * (s->devinfo->f_files - s->devinfo->f_filesfree) /
160                    s->devinfo->f_files,
161                    s->devinfo->f_files - s->devinfo->f_filesfree);
162            
163        } else {        } else {
164    
165          fprintf(stdout, "Device '%s' is accessible\n\t"          fprintf(stdout, "Device '%s' is accessible\n\t"
166                  "Space: %.1f%% [%.1f MB]\n\tMonitoring status: %s\n",                  "Space: %.1f%% [%.1f MB]\n",
167                  s->name,                  s->name,
168            (float) 100 * (s->devinfo->f_blocks - s->devinfo->f_blocksfree) / s->devinfo->f_blocks,                  (float) 100 * (s->devinfo->f_blocks -
169            (float) (s->devinfo->f_blocks - s->devinfo->f_blocksfree) / 1048576 * s->devinfo->f_bsize,                                 s->devinfo->f_blocksfree) / s->devinfo->f_blocks,
170            statusnames[s->do_monitor]);                  (float) (s->devinfo->f_blocks - s->devinfo->f_blocksfree) /
171                    1048576 * s->devinfo->f_bsize);
172        }        }
173    
174      }      }
175      break;      break;
176    
177    case TASK_FILE:    case TASK_FILE:
178      if( (stat(s->path, &stat_buf) != 0) || !S_ISREG(stat_buf.st_mode) ) {        if( (stat(s->path, &stat_buf) != 0) || !S_ISREG(stat_buf.st_mode) ) {
179        fprintf(stdout, "File '%s' doesn't exist\n\tMonitoring status: %s\n",          fprintf(stdout, "File '%s' doesn't exist\n",
180          s->name, statusnames[s->do_monitor]);                  s->name);
181      } else {        } else {
182        fprintf(stdout,          fprintf(stdout,
183          "File '%s' exist\n\t"                  "File '%s' exist\n\t"
184          "Size: %.3f MB UID: %d GID: %d Permission: %o\n\t"                  "Size: %.3f MB UID: %d GID: %d Permission: %o\n",
185          "Monitoring status: %s\n",                  s->name,
186          s->name,                  (float)stat_buf.st_size/1048576, (int)stat_buf.st_uid,
187          (float)stat_buf.st_size/1048576, (int)stat_buf.st_uid,                  (int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777));
188          (int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777),        }
189          statusnames[s->do_monitor]);        break;
190      }        
     break;  
   
191    case TASK_DIRECTORY:    case TASK_DIRECTORY:
192      if( (stat(s->path, &stat_buf) != 0) || !S_ISDIR(stat_buf.st_mode) ) {        if( (stat(s->path, &stat_buf) != 0) || !S_ISDIR(stat_buf.st_mode) ) {
193        fprintf(stdout, "Directory '%s' doesn't exist\n\tMonitoring status: %s\n",          fprintf(stdout, "Directory '%s' doesn't exist\n", s->name);
194          s->name, statusnames[s->do_monitor]);        } else {
195      } else {          fprintf(stdout,
196        fprintf(stdout,                  "Directory '%s' exist\n\t"
197                "Directory '%s' exist\n\t"                  "UID: %d GID: %d Permission: %o\n",
198                "UID: %d GID: %d Permission: %o\n\t"                  s->name,
199                "Monitoring status: %s\n",                  (int)stat_buf.st_uid, (int)stat_buf.st_gid,
200                s->name,                  (int)(stat_buf.st_mode & 07777));
201                (int)stat_buf.st_uid, (int)stat_buf.st_gid,        }
202                (int)(stat_buf.st_mode & 07777),        break;
203                statusnames[s->do_monitor]);        
     }  
     break;  
   
204    default:    default:
205      break;        break;
206          
207    }    }
208    
209  }  }
# Line 249  static int remote_status(Service_T s) { Line 225  static int remote_status(Service_T s) {
225      Socket_T sock= socket_new(Run.bind_addr?Run.bind_addr:"localhost",      Socket_T sock= socket_new(Run.bind_addr?Run.bind_addr:"localhost",
226                                Run.httpdport, SOCKET_TCP, Run.httpdssl);                                Run.httpdport, SOCKET_TCP, Run.httpdssl);
227      if(!sock) {      if(!sock) {
228          
       fprintf(stdout,  
               "Cannot connect to monit server to get extended service data.\n");  
229        local_status(s);        local_status(s);
230                
231        return FALSE;        return FALSE;
232                      
233      } else {      } else {
234    
235        int n;        int n;
# Line 304  static int remote_status(Service_T s) { Line 278  static int remote_status(Service_T s) {
278            
279      /* No monit daemon exist, just print local status information */      /* No monit daemon exist, just print local status information */
280            
     fprintf(stdout, "Cannot connect to the monit server to get extended "  
             "process data.\n");  
281      local_status(s);      local_status(s);
282            
283      return FALSE;      return FALSE;

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.33

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