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.8 by pajs, Tue Apr 2 12:43:15 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  
12 < int die()
13 < {
13 <   exit (1);
12 > int die() {
13 >    exit (1);
14   }
15  
16 < void getLoadAv()
17 < {
18 <   FILE *f;
19 <   char *loadavg;
20 <   char *load_p;
21 <      
22 <   if ((f=fopen("/proc/loadavg", "r" ))==NULL)
23 <     {
24 <        errf("Failed to open load averages (%m)");
25 <        die();
26 <     }
27 <  
28 <  
29 <   if ((loadavg=fpgetline(f)) == NULL)
30 <     {
31 <        errf("Failed to read any data for load averages (%m)");
32 <        die();
33 <     }
34 <  
35 <  
36 <   if ((fclose(f)) != 0)
37 <     {
38 <        
39 <        errf("Failed to close file (%m).");
40 <        die();
41 <     }
42 <  
43 <
44 <  
16 > void getLoadAv() {
17  
18 <   load_p=strtok(loadavg, " ");
47 <   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);
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 < {
33 <   char *line;
34 <   char *mem;
35 <   char *swap;
36 <   char *ch;
37 <   long memstat[6];
38 <   long swapstat[3];
39 <   long tmp;
40 <   int counter=0;
41 <
42 <   FILE *f;
31 > void getMemInfo() {
32 >    char *line;
33 >    char *mem=NULL;
34 >    char *swap=NULL;
35 >    char *ch;
36 >    long memstat[6];
37 >    long swapstat[3];
38 >    long tmp;
39 >    int counter=0;
40 >    
41 >    FILE *f;
42 >    
43 >    if ((f=fopen("/proc/meminfo", "r" ))==NULL) {
44 >        errf("Failed to open memory stats (%m)");
45 >        die();
46 >    }
47 >    
48 >    while(((line=fpgetline(f)) != NULL) && (counter < 2)) {
49 >        if (((strncmp("Mem: ",line,5)) == 0)) {
50 >            mem=strdup(line);
51 >            counter++;
52 >        }
53 >        if (((strncmp(line,"Swap: ",6)) == 0)) {
54 >            swap=strdup(line);
55 >            counter++;
56 >        }
57 >    }
58 >    
59 >    if ((fclose(f)) != 0) {
60 >        errf("Failed to close file (%m).");
61 >        die();
62 >    }
63    
64 <   if ((f=fopen("/proc/meminfo", "r" ))==NULL)
65 <     {
78 <        errf("Failed to open memory stats (%m)");
64 >    if (mem==NULL || swap==NULL){
65 >        errf("Failed to obtain information required for memory and swap stats");
66          die();
67 <     }
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 <     }
67 >    }
68  
69 <   /* Get the info we want from the 2 read in lines */
70 <  
71 <   ch = strchr(mem, ' ');
72 <   if (ch == NULL) abort();
73 <   *ch = '\0';
74 <   ch++;
75 <   /* By now we should of skipped the mem: bit.. onto the numbers */
76 <  
77 <   for(counter=0;counter<6;counter++)
78 <     {
79 <        for (; (*ch == ' '); ch++);
80 <        if (ch == NULL) abort();
81 <        memstat[counter]=atol(ch);
82 <        ch++;
83 <        for(; (*ch != ' ') && (*ch != '\0'); ch++);
84 <        if (ch == NULL) abort();
85 <     }
86 <        
87 <      
88 <   /* Now swap.. */
89 <   ch = strchr(swap, ' ');
90 <   if (ch == NULL) abort();
91 <   *ch = '\0';
92 <   ch++;
93 <  
94 <   for(counter=0;counter<3;counter++)
95 <     {  
96 <        for (; (*ch == ' '); ch++);
97 <        if (ch == NULL) abort();
98 <        swapstat[counter]=atol(ch);
99 <        ch++;  
100 <        for(; (*ch != ' ') && (*ch != '\0'); ch++);
101 <        if (ch == NULL) abort();
102 <        
103 <     }
104 <  
105 <   printf("packet.memory.total %ld\n",((memstat[0]/1024)/1024));
106 <   /* Due to batty linux we do some maths to work out roughly what the free ram is */
107 <   tmp=((memstat[1] - memstat[4])/1024)/1024;
108 <   printf("packet.memory.used %ld\n",tmp);
109 <   tmp=((memstat[2] + memstat[4])/1024)/1024;
110 <   printf("packet.memory.free %ld\n",tmp);
111 <
112 <   printf("packet.swap.total %ld\n",((swapstat[0]/1024)/1024));
113 <   printf("packet.swap.used %ld\n",((swapstat[1]/1024)/1024));
114 <   printf("packet.swap.free %ld\n",((swapstat[2])/1024)/1024);
115 <  
152 <   free(mem);
153 <   free(swap);
154 <  
69 >    /* Get the info we want from the 2 read in lines */
70 >    
71 >    ch = strchr(mem, ' ');
72 >    if (ch == NULL) abort();
73 >    *ch = '\0';
74 >    ch++;
75 >    
76 >    /* By now we should of skipped the mem: bit.. onto the numbers */
77 >    
78 >    for(counter=0;counter<6;counter++) {
79 >        for (; (*ch == ' '); ch++);
80 >        if (ch == NULL) abort();
81 >        memstat[counter]=atol(ch);
82 >        ch++;
83 >        for(; (*ch != ' ') && (*ch != '\0'); ch++);
84 >        if (ch == NULL) abort();
85 >    }
86 >    
87 >    /* Now swap.. */
88 >    ch = strchr(swap, ' ');
89 >    if (ch == NULL) abort();
90 >    *ch = '\0';
91 >    ch++;
92 >    
93 >    for(counter=0;counter<3;counter++) {
94 >        for (; (*ch == ' '); ch++);
95 >        if (ch == NULL) abort();
96 >        swapstat[counter]=atol(ch);
97 >        ch++;
98 >        for(; (*ch != ' ') && (*ch != '\0'); ch++);
99 >        if (ch == NULL) abort();
100 >    }
101 >    
102 >    printf("packet.memory.total %ld\n",((memstat[0]/1024)/1024));
103 >    
104 >    /* Due to batty linux we do some maths to work out roughly what the free ram is */
105 >    tmp=((memstat[1] - memstat[4])/1024)/1024;
106 >    printf("packet.memory.used %ld\n",tmp);
107 >    tmp=((memstat[2] + memstat[4])/1024)/1024;
108 >    printf("packet.memory.free %ld\n",tmp);
109 >    
110 >    printf("packet.swap.total %ld\n",((swapstat[0]/1024)/1024));
111 >    printf("packet.swap.used %ld\n",((swapstat[1]/1024)/1024));
112 >    printf("packet.swap.free %ld\n",((swapstat[2])/1024)/1024);
113 >      
114 >    free(mem);
115 >    free(swap);
116   }
117  
118 < void cpustats()
119 < {
120 <   char *tmp;
121 <   char *line[2];
122 <   char *line_p[2];
123 <   long cpustats[4][2];
124 <   long user, kernel, idle;
125 <   long total;
126 <   int x,y;
127 <   float usage;
128 <   FILE *f;
129 <  
130 <   if ((f=fopen("/proc/stat", "r" ))==NULL)
131 <     {
132 <        errf("Failed to open cpu stats (%m)");
133 <        die();
134 <     }
135 <
136 <   if((tmp=fpgetline(f)) == NULL)
137 <     {
138 <        errf("Failed to read cpu stats (%m)");
139 <        die();
140 <     }
141 <
142 <   if((line[0]=strdup(tmp)) == NULL)
143 <     {
144 <        errf("strdup failed (%m)");
145 <        die();
146 <     }
147 <  
187 <   if ((fclose(f)) != 0)
188 <     {
189 <        errf("Failed to close file (%m).");
190 <        die();
191 <     }
118 > void cpustats() {
119 >    char *tmp;
120 >    char *line[2];
121 >    char *line_p[2];
122 >    long cpustats[4][2];
123 >    long user, kernel, idle;
124 >    long total;
125 >    int x,y;
126 >    float usage;
127 >    FILE *f;
128 >    
129 >    if ((f=fopen("/proc/stat", "r" ))==NULL) {
130 >        errf("Failed to open cpu stats (%m)");
131 >        die();
132 >    }
133 >    
134 >    if((tmp=fpgetline(f)) == NULL) {
135 >        errf("Failed to read cpu stats (%m)");
136 >        die();
137 >    }
138 >    
139 >    if((line[0]=strdup(tmp)) == NULL) {
140 >        errf("strdup failed (%m)");
141 >        die();
142 >    }
143 >    
144 >    if ((fclose(f)) != 0) {
145 >        errf("Failed to close file (%m).");
146 >        die();
147 >    }
148      
149 <   sleep(1);
150 <  
151 <   if ((f=fopen("/proc/stat", "r" ))==NULL)
152 <     {
153 <        errf("Failed to open cpu stats (%m)");
154 <        die();
155 <     }
156 <  
157 <   if((tmp=fpgetline(f)) == NULL)
158 <     {
159 <        errf("Failed to read cpu stats (%m)");
160 <        die();
161 <     }
162 <  
163 <   if((line[1]=strdup(tmp)) == NULL)
164 <     {
209 <        errf("strdup failed (%m)");
210 <        die();
211 <     }
149 >    sleep(1);
150 >    
151 >    if ((f=fopen("/proc/stat", "r" ))==NULL) {
152 >        errf("Failed to open cpu stats (%m)");
153 >        die();
154 >    }
155 >    
156 >    if((tmp=fpgetline(f)) == NULL) {
157 >        errf("Failed to read cpu stats (%m)");
158 >        die();
159 >    }
160 >    
161 >    if((line[1]=strdup(tmp)) == NULL) {
162 >        errf("strdup failed (%m)");
163 >        die();
164 >    }
165        
166 <     if ((fclose(f)) != 0)
167 <     {
168 <        errf("Failed to close file (%m).");
169 <        die();
170 <     }
171 <  
172 <      for(x=0;x<2;x++)
173 <     {
174 <        line_p[x] = strchr(line[x], ' ');
175 <        if (line_p[x] == NULL) abort();
176 <        *line_p[x] = '\0';
177 <        line_p[x]++;
178 <     }
179 <  
180 <   /* Now should be passed "cpu " */
181 <  
182 <  
183 <   for(x=0;x<2;x++)
184 <     {
185 <        for(y=0;y<4;y++)
186 <          {
187 <             for (; (*line_p[x] == ' '); line_p[x]++);
188 <             if (line_p[x] == NULL) abort();
189 <             cpustats[y][x]=atol(line_p[x]);
190 <             line_p[x]++;      
191 <             for(; (*line_p[x] != ' ') && (*line_p[x] != '\0'); line_p[x]++);
192 <             if (line_p[x] == NULL) abort();
193 <             for (; (*line_p[x] == ' '); line_p[x]++);
194 <          }
195 <        
196 <     }
197 <  
198 <   user=cpustats[0][1]-cpustats[0][0]+cpustats[1][1]-cpustats[1][0];
199 <   kernel=cpustats[2][1]-cpustats[2][0];
200 <   idle=cpustats[3][1]-cpustats[3][0];
201 <  
202 <   /* use total to get the total number and then work out the percentages */
203 <   total=user+kernel+idle;
204 <  
205 <   usage=((((float)user)/((float)total))*100.00);
206 <   printf("packet.cpu.user %3.2f\n", usage);
207 <   usage=((((float)kernel)/((float)total))*100.00);
208 <   printf("packet.cpu.kernel %3.2f\n", usage);
209 <   usage=((((float)idle)/((float)total))*100.00);
210 <   printf("packet.cpu.idle %3.2f\n", usage);
211 <  
259 <   /* Cos iscreams broke ;) */
260 <   printf("packet.cpu.iowait 0\n");
261 <  
262 <   free(line[0]);
263 <   free(line[1]);
166 >    if ((fclose(f)) != 0) {
167 >        errf("Failed to close file (%m).");
168 >        die();
169 >    }
170 >    
171 >    for(x=0;x<2;x++) {
172 >        line_p[x] = strchr(line[x], ' ');
173 >        if (line_p[x] == NULL) abort();
174 >        *line_p[x] = '\0';
175 >        line_p[x]++;
176 >    }
177 >    
178 >    /* Now should be passed "cpu " */
179 >    
180 >    for(x=0;x<2;x++) {
181 >        for(y=0;y<4;y++) {
182 >            for (; (*line_p[x] == ' '); line_p[x]++);
183 >            if (line_p[x] == NULL) abort();
184 >            cpustats[y][x]=atol(line_p[x]);
185 >            line_p[x]++;    
186 >            for(; (*line_p[x] != ' ') && (*line_p[x] != '\0'); line_p[x]++);
187 >            if (line_p[x] == NULL) abort();
188 >            for (; (*line_p[x] == ' '); line_p[x]++);
189 >        }
190 >    }
191 >    
192 >    user=cpustats[0][1]-cpustats[0][0]+cpustats[1][1]-cpustats[1][0];
193 >    kernel=cpustats[2][1]-cpustats[2][0];
194 >    idle=cpustats[3][1]-cpustats[3][0];
195 >    
196 >    /* use total to get the total number and then work out the percentages */
197 >    total=user+kernel+idle;
198 >    
199 >    usage=((((float)user)/((float)total))*100.00);
200 >    printf("packet.cpu.user %3.2f\n", usage);
201 >    usage=((((float)kernel)/((float)total))*100.00);
202 >    printf("packet.cpu.kernel %3.2f\n", usage);
203 >    usage=((((float)idle)/((float)total))*100.00);
204 >    printf("packet.cpu.idle %3.2f\n", usage);
205 >    
206 >    /* Cos i-scream's expects this to be sent :/ */
207 >    printf("packet.cpu.iowait 0\n");
208 >    printf("packet.cpu.swap 0\n");  
209 >
210 >    free(line[0]);
211 >    free(line[1]);
212   }
213  
214 < void processStats()
215 < {
216 <   int sleeping=0;
217 <   int zombie=0;
218 <   int stopped=0;
219 <   int running=0;
220 <   int nousers=0;
221 <   char *line;
222 <   char *line_p;
223 <   struct utmp *entry;
214 > void processStats() {
215 >    int sleeping=-1;
216 >    int zombie=0;
217 >    int stopped=0;
218 >    int running=0;
219 >    int nousers=0;
220 >    char *line;
221 >    char *line_p;
222 >    struct utmp *entry;
223 >    
224 >    FILE *f;
225 >    
226 >    if((f=popen("/bin/ps -Al" , "r")) == NULL) {
227 >        errf("Failed to get process stats (%m)");
228 >        die();
229 >    }
230 >    
231 >    while((line=fpgetline(f)) != NULL) {
232  
233 <   FILE *f;
234 <
235 <   if((f=popen("/bin/ps -Al" , "r")) == NULL)
236 <     {
237 <        errf("Failed to get process stats (%m)");
238 <        die();
239 <     }
240 <  
241 <   while((line=fpgetline(f)) != NULL)
242 <     {
243 <        line_p=strchr(line, ' ');
244 <        line_p++;
245 <        if (line_p==NULL) abort();
246 <        /* Ok, we should now be at the state :) .. */
247 <        if (*line_p=='S') sleeping++;
248 <        if (*line_p=='R') running++;
249 <        if (*line_p=='Z') zombie++;
250 <        if (*line_p=='T') stopped++;
251 <          
252 <     }
253 <  
254 <   if((pclose(f)) == -1)
255 <     {
256 <        errf("Failed to close process stats (%m)");
257 <        die();
258 <     }
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) {
246 >        errf("Failed to close process stats (%m)");
247 >        die();
248 >    }
249 >    
250 >    printf("packet.users.list");
251 >    
252 >    while((entry=getutent()) != NULL) {
253 >        if(entry->ut_type==USER_PROCESS) {
254 >            printf(" %s",entry->ut_user);
255 >            nousers++;
256 >        }
257 >    }
258 >    
259 >    printf("\npacket.users.count %d\n", nousers);
260 >      
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));
266 > }
267  
268 + void uptimeStats() {
269 +    char *line;
270 +    char *line_p;
271 +    FILE *f;
272 +    
273 +    if ((f=fopen("/proc/uptime", "r")) == NULL) {
274 +        errf("Failed to get uptime stats (%m)");
275 +        die();
276 +    }
277 +    
278 +    if ((line=fpgetline(f)) == NULL) {
279 +        errf("Failed to read uptime stats (%m)");
280 +        die();
281 +    }
282 +    
283 +    if ((fclose(f)) != 0) {
284 +        errf("Failed to close file (%m).");
285 +        die();
286 +    }
287 +    
288 +    line_p=strchr(line, '.');
289 +    if (line_p==NULL) abort();
290 +    *line_p='\0';
291 +    
292 +    printf("packet.os.uptime %s\n", line);
293 + }
294  
295 <   printf("packet.users.list");
296 <
297 <   while((entry=getutent()) != NULL)
298 <     {
299 <        if(entry->ut_type==USER_PROCESS)
300 <          {
301 <             printf(" %s",entry->ut_user);
302 <             nousers++;
303 <          }
304 <        
305 <     }
306 <  
307 <   printf("\npacket.users.count %d\n", nousers);
318 <  
319 <   printf("packet.processes.total %d\n",sleeping);
320 <   printf("packet.processes.sleeping %d\n",running);
321 <   printf("packet.processes.zombie %d\n",zombie);
322 <   printf("packet.processes.stopped %d\n", stopped);
323 <   printf("packet.processes.total %d\n", (sleeping+running+zombie+stopped));
324 <  
295 > void osStats() {
296 >    struct utsname os;
297 >    
298 >    if((uname(&os)) != 0) {
299 >        errf("Failed to get os stats (%m)");
300 >        die();
301 >    }
302 >    
303 >    printf("packet.os.name %s\n", os.sysname);
304 >    printf("packet.os.release %s\n" , os.release);
305 >    printf("packet.os.version %s\n", os.version);
306 >    printf("packet.os.sysname %s\n" , os.nodename);
307 >    printf("packet.os.platform %s\n", os.machine);
308   }
309  
310 < void uptimeStats()
328 < {
329 <   char *line;
330 <   char *line_p;
331 <   FILE *f;
332 <  
333 <   if ((f=fopen("/proc/uptime", "r")) == NULL)
334 <     {
335 <        errf("Failed to get uptime stats (%m)");
336 <        die();
337 <     }
338 <  
339 <   if ((line=fpgetline(f)) == NULL)
340 <     {  
341 <        errf("Failed to read uptime stats (%m)");
342 <        die();
343 <     }
310 > void diskStats() {
311  
312 <   if ((fclose(f)) != 0)
313 <     {
314 <        errf("Failed to close file (%m).");
315 <        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);
312 >  struct mntent *mp;
313 >  struct statfs df;
314 >  FILE *f;
315 >  int counter=0;
316  
317 < }
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 < void osStats()
329 < {
328 >    if((((strcmp(mp->mnt_type, MNTTYPE_NFS))==0) ||  (strcmp(mp->mnt_type,MNTTYPE_IGNORE)) ==0)) continue;
329 >    
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 <   struct utsname os;
365 <  
366 <   if((uname(&os)) != 0)
367 <     {
368 <        errf("Failed to get os stats (%m)");
369 <        die();
370 <     }
371 <  
372 <   printf("packet.os.name %s\n", os.sysname);
373 <   printf("packet.os.release %s\n" , os.release);
374 <   printf("packet.os.version %s\n", os.version);
375 <   printf("packet.os.sysname %s\n" , os.nodename);
376 <   printf("packet.os.platform %s\n", os.machine);
377 <  
378 < }
341 >  
342  
380 void diskStats()
381 {
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  
343   }
344  
345 <
425 < int main()
426 < {
345 > int main() {
346     getLoadAv();
347     getMemInfo();
348     cpustats();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines