ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/plugins/linux/linux.c
(Generate patch)

Comparing projects/cms/source/host/ihost-perl/plugins/linux/linux.c (file contents):
Revision 1.4 by tdb, Fri Mar 8 16:04:38 2002 UTC vs.
Revision 1.8 by pajs, Tue Apr 2 12:43:15 2002 UTC

# Line 7 | Line 7
7   #include <sys/vfs.h>
8   #include <utmp.h>
9   #include <pwd.h>
10 + #include <mntent.h>
11  
12   int die() {
13      exit (1);
14   }
15  
16   void getLoadAv() {
17 <    FILE *f;
18 <    char *loadavg;
19 <    char *load_p;
20 <      
21 <    if ((f=fopen("/proc/loadavg", "r" ))==NULL) {
22 <        errf("Failed to open load averages (%m)");
23 <        die();
24 <    }
25 <    
26 <    if ((loadavg=fpgetline(f)) == NULL) {
27 <        errf("Failed to read any data for load averages (%m)");
28 <        die();
28 <    }
29 <    
30 <    if ((fclose(f)) != 0) {
31 <        errf("Failed to close file (%m).");
32 <        die();
33 <    }
34 <    
35 <    load_p=strtok(loadavg, " ");
36 <    printf("packet.load.load1 %s\n",load_p);
37 <    for(; (*load_p != ' ') && (*load_p != '\0'); load_p++);
38 <    load_p++;
39 <    if (load_p == NULL) abort();
40 <    load_p=strtok(load_p, " ");
41 <    if (load_p == NULL) abort();
42 <    printf("packet.load.load5 %s\n",load_p);
43 <    for(; (*load_p != ' ') && (*load_p != '\0'); load_p++);
44 <    load_p++;
45 <    if (load_p == NULL) abort();
46 <    load_p=strtok(load_p, " ");
47 <    if (load_p == NULL) abort();
48 <    printf("packet.load.load15 %s\n",load_p);
17 >
18 >  double loadav[3];
19 >
20 >  if((getloadavg(loadav,3)) == -1){
21 >    errf("Failed to get load averages (%m)");
22 >    die();
23 >  }
24 >  
25 >  printf("packet.load.load1 %.2f\n",loadav[0]);
26 >  printf("packet.load.load5 %.2f\n",loadav[1]);
27 >  printf("packet.load.load15 %.2f\n",loadav[2]);
28 >  
29   }
30  
31   void getMemInfo() {
32      char *line;
33 <    char *mem;
34 <    char *swap;
33 >    char *mem=NULL;
34 >    char *swap=NULL;
35      char *ch;
36      long memstat[6];
37      long swapstat[3];
# Line 80 | Line 60 | void getMemInfo() {
60          errf("Failed to close file (%m).");
61          die();
62      }
63 <    
63 >  
64 >    if (mem==NULL || swap==NULL){
65 >        errf("Failed to obtain information required for memory and swap stats");
66 >        die();
67 >    }
68 >
69      /* Get the info we want from the 2 read in lines */
70      
71      ch = strchr(mem, ' ');
# Line 218 | Line 203 | void cpustats() {
203      usage=((((float)idle)/((float)total))*100.00);
204      printf("packet.cpu.idle %3.2f\n", usage);
205      
206 <    /* Cos i-scream's expexts this to be sent :/ */
206 >    /* Cos i-scream's expects this to be sent :/ */
207      printf("packet.cpu.iowait 0\n");
208 <    
208 >    printf("packet.cpu.swap 0\n");  
209 >
210      free(line[0]);
211      free(line[1]);
212   }
213  
214   void processStats() {
215 <    int sleeping=0;
215 >    int sleeping=-1;
216      int zombie=0;
217      int stopped=0;
218      int running=0;
# Line 243 | Line 229 | void processStats() {
229      }
230      
231      while((line=fpgetline(f)) != NULL) {
232 <        line_p=strchr(line, ' ');
233 <        line_p++;
234 <        if (line_p==NULL) abort();
235 <        /* Ok, we should now be at the state :) .. */
236 <        if (*line_p=='S') sleeping++;
237 <        if (*line_p=='R') running++;
238 <        if (*line_p=='Z') zombie++;
239 <        if (*line_p=='T') stopped++;
232 >
233 >      line_p=line;
234 >      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
235 >      line_p=strchr(line_p, ' ');
236 >      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
237 >      if (line_p==NULL) abort();
238 >      /* Ok, we should now be at the state :) .. */
239 >      if (*line_p=='S') sleeping++;
240 >      if (*line_p=='R') running++;
241 >      if (*line_p=='Z') zombie++;
242 >      if (*line_p=='T') stopped++;
243      }
244      
245      if((pclose(f)) == -1) {
# Line 269 | Line 258 | void processStats() {
258      
259      printf("\npacket.users.count %d\n", nousers);
260        
261 <    printf("packet.processes.total %d\n",sleeping);
262 <    printf("packet.processes.sleeping %d\n",running);
261 >    printf("packet.processes.sleeping %d\n",sleeping);
262 >    printf("packet.processes.cpu %d\n",running);
263      printf("packet.processes.zombie %d\n",zombie);
264      printf("packet.processes.stopped %d\n", stopped);
265      printf("packet.processes.total %d\n", (sleeping+running+zombie+stopped));
# Line 319 | Line 308 | void osStats() {
308   }
309  
310   void diskStats() {
311 <    struct statfs df;
312 <    FILE *f;
313 <    char *line;
314 <    char *line_p;
315 <    long bstok;
316 <    int diskcnt=0;
317 <    
318 <    if ((f=fopen("/etc/mtab", "r")) == NULL) {
319 <        errf("Failed to get uptime stats (%m)");
320 <        die();
311 >
312 >  struct mntent *mp;
313 >  struct statfs df;
314 >  FILE *f;
315 >  int counter=0;
316 >
317 >  if ((f=fopen("/etc/mtab", "r" ))==NULL){
318 >      errf("Failed to open mounts (%m)");
319 >      die();
320 >  }
321 >
322 >  while((mp=getmntent(f))){
323 >    if ((statfs(mp->mnt_dir, &df)) !=0){
324 >      errf("Failed to gets fs stats (%m)");
325 >      continue;
326      }
327 +
328 +    if((((strcmp(mp->mnt_type, MNTTYPE_NFS))==0) ||  (strcmp(mp->mnt_type,MNTTYPE_IGNORE)) ==0)) continue;
329      
330 <    while((line=fpgetline(f)) != NULL) {
331 <        line_p=strchr(line, ' ');
332 <        if(line_p==NULL) abort();
333 <        *line_p='\0';
334 <        line_p++;
335 <        if(line_p==NULL) abort();
336 <        printf("packet.disk.p%d.attributes.name %s\n",diskcnt,line);
337 <        line=strchr(line_p, ' ');
338 <        if(line==NULL) abort();
339 <        *line='\0';
340 <        printf("packet.disk.p%d.attributes.mount %s\n",diskcnt,line_p);
341 <        if((statfs(line_p, &df)) != 0) {
342 <            errf("Failed to get Filesystem stats (%m)");
347 <            die();
348 <        }
349 <        bstok=(df.f_bsize/1024);
350 <        printf("packet.disk.p%d.attributes.kbytes %ld\n",diskcnt,bstok*df.f_blocks);
351 <        printf("packet.disk.p%d.attributes.used %ld\n" ,diskcnt, ((bstok*df.f_blocks)-(bstok*df.f_bfree)));
352 <        printf("packet.disk.p%d.attributes.avail %ld\n", diskcnt, (df.f_bsize/1024)*df.f_bavail);
353 <        printf("packet.disk.p%d.attributes.totalinodes %ld\n", diskcnt, df.f_files);
354 <        printf("packet.disk.p%d.attributes.freeinodes %ld\n", diskcnt, df.f_ffree);
355 <        diskcnt++;
356 <    }
330 >      printf("packet.disk.p%d.attributes.mount %s\n", counter, mp->mnt_dir);
331 >      printf("packet.disk.p%d.attributes.name %s\n", counter, mp->mnt_fsname);
332 >      printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_bsize/1024) * df.f_blocks));
333 >      printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_bsize/1024) * df.f_blocks) -((df.f_bsize/1024) * df.f_bfree)));
334 >      printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_bsize/1024) * df.f_bavail);
335 >      printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files);
336 >      printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree);
337 >    
338 >      counter++;
339 >  }
340 >
341 >  
342 >
343   }
344  
345   int main() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines