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

Diff of /monit/status.c

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

revision 1.25 by hauk, Fri Jun 6 16:43:06 2003 UTC revision 1.26 by martinp, Mon Jun 9 19:33:42 2003 UTC
# Line 158  void status_group(char *G) { Line 158  void status_group(char *G) {
158  static void local_status(Process_T p) {  static void local_status(Process_T p) {
159        
160    pid_t  pid= -1;    pid_t  pid= -1;
161      struct stat stat_buf;
162    
163    ASSERT(p);    ASSERT(p);
164        
165    if((pid= is_process_running(p))) {    switch(p->task) {
166    
167      char *uptime= get_process_uptime(p->pidfile);    case TASK_PROCESS:
168        if((pid= is_process_running(p))) {
169    
170      fprintf(stdout, "Process '%s' is running with pid [%d] Uptime: %s "        char *uptime= get_process_uptime(p->path);
171              "Monitoring status: %s\n",  
172              p->name, (int)pid, uptime, statusnames[p->do_validate]);        fprintf(stdout, "Process '%s' is running with pid [%d]\n\t"
173            "Uptime: %s\n\t"
174            "Monitoring status: %s\n",
175            p->name, (int)pid, uptime, statusnames[p->do_validate]);
176            
177      free(uptime);        free(uptime);
178    
179    } else {      } else {
180            
181      fprintf(stdout, "Process '%s' is not running\n",  p->name);        fprintf(stdout, "Process '%s' is not running\n",  p->name);
182            
183        }
184        break;
185    
186      case TASK_DEVICE:
187        if(!get_fsusage(p->path, p->devinfo)) {
188          fprintf(stdout, "Device '%s' is not accessible\n\t"
189            "Space: - Inodes: -\n\tMonitoring status: %s\n",
190            p->name, statusnames[p->do_validate]);
191        } else {
192    
193          if(p->devinfo->f_files > 0) {
194    
195            fprintf(stdout, "Device '%s' is accessible\n\t"
196              "Space: %.1f%% [%.1f MB] Inodes: %.1f%% [%ld objects]\n\t"
197              "Monitoring status: %s\n",
198              p->name,
199              (float) 100 * (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / p->devinfo->f_blocks,
200              (float) (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / 1048576 * p->devinfo->f_bsize,
201              (float) 100 * (p->devinfo->f_files - p->devinfo->f_filesfree) / p->devinfo->f_files,
202              p->devinfo->f_files - p->devinfo->f_filesfree,
203              statusnames[p->do_validate]);
204    
205          } else {
206    
207            fprintf(stdout, "Device '%s' is accessible\n\t"
208              "Space: %.1f%% [%.1f MB]\n\t"
209              "Monitoring status: %s\n",
210              p->name,
211              (float) 100 * (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / p->devinfo->f_blocks,
212              (float) (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / 1048576 * p->devinfo->f_bsize,
213              statusnames[p->do_validate]);
214    
215          }
216    
217        }
218        break;
219    
220      case TASK_FILE:
221        if( (stat(p->path, &stat_buf) != 0) || !S_ISREG(stat_buf.st_mode) ) {
222          fprintf(stdout, "File '%s' doesn't exist\n\tMonitoring status: %s\n",
223            p->name, statusnames[p->do_validate]);
224        } else {
225          fprintf(stdout,
226            "File '%s' exist\n\t"
227            "Size: %.3f MB UID: %d GID: %d Permission: %o\n\t"
228            "Monitoring status: %s\n",
229            p->name,
230            (float)stat_buf.st_size/1048576, (int)stat_buf.st_uid,
231            (int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777),
232            statusnames[p->do_validate]);
233        }
234        break;
235    
236      case TASK_DIRECTORY:
237        if( (stat(p->path, &stat_buf) != 0) || !S_ISDIR(stat_buf.st_mode) ) {
238          fprintf(stdout, "Directory '%s' doesn't exist\n\tMonitoring status: %s\n",
239            p->name, statusnames[p->do_validate]);
240        } else {
241          fprintf(stdout,
242            "Directory '%s' exist\n\t"
243            "UID: %d GID: %d Permission: %o\n\t"
244            "Monitoring status: %s\n",
245            p->name,
246            (int)stat_buf.st_uid, (int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777),
247            statusnames[p->do_validate]);
248        }
249        break;
250    
251      default:
252        break;
253    
254    }    }
255      
256  }  }
257    
258    
# Line 259  static int remote_status(Process_T p, ss Line 335  static int remote_status(Process_T p, ss
335                
336    
337        /* If everything has gone well the returned string starts with        /* If everything has gone well the returned string starts with
338           "Process " */           "Process ", "Device ", "File " or "Directory " */
339    
340        buf[n]= 0;        buf[n]= 0;
341        if(starts_with(buf, "Process ")) {        if(starts_with(buf, "Process ") ||
342             starts_with(buf, "Device ") ||
343             starts_with(buf, "File ") ||
344             starts_with(buf, "Directory ")) {
345    
346          fprintf(stdout, "%s", buf);          fprintf(stdout, "%s", buf);
347                    
348        } else {        } else {
349    
350          fprintf(stdout, "The monit server did not return a process record.\n");          fprintf(stdout, "The monit server did not return a process, "
351              "device, file or directory record.\n");
352          local_status(p);          local_status(p);
353            
         return TRUE;  
   
354        }        }
355    
356        return TRUE;        return TRUE;

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

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