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.5 by pajs, Thu Mar 28 17:46:52 2002 UTC vs.
Revision 1.7 by pajs, Tue Apr 2 11:25:37 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 113 | Line 115 | void systemStats(){
115    long total, user, idle, kernel, nice;
116    long totalmem, freemem, swaptotal, swapused;
117  
118 +  static char *uptimename = "kern.boottime";
119    static char *cpname = "kern.cp_time";
120    static char *tmemname = "hw.physmem";
121    static char *fmemname = "vm.stats.vm.v_free_count";
# Line 122 | Line 125 | void systemStats(){
125    kvm_t *kvmd = NULL;
126    struct kvm_swap swapinfo;
127    char errbuf[_POSIX2_LINE_MAX];
128 +  time_t current;
129 +  struct timeval uptime;
130 +
131 +  time(&current);
132    
133 +  if (sysctlbyname(uptimename, NULL, &size, NULL, NULL) < 0){
134 +    errf("sysctlbyname (%m)");
135 +    die();
136 +  }
137 +
138 +
139 +  if (sysctlbyname(uptimename, &uptime, &size, NULL, NULL) < 0){
140 +    errf("Failed to get cpu stats (%m)");
141 +    die();
142 +  }
143 +  
144 +  printf("packet.os.uptime %ld\n",(current-(uptime.tv_sec)));
145 +
146 +
147    if (sysctlbyname(cpname, NULL, &size, NULL, NULL) < 0){
148      errf("sysctlbyname (%m)");
149      die();
# Line 241 | Line 262 | void systemStats(){
262    
263   }
264  
265 + void processStats(){
266 +  int sleeping=-1;
267 +  int zombie=0;
268 +  int stopped=0;
269 +  int running=0;
270 +  char *line;
271 +  char *line_p;
272 +  
273 +  FILE *f;
274 +
275 +  if((f=popen("/bin/ps -ax" , "r")) == NULL) {
276 +    errf("Failed to get process stats (%m)");
277 +    die();
278 +  }
279 +
280 +  while((line=fpgetline(f)) != NULL) {
281 +    line_p=line;
282 +    for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
283 +    line_p=strchr(line_p, ' ');
284 +    for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
285 +    line_p=strchr(line_p, ' ');
286 +    for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
287 +    if (line_p==NULL) abort();
288 +
289 +    if (*line_p=='S') sleeping++;
290 +    if (*line_p=='I') sleeping++;
291 +    if (*line_p=='R') running++;
292 +    if (*line_p=='D') running++;
293 +    if (*line_p=='Z') zombie++;
294 +    if (*line_p=='T') stopped++;
295 +    if (*line_p=='J') running++;
296 +
297 +  }
298 +
299 +  if((pclose(f)) != 0) {
300 +    errf("Failed to close process stats (%m)");
301 +    die();
302 +  }
303 +  
304 +  printf("packet.processes.sleeping %d\n",sleeping);
305 +  printf("packet.processes.cpu %d\n",running);
306 +  printf("packet.processes.zombie %d\n",zombie);
307 +  printf("packet.processes.stopped %d\n", stopped);
308 +  printf("packet.processes.total %d\n", (sleeping+running+zombie+stopped));
309 +
310 +
311 + }
312 +
313 +
314   int main(){
315    uid=getuid();
316    euid=geteuid();
# Line 263 | Line 333 | int main(){
333    loadStats();
334    userStats();
335    systemStats();
336 +  processStats();
337    exit(0);
338   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines