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.2 by pajs, Fri Mar 8 10:22:56 2002 UTC vs.
Revision 1.12 by pajs, Fri May 3 13:24:10 2002 UTC

# Line 1 | Line 1
1   #include <stdio.h>
2   #include <stdlib.h>
3 < #include <local/ukcprog.h>
3 > #include "ukcprog.h"
4   #include <string.h>
5   #include <unistd.h>
6   #include <sys/utsname.h>
7   #include <sys/vfs.h>
8   #include <utmp.h>
9   #include <pwd.h>
10 + #include <mntent.h>
11 + #include <dirent.h>
12 + #include <limits.h>
13  
14 < int die()
15 < {
13 <   exit (1);
14 > int die() {
15 >    exit (1);
16   }
17  
18 < void getLoadAv()
19 < {
20 <   FILE *f;
21 <   char *loadavg;
22 <   char *load_p;
23 <      
24 <   if ((f=fopen("/proc/loadavg", "r" ))==NULL)
25 <     {
26 <        errf("Failed to open load averages (%m)");
27 <        die();
28 <     }
29 <  
30 <  
31 <   if ((loadavg=fpgetline(f)) == NULL)
32 <     {
33 <        errf("Failed to read any data for load averages (%m)");
34 <        die();
35 <     }
36 <  
37 <  
38 <   if ((fclose(f)) != 0)
39 <     {
40 <        
41 <        errf("Failed to close file (%m).");
42 <        die();
43 <     }
44 <  
45 <
46 <  
18 > void getLoadAv() {
19 > #ifdef OLDLIBC
20 >  
21 >  FILE *f;
22 >  char *loadavg;
23 >  char *load_p;
24 >  
25 >  if ((f=fopen("/proc/loadavg", "r" ))==NULL) {
26 >    errf("Failed to open load averages (%m)");
27 >    die();
28 >  }
29 >  
30 >  if ((loadavg=fpgetline(f)) == NULL) {
31 >    errf("Failed to read any data for load averages (%m)");
32 >    die();
33 >  }
34 >  
35 >  if ((fclose(f)) != 0) {
36 >    errf("Failed to close file (%m).");
37 >    die();
38 >  }
39 >  
40 >  load_p=strtok(loadavg, " ");
41 >  printf("packet.load.load1 %s\n",load_p);
42 >  for(; (*load_p != ' ') && (*load_p != '\0'); load_p++);
43 >  load_p++;
44 >  if (load_p == NULL) abort();
45 >  load_p=strtok(load_p, " ");
46 >  if (load_p == NULL) abort();
47 >  printf("packet.load.load5 %s\n",load_p);
48 >  for(; (*load_p != ' ') && (*load_p != '\0'); load_p++);
49 >  load_p++;
50 >  if (load_p == NULL) abort();
51 >  load_p=strtok(load_p, " ");
52 >  if (load_p == NULL) abort();
53 >  printf("packet.load.load15 %s\n",load_p);
54  
55 <   load_p=strtok(loadavg, " ");
56 <   printf("packet.load.load1 %s\n",load_p);
48 <   for(; (*load_p != ' ') && (*load_p != '\0'); load_p++);
49 <   load_p++;
50 <   if (load_p == NULL) abort();
51 <   load_p=strtok(load_p, " ");
52 <   if (load_p == NULL) abort();
53 <   printf("packet.load.load5 %s\n",load_p);
54 <   for(; (*load_p != ' ') && (*load_p != '\0'); load_p++);
55 <   load_p++;
56 <   if (load_p == NULL) abort();
57 <   load_p=strtok(load_p, " ");
58 <   if (load_p == NULL) abort();
59 <   printf("packet.load.load15 %s\n",load_p);
55 > #else
56 >  double loadav[3];
57  
58 +  if((getloadavg(loadav,3)) == -1){
59 +    errf("Failed to get load averages (%m)");
60 +    die();
61 +  }
62 +  
63 +  printf("packet.load.load1 %.2f\n",loadav[0]);
64 +  printf("packet.load.load5 %.2f\n",loadav[1]);
65 +  printf("packet.load.load15 %.2f\n",loadav[2]);
66 + #endif
67   }
68  
69 < void getMemInfo()
70 < {
71 <   char *line;
72 <   char *mem;
73 <   char *swap;
74 <   char *ch;
75 <   long memstat[6];
76 <   long swapstat[3];
77 <   long tmp;
78 <   int counter=0;
79 <
80 <   FILE *f;
69 > void getMemInfo() {
70 >    char *line;
71 >    char *mem=NULL;
72 >    char *swap=NULL;
73 >    char *ch;
74 >    long memstat[6];
75 >    long swapstat[3];
76 >    long tmp;
77 >    int counter=0;
78 >    
79 >    FILE *f;
80 >    
81 >    if ((f=fopen("/proc/meminfo", "r" ))==NULL) {
82 >        errf("Failed to open memory stats (%m)");
83 >        die();
84 >    }
85 >    
86 >    while(((line=fpgetline(f)) != NULL) && (counter < 2)) {
87 >        if (((strncmp("Mem: ",line,5)) == 0)) {
88 >            mem=strdup(line);
89 >            counter++;
90 >        }
91 >        if (((strncmp(line,"Swap: ",6)) == 0)) {
92 >            swap=strdup(line);
93 >            counter++;
94 >        }
95 >    }
96 >    
97 >    if ((fclose(f)) != 0) {
98 >        errf("Failed to close file (%m).");
99 >        die();
100 >    }
101    
102 <   if ((f=fopen("/proc/meminfo", "r" ))==NULL)
103 <     {
78 <        errf("Failed to open memory stats (%m)");
102 >    if (mem==NULL || swap==NULL){
103 >        errf("Failed to obtain information required for memory and swap stats");
104          die();
105 <     }
81 <  
82 <   /* Readin being the number of lines we want to get.. Once we have them, why bother continuing */
83 <   while(((line=fpgetline(f)) != NULL) && (counter < 2) )
84 <     {
85 <        
86 <        if (((strncmp("Mem: ",line,5)) == 0))
87 <          {
88 <             mem=strdup(line);
89 <             counter++;
90 <          }
91 <        if (((strncmp(line,"Swap: ",6)) == 0))
92 <          {
93 <             swap=strdup(line);
94 <             counter++;
95 <          }
96 <     }
97 <  
98 <  
99 <   if ((fclose(f)) != 0)
100 <     {
101 <        errf("Failed to close file (%m).");
102 <        die();
103 <     }
105 >    }
106  
107 <   /* Get the info we want from the 2 read in lines */
108 <  
109 <   ch = strchr(mem, ' ');
110 <   if (ch == NULL) abort();
111 <   *ch = '\0';
112 <   ch++;
113 <   /* By now we should of skipped the mem: bit.. onto the numbers */
114 <  
115 <   for(counter=0;counter<6;counter++)
116 <     {
117 <        for (; (*ch == ' '); ch++);
118 <        if (ch == NULL) abort();
119 <        memstat[counter]=atol(ch);
120 <        ch++;
121 <        for(; (*ch != ' ') && (*ch != '\0'); ch++);
122 <        if (ch == NULL) abort();
123 <     }
124 <        
125 <      
126 <   /* Now swap.. */
127 <   ch = strchr(swap, ' ');
128 <   if (ch == NULL) abort();
129 <   *ch = '\0';
130 <   ch++;
131 <  
132 <   for(counter=0;counter<3;counter++)
133 <     {  
134 <        for (; (*ch == ' '); ch++);
135 <        if (ch == NULL) abort();
136 <        swapstat[counter]=atol(ch);
137 <        ch++;  
138 <        for(; (*ch != ' ') && (*ch != '\0'); ch++);
139 <        if (ch == NULL) abort();
140 <        
141 <     }
142 <  
143 <   printf("packet.memory.total %ld\n",((memstat[0]/1024)/1024));
144 <   /* Due to batty linux we do some maths to work out roughly what the free ram is */
145 <   tmp=((memstat[1] - memstat[4])/1024)/1024;
146 <   printf("packet.memory.used %ld\n",tmp);
147 <   tmp=((memstat[2] + memstat[4])/1024)/1024;
148 <   printf("packet.memory.free %ld\n",tmp);
149 <
150 <   printf("packet.swap.total %ld\n",((swapstat[0]/1024)/1024));
151 <   printf("packet.swap.used %ld\n",((swapstat[1]/1024)/1024));
152 <   printf("packet.swap.free %ld\n",((swapstat[2])/1024)/1024);
153 <  
152 <   free(mem);
153 <   free(swap);
154 <  
107 >    /* Get the info we want from the 2 read in lines */
108 >    
109 >    ch = strchr(mem, ' ');
110 >    if (ch == NULL) abort();
111 >    *ch = '\0';
112 >    ch++;
113 >    
114 >    /* By now we should of skipped the mem: bit.. onto the numbers */
115 >    
116 >    for(counter=0;counter<6;counter++) {
117 >        for (; (*ch == ' '); ch++);
118 >        if (ch == NULL) abort();
119 >        memstat[counter]=atol(ch);
120 >        ch++;
121 >        for(; (*ch != ' ') && (*ch != '\0'); ch++);
122 >        if (ch == NULL) abort();
123 >    }
124 >    
125 >    /* Now swap.. */
126 >    ch = strchr(swap, ' ');
127 >    if (ch == NULL) abort();
128 >    *ch = '\0';
129 >    ch++;
130 >    
131 >    for(counter=0;counter<3;counter++) {
132 >        for (; (*ch == ' '); ch++);
133 >        if (ch == NULL) abort();
134 >        swapstat[counter]=atol(ch);
135 >        ch++;
136 >        for(; (*ch != ' ') && (*ch != '\0'); ch++);
137 >        if (ch == NULL) abort();
138 >    }
139 >    
140 >    printf("packet.memory.total %ld\n",((memstat[0]/1024)/1024));
141 >    
142 >    /* Due to batty linux we do some maths to work out roughly what the free ram is */
143 >    tmp=((memstat[1] - memstat[4])/1024)/1024;
144 >    printf("packet.memory.used %ld\n",tmp);
145 >    tmp=((memstat[2] + memstat[4])/1024)/1024;
146 >    printf("packet.memory.free %ld\n",tmp);
147 >    
148 >    printf("packet.swap.total %ld\n",((swapstat[0]/1024)/1024));
149 >    printf("packet.swap.used %ld\n",((swapstat[1]/1024)/1024));
150 >    printf("packet.swap.free %ld\n",((swapstat[2])/1024)/1024);
151 >      
152 >    free(mem);
153 >    free(swap);
154   }
155  
156 < void cpustats()
157 < {
158 <   char *tmp;
159 <   char *line[2];
160 <   char *line_p[2];
161 <   long cpustats[4][2];
162 <   long user, kernel, idle;
163 <   long total;
164 <   int x,y;
165 <   float usage;
166 <   FILE *f;
167 <  
168 <   if ((f=fopen("/proc/stat", "r" ))==NULL)
169 <     {
170 <        errf("Failed to open cpu stats (%m)");
171 <        die();
172 <     }
173 <
174 <   if((tmp=fpgetline(f)) == NULL)
175 <     {
176 <        errf("Failed to read cpu stats (%m)");
177 <        die();
178 <     }
179 <
180 <   if((line[0]=strdup(tmp)) == NULL)
181 <     {
182 <        errf("strdup failed (%m)");
183 <        die();
184 <     }
185 <  
187 <   if ((fclose(f)) != 0)
188 <     {
189 <        errf("Failed to close file (%m).");
190 <        die();
191 <     }
156 > void cpustats() {
157 >    char *tmp;
158 >    char *line[2];
159 >    char *line_p[2];
160 >    long cpustats[4][2];
161 >    long user, kernel, idle;
162 >    long total;
163 >    int x,y;
164 >    float usage;
165 >    FILE *f;
166 >    
167 >    if ((f=fopen("/proc/stat", "r" ))==NULL) {
168 >        errf("Failed to open cpu stats (%m)");
169 >        die();
170 >    }
171 >    
172 >    if((tmp=fpgetline(f)) == NULL) {
173 >        errf("Failed to read cpu stats (%m)");
174 >        die();
175 >    }
176 >    
177 >    if((line[0]=strdup(tmp)) == NULL) {
178 >        errf("strdup failed (%m)");
179 >        die();
180 >    }
181 >    
182 >    if ((fclose(f)) != 0) {
183 >        errf("Failed to close file (%m).");
184 >        die();
185 >    }
186      
187 <   sleep(1);
188 <  
189 <   if ((f=fopen("/proc/stat", "r" ))==NULL)
190 <     {
191 <        errf("Failed to open cpu stats (%m)");
192 <        die();
193 <     }
194 <  
195 <   if((tmp=fpgetline(f)) == NULL)
196 <     {
197 <        errf("Failed to read cpu stats (%m)");
198 <        die();
199 <     }
200 <  
201 <   if((line[1]=strdup(tmp)) == NULL)
202 <     {
209 <        errf("strdup failed (%m)");
210 <        die();
211 <     }
187 >    sleep(1);
188 >    
189 >    if ((f=fopen("/proc/stat", "r" ))==NULL) {
190 >        errf("Failed to open cpu stats (%m)");
191 >        die();
192 >    }
193 >    
194 >    if((tmp=fpgetline(f)) == NULL) {
195 >        errf("Failed to read cpu stats (%m)");
196 >        die();
197 >    }
198 >    
199 >    if((line[1]=strdup(tmp)) == NULL) {
200 >        errf("strdup failed (%m)");
201 >        die();
202 >    }
203        
204 <     if ((fclose(f)) != 0)
205 <     {
206 <        errf("Failed to close file (%m).");
207 <        die();
208 <     }
209 <  
210 <      for(x=0;x<2;x++)
211 <     {
212 <        line_p[x] = strchr(line[x], ' ');
213 <        if (line_p[x] == NULL) abort();
214 <        *line_p[x] = '\0';
215 <        line_p[x]++;
216 <     }
217 <  
218 <   /* Now should be passed "cpu " */
219 <  
220 <  
221 <   for(x=0;x<2;x++)
222 <     {
223 <        for(y=0;y<4;y++)
224 <          {
225 <             for (; (*line_p[x] == ' '); line_p[x]++);
226 <             if (line_p[x] == NULL) abort();
227 <             cpustats[y][x]=atol(line_p[x]);
228 <             line_p[x]++;      
229 <             for(; (*line_p[x] != ' ') && (*line_p[x] != '\0'); line_p[x]++);
230 <             if (line_p[x] == NULL) abort();
231 <             for (; (*line_p[x] == ' '); line_p[x]++);
232 <          }
233 <        
234 <     }
235 <  
236 <   user=cpustats[0][1]-cpustats[0][0]+cpustats[1][1]-cpustats[1][0];
237 <   kernel=cpustats[2][1]-cpustats[2][0];
238 <   idle=cpustats[3][1]-cpustats[3][0];
239 <  
240 <   /* use total to get the total number and then work out the percentages */
241 <   total=user+kernel+idle;
242 <  
243 <   usage=((((float)user)/((float)total))*100.00);
244 <   printf("packet.cpu.user %3.2f\n", usage);
245 <   usage=((((float)kernel)/((float)total))*100.00);
246 <   printf("packet.cpu.kernel %3.2f\n", usage);
247 <   usage=((((float)idle)/((float)total))*100.00);
248 <   printf("packet.cpu.idle %3.2f\n", usage);
249 <  
259 <   /* Cos iscreams broke ;) */
260 <   printf("packet.cpu.iowait 0\n");
261 <  
262 <   free(line[0]);
263 <   free(line[1]);
204 >    if ((fclose(f)) != 0) {
205 >        errf("Failed to close file (%m).");
206 >        die();
207 >    }
208 >    
209 >    for(x=0;x<2;x++) {
210 >        line_p[x] = strchr(line[x], ' ');
211 >        if (line_p[x] == NULL) abort();
212 >        *line_p[x] = '\0';
213 >        line_p[x]++;
214 >    }
215 >    
216 >    /* Now should be passed "cpu " */
217 >    
218 >    for(x=0;x<2;x++) {
219 >        for(y=0;y<4;y++) {
220 >            for (; (*line_p[x] == ' '); line_p[x]++);
221 >            if (line_p[x] == NULL) abort();
222 >            cpustats[y][x]=atol(line_p[x]);
223 >            line_p[x]++;    
224 >            for(; (*line_p[x] != ' ') && (*line_p[x] != '\0'); line_p[x]++);
225 >            if (line_p[x] == NULL) abort();
226 >            for (; (*line_p[x] == ' '); line_p[x]++);
227 >        }
228 >    }
229 >    
230 >    user=cpustats[0][1]-cpustats[0][0]+cpustats[1][1]-cpustats[1][0];
231 >    kernel=cpustats[2][1]-cpustats[2][0];
232 >    idle=cpustats[3][1]-cpustats[3][0];
233 >    
234 >    /* use total to get the total number and then work out the percentages */
235 >    total=user+kernel+idle;
236 >    
237 >    usage=((((float)user)/((float)total))*100.00);
238 >    printf("packet.cpu.user %3.2f\n", usage);
239 >    usage=((((float)kernel)/((float)total))*100.00);
240 >    printf("packet.cpu.kernel %3.2f\n", usage);
241 >    usage=((((float)idle)/((float)total))*100.00);
242 >    printf("packet.cpu.idle %3.2f\n", usage);
243 >    
244 >    /* Cos i-scream's expects this to be sent :/ */
245 >    printf("packet.cpu.iowait 0\n");
246 >    printf("packet.cpu.swap 0\n");  
247 >
248 >    free(line[0]);
249 >    free(line[1]);
250   }
251  
252 < void processStats()
253 < {
254 <   int sleeping=0;
255 <   int zombie=0;
256 <   int stopped=0;
257 <   int running=0;
258 <   int nousers=0;
259 <   char *line;
260 <   char *line_p;
261 <   struct utmp *entry;
252 > void processStats() {
253 >    int sleeping=0;
254 >    int zombie=0;
255 >    int stopped=0;
256 >    int running=0;
257 >    int nousers=0;
258 >    char *line;
259 >    char *line_ptr;
260 >    struct utmp *entry;
261 >    DIR *procdir;
262 >    struct dirent *procent;
263 >    char fname[_POSIX_PATH_MAX];
264 >    FILE *f;
265 >    
266 >    chdir("/proc");
267 >    if((procdir=opendir(".")) == NULL){
268 >      errf("Failed to open proc (%m)");
269 >      exit(1);
270 >    }
271  
272 <   FILE *f;
272 >    while((procent = readdir(procdir)) != NULL){
273 >      if(atoi(procent->d_name) == 0) continue;
274 >      strncpy(fname, procent->d_name, _POSIX_PATH_MAX-7);
275 >      strcat(fname, "/status");
276 >
277 >      if((f=fopen(fname, "r")) == NULL){
278 >         errf("Failed to open process stat (%m)");
279 >         exit(1);
280 >      }
281 >    
282 >      while((line=fpgetline(f)) != NULL){
283 >         if(strncasecmp(line,"State:",6)==0) break;
284 >      }
285 >
286 >      line_ptr=line;
287 >      for(;*line_ptr++ != '\t';);
288 >    
289  
290 <   if((f=popen("/bin/ps -Al" , "r")) == NULL)
291 <     {
292 <        errf("Failed to get process stats (%m)");
293 <        die();
294 <     }
284 <  
285 <   while((line=fpgetline(f)) != NULL)
286 <     {
287 <        line_p=strchr(line, ' ');
288 <        line_p++;
289 <        if (line_p==NULL) abort();
290 <        /* Ok, we should now be at the state :) .. */
291 <        if (*line_p=='S') sleeping++;
292 <        if (*line_p=='R') running++;
293 <        if (*line_p=='Z') zombie++;
294 <        if (*line_p=='T') stopped++;
295 <          
296 <     }
297 <  
298 <   if((pclose(f)) == -1)
299 <     {
300 <        errf("Failed to close process stats (%m)");
301 <        die();
302 <     }
290 >      if(*line_ptr=='R') running++;
291 >      if(*line_ptr=='S') sleeping++;
292 >      if(*line_ptr=='Z') zombie++;
293 >      if(*line_ptr=='T') stopped++;
294 >      if(*line_ptr=='D') stopped++;
295  
296 +    }
297 +    closedir(procdir);
298  
299 <   printf("packet.users.list");
299 >    printf("packet.users.list");
300 >    
301 >    while((entry=getutent()) != NULL) {
302 >        if(entry->ut_type==USER_PROCESS) {
303 >            printf(" %s",entry->ut_user);
304 >            nousers++;
305 >        }
306 >    }
307 >    
308 >    printf("\npacket.users.count %d\n", nousers);
309 >      
310 >    printf("packet.processes.sleeping %d\n",sleeping);
311 >    printf("packet.processes.cpu %d\n",running);
312 >    printf("packet.processes.zombie %d\n",zombie);
313 >    printf("packet.processes.stopped %d\n", stopped);
314 >    printf("packet.processes.total %d\n", (sleeping+running+zombie+stopped));
315 > }
316  
317 <   while((entry=getutent()) != NULL)
318 <     {
319 <        if(entry->ut_type==USER_PROCESS)
320 <          {
321 <             printf(" %s",entry->ut_user);
322 <             nousers++;
323 <          }
324 <        
325 <     }
326 <  
327 <   printf("\npacket.users.count %d\n", nousers);
328 <  
329 <   printf("packet.processes.total %d\n",sleeping);
330 <   printf("packet.processes.sleeping %d\n",running);
331 <   printf("packet.processes.zombie %d\n",zombie);
332 <   printf("packet.processes.stopped %d\n", stopped);
333 <   printf("packet.processes.total %d\n", (sleeping+running+zombie+stopped));
334 <  
317 > void uptimeStats() {
318 >    char *line;
319 >    char *line_p;
320 >    FILE *f;
321 >    
322 >    if ((f=fopen("/proc/uptime", "r")) == NULL) {
323 >        errf("Failed to get uptime stats (%m)");
324 >        die();
325 >    }
326 >    
327 >    if ((line=fpgetline(f)) == NULL) {
328 >        errf("Failed to read uptime stats (%m)");
329 >        die();
330 >    }
331 >    
332 >    if ((fclose(f)) != 0) {
333 >        errf("Failed to close file (%m).");
334 >        die();
335 >    }
336 >    
337 >    line_p=strchr(line, '.');
338 >    if (line_p==NULL) abort();
339 >    *line_p='\0';
340 >    
341 >    printf("packet.os.uptime %s\n", line);
342   }
343  
344 < void uptimeStats()
345 < {
346 <   char *line;
347 <   char *line_p;
348 <   FILE *f;
349 <  
350 <   if ((f=fopen("/proc/uptime", "r")) == NULL)
351 <     {
352 <        errf("Failed to get uptime stats (%m)");
353 <        die();
354 <     }
355 <  
356 <   if ((line=fpgetline(f)) == NULL)
357 <     {  
341 <        errf("Failed to read uptime stats (%m)");
342 <        die();
343 <     }
344 > void osStats() {
345 >    struct utsname os;
346 >    
347 >    if((uname(&os)) != 0) {
348 >        errf("Failed to get os stats (%m)");
349 >        die();
350 >    }
351 >    
352 >    printf("packet.os.name %s\n", os.sysname);
353 >    printf("packet.os.release %s\n" , os.release);
354 >    printf("packet.os.version %s\n", os.version);
355 >    printf("packet.os.sysname %s\n" , os.nodename);
356 >    printf("packet.os.platform %s\n", os.machine);
357 > }
358  
359 <   if ((fclose(f)) != 0)
346 <     {
347 <        errf("Failed to close file (%m).");
348 <        die();
349 <     }
350 <  
351 <  
352 <   line_p=strchr(line, '.');
353 <   if (line_p==NULL) abort();
354 <   *line_p='\0';
355 <  
356 <   printf("packet.os.uptime %s\n", line);
359 > void diskStats() {
360  
361 < }
361 >  struct mntent *mp;
362 >  struct statfs df;
363 >  FILE *f;
364 >  int counter=0;
365  
366 +  if ((f=fopen("/etc/mtab", "r" ))==NULL){
367 +      errf("Failed to open mounts (%m)");
368 +      die();
369 +  }
370  
371 < void osStats()
372 < {
371 >  while((mp=getmntent(f))){
372 >    if ((statfs(mp->mnt_dir, &df)) !=0){
373 >      errf("Failed to gets fs stats (%m)");
374 >      continue;
375 >    }
376  
377 <   struct utsname os;
378 <  
379 <   if((uname(&os)) != 0)
380 <     {
381 <        errf("Failed to get os stats (%m)");
382 <        die();
383 <     }
384 <  
385 <   printf("packet.os.name %s\n", os.sysname);
386 <   printf("packet.os.release %s\n" , os.release);
387 <   printf("packet.os.version %s\n", os.version);
388 <   printf("packet.os.sysname %s\n" , os.nodename);
376 <   printf("packet.os.platform %s\n", os.machine);
377 <  
378 < }
377 >    if((((strcmp(mp->mnt_type, MNTTYPE_NFS))==0) ||  (strcmp(mp->mnt_type,MNTTYPE_IGNORE)) ==0)) continue;
378 >    
379 >      printf("packet.disk.p%d.attributes.mount %s\n", counter, mp->mnt_dir);
380 >      printf("packet.disk.p%d.attributes.name %s\n", counter, mp->mnt_fsname);
381 >      printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_bsize/1024) * df.f_blocks));
382 >      printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_bsize/1024) * df.f_blocks) -((df.f_bsize/1024) * df.f_bfree)));
383 >      printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_bsize/1024) * df.f_bavail);
384 >      printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files);
385 >      printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree);
386 >    
387 >      counter++;
388 >  }
389  
390 < void diskStats()
391 < {
382 <   struct statfs df;
383 <   FILE *f;
384 <   char *line;
385 <   char *line_p;
386 <   long bstok;
387 <   int diskcnt=0;
388 <  
389 <   if ((f=fopen("/etc/mtab", "r")) == NULL)
390 <     {
391 <        errf("Failed to get uptime stats (%m)");
392 <        die();
393 <     }  
394 <  
395 <   while((line=fpgetline(f)) != NULL)
396 <     {
397 <        line_p=strchr(line, ' ');
398 <        if(line_p==NULL) abort();
399 <        *line_p='\0';
400 <        line_p++;
401 <        if(line_p==NULL) abort();
402 <        printf("packet.disk.p%d.attributes.name %s\n",diskcnt,line);
403 <        line=strchr(line_p, ' ');
404 <        if(line==NULL) abort();
405 <        *line='\0';
406 <        printf("packet.disk.p%d.attributes.mount %s\n",diskcnt,line_p);
407 <        if((statfs(line_p, &df)) != 0)
408 <          {
409 <             errf("Failed to get Filesystem stats (%m)");
410 <             die();
411 <          }
412 <        bstok=(df.f_bsize/1024);
413 <        printf("packet.disk.p%d.attributes.kbytes %ld\n",diskcnt,bstok*df.f_blocks);
414 <        printf("packet.disk.p%d.attributes.used %ld\n" ,diskcnt, ((bstok*df.f_blocks)-(bstok*df.f_bfree)));
415 <        printf("packet.disk.p%d.attributes.avail %ld\n", diskcnt, (df.f_bsize/1024)*df.f_bavail);
416 <        printf("packet.disk.p%d.attributes.totalinodes %ld\n", diskcnt, df.f_files);
417 <        printf("packet.disk.p%d.attributes.freeinodes %ld\n", diskcnt, df.f_ffree);
418 <        diskcnt++;
419 <     }
420 <  
421 <  
390 >  
391 >
392   }
393  
394 <
425 < int main()
426 < {
394 > int main() {
395     getLoadAv();
396     getMemInfo();
397     cpustats();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines