| 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 |
| 16 |
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
* along with this program; if not, write to the Free Software |
| 18 |
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
+ |
* |
| 20 |
+ |
* $Id$ |
| 21 |
|
*/ |
| 22 |
|
|
| 23 |
|
#ifdef HAVE_CONFIG_H |
| 297 |
|
printw("%8s", size_conv(stats.swap_stats->free)); |
| 298 |
|
} |
| 299 |
|
|
| 300 |
< |
if (stats.mem_stats != NULL && stats.swap_stats != NULL) { |
| 301 |
< |
/* VM */ |
| 300 |
> |
/* VM */ |
| 301 |
> |
if (stats.mem_stats != NULL && stats.mem_stats->total != 0) { |
| 302 |
|
move(6, 54); |
| 303 |
|
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total)); |
| 304 |
+ |
} |
| 305 |
+ |
if (stats.swap_stats != NULL && stats.swap_stats->total != 0) { |
| 306 |
|
move(7, 54); |
| 307 |
|
printw("%5.2f%%", (100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total)); |
| 308 |
+ |
} |
| 309 |
+ |
if (stats.mem_stats != NULL && stats.swap_stats != NULL && |
| 310 |
+ |
stats.mem_stats->total != 0 && stats.swap_stats->total != 0) { |
| 311 |
|
move(8, 54); |
| 312 |
|
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used+stats.swap_stats->used)/(stats.mem_stats->total+stats.swap_stats->total))); |
| 313 |
|
} |
| 427 |
|
int main(int argc, char **argv){ |
| 428 |
|
|
| 429 |
|
extern char *optarg; |
| 423 |
– |
extern int optind; |
| 430 |
|
int c; |
| 431 |
|
|
| 432 |
+ |
time_t last_update = 0; |
| 433 |
+ |
|
| 434 |
|
WINDOW *window; |
| 435 |
|
|
| 428 |
– |
int stdin_fileno; |
| 429 |
– |
fd_set infds; |
| 430 |
– |
struct timeval timeout; |
| 431 |
– |
|
| 436 |
|
extern int errno; |
| 433 |
– |
char ch; |
| 437 |
|
|
| 438 |
|
int delay=2; |
| 439 |
< |
#ifdef ALLBSD |
| 437 |
< |
gid_t gid; |
| 438 |
< |
#endif |
| 439 |
> |
|
| 440 |
|
statgrab_init(); |
| 441 |
< |
#ifdef ALLBSD |
| 442 |
< |
if((setegid(getgid())) != 0){ |
| 442 |
< |
fprintf(stderr, "Failed to lose setgid'ness\n"); |
| 441 |
> |
if(statgrab_drop_privileges() != 0){ |
| 442 |
> |
fprintf(stderr, "Failed to drop setuid/setgid privileges\n"); |
| 443 |
|
return 1; |
| 444 |
|
} |
| 445 |
– |
#endif |
| 445 |
|
|
| 446 |
< |
while ((c = getopt(argc, argv, "vhd:")) != EOF){ |
| 446 |
> |
while ((c = getopt(argc, argv, "vhd:")) != -1){ |
| 447 |
|
switch (c){ |
| 448 |
|
case 'd': |
| 449 |
|
delay = atoi(optarg); |
| 450 |
< |
if (delay == 0){ |
| 450 |
> |
if (delay < 1){ |
| 451 |
|
fprintf(stderr, "Time must be 1 second or greater\n"); |
| 452 |
|
exit(1); |
| 453 |
|
} |
| 455 |
– |
delay--; |
| 454 |
|
break; |
| 455 |
|
case 'v': |
| 456 |
|
version_num(argv[0]); |
| 460 |
|
usage(argv[0]); |
| 461 |
|
return 1; |
| 462 |
|
break; |
| 465 |
– |
|
| 463 |
|
} |
| 464 |
|
} |
| 465 |
|
|
| 468 |
|
nonl(); |
| 469 |
|
cbreak(); |
| 470 |
|
noecho(); |
| 471 |
+ |
timeout(delay * 1000); |
| 472 |
|
window=newwin(0, 0, 0, 0); |
| 473 |
|
clear(); |
| 474 |
|
|
| 479 |
|
} |
| 480 |
|
|
| 481 |
|
display_headings(); |
| 484 |
– |
stdin_fileno=fileno(stdin); |
| 482 |
|
|
| 483 |
|
for(;;){ |
| 484 |
+ |
time_t now; |
| 485 |
+ |
int ch = getch(); |
| 486 |
|
|
| 487 |
< |
FD_ZERO(&infds); |
| 488 |
< |
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 |
< |
} |
| 487 |
> |
if (ch == 'q'){ |
| 488 |
> |
break; |
| 489 |
|
} |
| 490 |
|
|
| 491 |
< |
if(FD_ISSET(stdin_fileno, &infds)){ |
| 492 |
< |
ch=getch(); |
| 493 |
< |
if (ch == 'q'){ |
| 494 |
< |
endwin(); |
| 495 |
< |
return 0; |
| 496 |
< |
} |
| 491 |
> |
/* To keep the numbers slightly accurate we do not want them |
| 492 |
> |
* updating more frequently than once a second. |
| 493 |
> |
*/ |
| 494 |
> |
now = time(NULL); |
| 495 |
> |
if ((now - last_update) >= 1) { |
| 496 |
> |
get_stats(); |
| 497 |
|
} |
| 498 |
+ |
last_update = now; |
| 499 |
|
|
| 508 |
– |
get_stats(); |
| 509 |
– |
|
| 500 |
|
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); |
| 501 |
|
} |
| 502 |
|
|
| 503 |
|
endwin(); |