| 1 |
pajs |
1.1 |
#include <stdio.h> |
| 2 |
|
|
#include "ukcprog.h" |
| 3 |
|
|
#include <sys/param.h> |
| 4 |
|
|
#include <sys/ucred.h> |
| 5 |
|
|
#include <sys/mount.h> |
| 6 |
|
|
#include <string.h> |
| 7 |
|
|
#include <stdlib.h> |
| 8 |
|
|
|
| 9 |
|
|
void die(){ |
| 10 |
|
|
exit(1); |
| 11 |
|
|
} |
| 12 |
|
|
|
| 13 |
|
|
void diskStats(){ |
| 14 |
|
|
struct statfs *mp; |
| 15 |
|
|
int nummnt; |
| 16 |
|
|
int counter=0; |
| 17 |
|
|
char *mntpnt; |
| 18 |
|
|
char *devicename; |
| 19 |
|
|
|
| 20 |
|
|
nummnt=getmntinfo(&mp , MNT_LOCAL); |
| 21 |
|
|
if (nummnt<=0){ |
| 22 |
|
|
errf("Failed to get disk stats (%m)"); |
| 23 |
|
|
die(); |
| 24 |
|
|
} |
| 25 |
|
|
|
| 26 |
|
|
mntpnt=malloc(MNAMELEN); |
| 27 |
|
|
devicename=malloc(MNAMELEN); |
| 28 |
|
|
|
| 29 |
|
|
for(;counter<nummnt;counter++){ |
| 30 |
|
|
strncpy(mntpnt, mp->f_mntonname ,MNAMELEN); |
| 31 |
|
|
strncpy(devicename, mp->f_mntfromname ,MNAMELEN); |
| 32 |
|
|
printf("packet.disk.p%d.attributes.mount %s\n", counter, mntpnt); |
| 33 |
|
|
printf("packet.disk.p%d.attributes.name %s\n", counter, devicename); |
| 34 |
|
|
printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((mp->f_bsize/1024) * mp->f_blocks)); |
| 35 |
|
|
printf("packet.disk.p%d.attributes.used %lu\n",counter, (((mp->f_bsize/1024) * mp->f_blocks) -((mp->f_bsize/1024) * mp->f_bfree))); |
| 36 |
|
|
printf("packet.disk.p%d.attributes.avail %lu\n",counter, (mp->f_bsize/1024) * mp->f_bavail); |
| 37 |
|
|
printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, mp->f_files); |
| 38 |
|
|
printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, mp->f_ffree); |
| 39 |
|
|
|
| 40 |
|
|
mp++; |
| 41 |
|
|
} |
| 42 |
|
|
|
| 43 |
|
|
|
| 44 |
|
|
} |
| 45 |
|
|
|
| 46 |
|
|
int main(){ |
| 47 |
|
|
diskStats(); |
| 48 |
|
|
exit(0); |
| 49 |
|
|
|
| 50 |
|
|
} |