1 |
pajs |
1.1 |
#include <stdio.h> |
2 |
|
|
#include <sys/types.h> |
3 |
|
|
#include <sys/statvfs.h> |
4 |
|
|
#include <sys/mnttab.h> |
5 |
|
|
#include <ukcprog.h> |
6 |
|
|
|
7 |
|
|
void die() |
8 |
|
|
{ |
9 |
|
|
exit(1); |
10 |
|
|
} |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
void diskStats() |
14 |
|
|
{ |
15 |
|
|
struct mnttab mp; |
16 |
|
|
struct statvfs df; |
17 |
|
|
FILE *f; |
18 |
|
|
int counter=0; |
19 |
|
|
|
20 |
|
|
if ((f=fopen("/etc/mnttab", "r" ))==NULL) |
21 |
|
|
{ |
22 |
|
|
errf("Failed to open mounts (%m)"); |
23 |
|
|
die(); |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
while((getmntent(f, &mp)) == 0) |
27 |
|
|
{ |
28 |
|
|
if ((statvfs(mp.mnt_mountp, &df)) !=0) |
29 |
|
|
{ |
30 |
|
|
errf("Failed to gets fs stats (%m)"); |
31 |
|
|
die(); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
printf("packet.disk.p%d.attributes.mount %s\n", counter, mp.mnt_mountp); |
35 |
|
|
printf("packet.disk.p%d.attributes.name %s\n", counter, mp.mnt_special); |
36 |
|
|
printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_frsize/1024) * df.f_blocks)); |
37 |
|
|
printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree))); |
38 |
|
|
printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_frsize/1024) * df.f_bavail); |
39 |
|
|
printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files); |
40 |
|
|
printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree); |
41 |
|
|
|
42 |
|
|
counter++; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
int main() |
51 |
|
|
{ |
52 |
|
|
diskStats(); |
53 |
|
|
return 0; |
54 |
|
|
} |
55 |
|
|
|