ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/plugins/solaris/solaris.c
Revision: 1.2
Committed: Fri Mar 8 14:57:28 2002 UTC (23 years, 9 months ago) by pajs
Content type: text/plain
Branch: MAIN
Changes since 1.1: +40 -5 lines
Log Message:
Now also does OS stats and load averages.

File Contents

# Content
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/statvfs.h>
4 #include <sys/mnttab.h>
5 #include <ukcprog.h>
6 #include <sys/utsname.h>
7 #include <sys/loadavg.h>
8
9 void die()
10 {
11 exit(1);
12 }
13
14
15 void diskStats()
16 {
17 struct mnttab mp;
18 struct statvfs df;
19 FILE *f;
20 int counter=0;
21
22 if ((f=fopen("/etc/mnttab", "r" ))==NULL)
23 {
24 errf("Failed to open mounts (%m)");
25 die();
26 }
27
28 while((getmntent(f, &mp)) == 0)
29 {
30 if ((statvfs(mp.mnt_mountp, &df)) !=0)
31 {
32 errf("Failed to gets fs stats (%m)");
33 die();
34 }
35
36 printf("packet.disk.p%d.attributes.mount %s\n", counter, mp.mnt_mountp);
37 printf("packet.disk.p%d.attributes.name %s\n", counter, mp.mnt_special);
38 printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_frsize/1024) * df.f_blocks));
39 printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree)));
40 printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_frsize/1024) * df.f_bavail);
41 printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files);
42 printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree);
43
44 counter++;
45 }
46 }
47
48 void osStats()
49 {
50 struct utsname os;
51
52 if((uname(&os)) == -1)
53 {
54 errf("Failed to get os stats (%m)");
55 die();
56 }
57
58 printf("packet.os.name %s\n", os.sysname);
59 printf("packet.os.release %s\n" , os.release);
60 printf("packet.os.version %s\n", os.version);
61 printf("packet.os.sysname %s\n" , os.nodename);
62 printf("packet.os.platform %s\n", os.machine);
63
64 }
65
66 void loadStats()
67 {
68 double loadav[3];
69
70 if((getloadavg(loadav,3)) == -1)
71 {
72 errf("Failed to get load averages (%m)");
73 die();
74
75 }
76
77 printf("packet.load.load1 %.2f\n",loadav[0]);
78 printf("packet.load.load5 %.2f\n",loadav[1]);
79 printf("packet.load.load15 %.2f\n",loadav[2]);
80 }
81
82 int main()
83 {
84
85 diskStats();
86 osStats();
87 loadStats();
88 return 0;
89 }
90