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 |
pajs |
1.2 |
#include <sys/utsname.h> |
9 |
|
|
#include <sys/types.h> |
10 |
|
|
#include <utmp.h> |
11 |
pajs |
1.1 |
|
12 |
|
|
void die(){ |
13 |
|
|
exit(1); |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
void diskStats(){ |
17 |
|
|
struct statfs *mp; |
18 |
|
|
int nummnt; |
19 |
|
|
int counter=0; |
20 |
|
|
char *mntpnt; |
21 |
|
|
char *devicename; |
22 |
|
|
|
23 |
|
|
nummnt=getmntinfo(&mp , MNT_LOCAL); |
24 |
|
|
if (nummnt<=0){ |
25 |
|
|
errf("Failed to get disk stats (%m)"); |
26 |
|
|
die(); |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
mntpnt=malloc(MNAMELEN); |
30 |
|
|
devicename=malloc(MNAMELEN); |
31 |
|
|
|
32 |
|
|
for(;counter<nummnt;counter++){ |
33 |
|
|
strncpy(mntpnt, mp->f_mntonname ,MNAMELEN); |
34 |
|
|
strncpy(devicename, mp->f_mntfromname ,MNAMELEN); |
35 |
|
|
printf("packet.disk.p%d.attributes.mount %s\n", counter, mntpnt); |
36 |
|
|
printf("packet.disk.p%d.attributes.name %s\n", counter, devicename); |
37 |
|
|
printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((mp->f_bsize/1024) * mp->f_blocks)); |
38 |
|
|
printf("packet.disk.p%d.attributes.used %lu\n",counter, (((mp->f_bsize/1024) * mp->f_blocks) -((mp->f_bsize/1024) * mp->f_bfree))); |
39 |
|
|
printf("packet.disk.p%d.attributes.avail %lu\n",counter, (mp->f_bsize/1024) * mp->f_bavail); |
40 |
|
|
printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, mp->f_files); |
41 |
|
|
printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, mp->f_ffree); |
42 |
|
|
|
43 |
|
|
mp++; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
} |
48 |
|
|
|
49 |
pajs |
1.2 |
void osStats(){ |
50 |
|
|
struct utsname os; |
51 |
|
|
|
52 |
|
|
if((uname(&os)) != 0){ |
53 |
|
|
errf("Failed to get os stats (%m)"); |
54 |
|
|
die(); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
printf("packet.os.name %s\n", os.sysname); |
58 |
|
|
printf("packet.os.release %s\n" , os.release); |
59 |
|
|
printf("packet.os.version %s\n", os.version); |
60 |
|
|
printf("packet.os.sysname %s\n" , os.nodename); |
61 |
|
|
printf("packet.os.platform %s\n", os.machine); |
62 |
|
|
|
63 |
|
|
} |
64 |
|
|
void loadStats(){ |
65 |
|
|
double loadav[3]; |
66 |
|
|
|
67 |
|
|
if((getloadavg(loadav,3)) == -1){ |
68 |
|
|
errf("Failed to get load averages (%m)"); |
69 |
|
|
die(); |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
printf("packet.load.load1 %.2f\n",loadav[0]); |
73 |
|
|
printf("packet.load.load5 %.2f\n",loadav[1]); |
74 |
|
|
printf("packet.load.load15 %.2f\n",loadav[2]); |
75 |
|
|
} |
76 |
|
|
|
77 |
pajs |
1.1 |
int main(){ |
78 |
|
|
diskStats(); |
79 |
pajs |
1.2 |
osStats(); |
80 |
|
|
loadStats(); |
81 |
pajs |
1.1 |
exit(0); |
82 |
|
|
|
83 |
|
|
} |