| 1 |
|
/* |
| 2 |
|
* i-scream central monitoring system |
| 3 |
|
* http://www.i-scream.org |
| 4 |
< |
* Copyright (C) 2000-2002 i-scream |
| 4 |
> |
* Copyright (C) 2000-2004 i-scream |
| 5 |
|
* |
| 6 |
|
* This program is free software; you can redistribute it and/or |
| 7 |
|
* modify it under the terms of the GNU General Public License |
| 295 |
|
printw("%8s", size_conv(stats.swap_stats->free)); |
| 296 |
|
} |
| 297 |
|
|
| 298 |
< |
if (stats.mem_stats != NULL && stats.swap_stats != NULL) { |
| 299 |
< |
/* VM */ |
| 298 |
> |
/* VM */ |
| 299 |
> |
if (stats.mem_stats != NULL && stats.mem_stats->total != 0) { |
| 300 |
|
move(6, 54); |
| 301 |
|
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total)); |
| 302 |
+ |
} |
| 303 |
+ |
if (stats.swap_stats != NULL && stats.swap_stats->total != 0) { |
| 304 |
|
move(7, 54); |
| 305 |
|
printw("%5.2f%%", (100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total)); |
| 306 |
+ |
} |
| 307 |
+ |
if (stats.mem_stats != NULL && stats.swap_stats != NULL && |
| 308 |
+ |
stats.mem_stats->total != 0 && stats.swap_stats->total != 0) { |
| 309 |
|
move(8, 54); |
| 310 |
|
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used+stats.swap_stats->used)/(stats.mem_stats->total+stats.swap_stats->total))); |
| 311 |
|
} |
| 428 |
|
extern int optind; |
| 429 |
|
int c; |
| 430 |
|
|
| 431 |
+ |
time_t last_update = 0; |
| 432 |
+ |
|
| 433 |
|
WINDOW *window; |
| 434 |
|
|
| 428 |
– |
int stdin_fileno; |
| 429 |
– |
fd_set infds; |
| 430 |
– |
struct timeval timeout; |
| 431 |
– |
|
| 435 |
|
extern int errno; |
| 433 |
– |
char ch; |
| 436 |
|
|
| 437 |
|
int delay=2; |
| 438 |
< |
#ifdef ALLBSD |
| 437 |
< |
gid_t gid; |
| 438 |
< |
#endif |
| 438 |
> |
|
| 439 |
|
statgrab_init(); |
| 440 |
< |
#ifdef ALLBSD |
| 441 |
< |
if((setegid(getgid())) != 0){ |
| 442 |
< |
fprintf(stderr, "Failed to lose setgid'ness\n"); |
| 440 |
> |
if(statgrab_drop_privileges() != 0){ |
| 441 |
> |
fprintf(stderr, "Failed to drop setuid/setgid privileges\n"); |
| 442 |
|
return 1; |
| 443 |
|
} |
| 445 |
– |
#endif |
| 444 |
|
|
| 445 |
< |
while ((c = getopt(argc, argv, "vhd:")) != EOF){ |
| 445 |
> |
while ((c = getopt(argc, argv, "vhd:")) != -1){ |
| 446 |
|
switch (c){ |
| 447 |
|
case 'd': |
| 448 |
|
delay = atoi(optarg); |
| 450 |
|
fprintf(stderr, "Time must be 1 second or greater\n"); |
| 451 |
|
exit(1); |
| 452 |
|
} |
| 455 |
– |
delay--; |
| 453 |
|
break; |
| 454 |
|
case 'v': |
| 455 |
|
version_num(argv[0]); |
| 459 |
|
usage(argv[0]); |
| 460 |
|
return 1; |
| 461 |
|
break; |
| 465 |
– |
|
| 462 |
|
} |
| 463 |
|
} |
| 464 |
|
|
| 467 |
|
nonl(); |
| 468 |
|
cbreak(); |
| 469 |
|
noecho(); |
| 470 |
+ |
timeout(delay * 1000); |
| 471 |
|
window=newwin(0, 0, 0, 0); |
| 472 |
|
clear(); |
| 473 |
|
|
| 478 |
|
} |
| 479 |
|
|
| 480 |
|
display_headings(); |
| 484 |
– |
stdin_fileno=fileno(stdin); |
| 481 |
|
|
| 482 |
|
for(;;){ |
| 483 |
+ |
time_t now; |
| 484 |
+ |
int ch = getch(); |
| 485 |
|
|
| 486 |
< |
FD_ZERO(&infds); |
| 487 |
< |
FD_SET(stdin_fileno, &infds); |
| 490 |
< |
timeout.tv_sec = delay; |
| 491 |
< |
timeout.tv_usec = 0; |
| 492 |
< |
|
| 493 |
< |
if((select((stdin_fileno+1), &infds, NULL, NULL, &timeout)) == -1){ |
| 494 |
< |
if(errno!=EINTR){ |
| 495 |
< |
perror("select failed"); |
| 496 |
< |
exit(1); |
| 497 |
< |
} |
| 486 |
> |
if (ch == 'q'){ |
| 487 |
> |
break; |
| 488 |
|
} |
| 489 |
|
|
| 490 |
< |
if(FD_ISSET(stdin_fileno, &infds)){ |
| 491 |
< |
ch=getch(); |
| 492 |
< |
if (ch == 'q'){ |
| 493 |
< |
endwin(); |
| 494 |
< |
return 0; |
| 495 |
< |
} |
| 490 |
> |
/* To keep the numbers slightly accurate we do not want them |
| 491 |
> |
* updating more frequently than once a second. |
| 492 |
> |
*/ |
| 493 |
> |
now = time(NULL); |
| 494 |
> |
if ((now - last_update) >= 1) { |
| 495 |
> |
get_stats(); |
| 496 |
|
} |
| 497 |
+ |
last_update = now; |
| 498 |
|
|
| 508 |
– |
get_stats(); |
| 509 |
– |
|
| 499 |
|
display_data(); |
| 511 |
– |
|
| 512 |
– |
/* To keep the numbers slightly accurate we do not want them updating more |
| 513 |
– |
* frequently than once a second. |
| 514 |
– |
*/ |
| 515 |
– |
sleep(1); |
| 500 |
|
} |
| 501 |
|
|
| 502 |
|
endwin(); |