ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/plugins/freebsd/freebsd.c
(Generate patch)

Comparing projects/cms/source/host/ihost-perl/plugins/freebsd/freebsd.c (file contents):
Revision 1.1 by pajs, Tue Mar 19 13:17:58 2002 UTC vs.
Revision 1.3 by pajs, Thu Mar 21 16:40:11 2002 UTC

# Line 5 | Line 5
5   #include <sys/mount.h>
6   #include <string.h>
7   #include <stdlib.h>
8 + #include <sys/utsname.h>
9 + #include <sys/types.h>
10 + #include <utmp.h>
11  
12   void die(){
13    exit(1);
# Line 43 | Line 46 | void diskStats(){
46  
47   }
48  
49 + 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 + void userStats(){
78 +  struct utmp users;
79 +  FILE *f;
80 +  int numusers=0;
81 +
82 +  if ((f=fopen(_PATH_UTMP, "r")) == NULL){
83 +    errf("Failed to get user stats(%m)");
84 +    die();
85 +  }
86 +
87 +  printf("packet.users.list");
88 +
89 +  while((fread(&users, sizeof(users),1,f)) != 0){
90 +    if (users.ut_name[0] == '\0') continue;
91 +    printf(" %s",users.ut_name);
92 +    numusers++;
93 +  }
94 +
95 +  printf("\npacket.users.count %d\n",numusers);
96 +
97 +  
98 +
99 + }
100 +
101   int main(){
102    diskStats();
103 +  osStats();
104 +  loadStats();
105 +  userStats();
106    exit(0);
49  
107   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines