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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines