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.6 by pajs, Thu Mar 28 18:16:21 2002 UTC vs.
Revision 1.8 by pajs, Fri Apr 5 12:02:09 2002 UTC

# Line 14 | Line 14
14   #include <sys/sysctl.h>
15   #include <fcntl.h>
16   #include <limits.h>
17 + #include <time.h>
18 + #include <sys/time.h>
19  
20   uid_t uid;
21   uid_t euid;
# Line 112 | Line 114 | void systemStats(){
114    long cp_time[CPUSTATES];
115    long total, user, idle, kernel, nice;
116    long totalmem, freemem, swaptotal, swapused;
117 +  float stat;
118  
119 +  static char *uptimename = "kern.boottime";
120    static char *cpname = "kern.cp_time";
121    static char *tmemname = "hw.physmem";
122    static char *fmemname = "vm.stats.vm.v_free_count";
# Line 122 | Line 126 | void systemStats(){
126    kvm_t *kvmd = NULL;
127    struct kvm_swap swapinfo;
128    char errbuf[_POSIX2_LINE_MAX];
129 +  time_t current;
130 +  struct timeval uptime;
131 +
132 +  time(&current);
133    
134 +  if (sysctlbyname(uptimename, NULL, &size, NULL, NULL) < 0){
135 +    errf("sysctlbyname (%m)");
136 +    die();
137 +  }
138 +
139 +
140 +  if (sysctlbyname(uptimename, &uptime, &size, NULL, NULL) < 0){
141 +    errf("Failed to get cpu stats (%m)");
142 +    die();
143 +  }
144 +  
145 +  printf("packet.os.uptime %ld\n",(current-(uptime.tv_sec)));
146 +
147 +
148    if (sysctlbyname(cpname, NULL, &size, NULL, NULL) < 0){
149      errf("sysctlbyname (%m)");
150      die();
# Line 150 | Line 172 | void systemStats(){
172      die();
173    }
174    
175 <  user-=cp_time[CP_USER];
176 <  nice-=cp_time[CP_NICE];
177 <  kernel-=cp_time[CP_SYS];
178 <  idle-=cp_time[CP_IDLE];
175 >  user=cp_time[CP_USER]-user;
176 >  nice=cp_time[CP_NICE]-nice;
177 >  kernel=cp_time[CP_SYS]-kernel;
178 >  idle=cp_time[CP_IDLE]-idle;
179    
180    total=user+nice+kernel+idle;
181 <
182 <  printf("packet.cpu.user %ld\n",((user+nice)*100)/total);
183 <  printf("packet.cpu.kernel %ld\n",(kernel*100)/total);
184 <  printf("packet.cpu.idle %ld\n",(idle*100)/total);
181 >  stat=((float)(user+nice)/(float)total)*100.0;
182 >  printf("packet.cpu.user %.2f\n",stat);
183 >  stat=((float)(kernel)/(float)total)*100.0;
184 >  printf("packet.cpu.kernel %.2f\n",stat);
185 >  stat=((float)(idle)/(float)total)*100.0;
186 >  printf("packet.cpu.idle %.2f\n",stat);
187  
188     /* Cos i-scream's expects this to be sent :/ */
189    printf("packet.cpu.iowait 0\n");
# Line 216 | Line 240 | void systemStats(){
240      die();
241    }
242    
243 <  /* Lose are setgid'ness */
243 >  /* Lose our setgid'ness */
244  
245    if ((setegid(gid)) != 0){
246      errf("Failed to release permissions, refusing to keep setgid. (%m)");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines