| 39 |
|
#include <math.h> |
| 40 |
|
|
| 41 |
|
#ifdef HAVE_NCURSES_H |
| 42 |
< |
#include <ncurses.h> |
| 43 |
< |
#else |
| 44 |
< |
#include <curses.h> |
| 42 |
> |
#define COLOR_SUPPORT |
| 43 |
|
#endif |
| 44 |
+ |
#include CURSES_HEADER_FILE |
| 45 |
|
|
| 46 |
|
#define THRESHOLD_LOAD 1.0 |
| 47 |
|
|
| 59 |
|
#define THRESHOLD_WARN_DISK 75.0 |
| 60 |
|
#define THRESHOLD_ALERT_DISK 90.0 |
| 61 |
|
|
| 62 |
+ |
int sig_winch_flag = 0; |
| 63 |
+ |
|
| 64 |
|
typedef struct{ |
| 65 |
|
sg_cpu_percents *cpu_percents; |
| 66 |
|
sg_mem_stats *mem_stats; |
| 311 |
|
move(4,33); |
| 312 |
|
if (colors && stats.cpu_percents->user + stats.cpu_percents->nice > THRESHOLD_ALERT_CPU) { |
| 313 |
|
attron(A_STANDOUT); |
| 314 |
+ |
attron(A_BOLD); |
| 315 |
|
} |
| 316 |
|
else if (colors && stats.cpu_percents->user + stats.cpu_percents->nice > THRESHOLD_WARN_CPU) { |
| 317 |
|
attron(A_BOLD); |
| 331 |
|
move(2,74); |
| 332 |
|
if (colors && stats.process_count->zombie > THRESHOLD_WARN_ZMB) { |
| 333 |
|
attron(A_STANDOUT); |
| 334 |
+ |
attron(A_BOLD); |
| 335 |
|
} |
| 336 |
|
printw("%5d", stats.process_count->zombie); |
| 337 |
|
if(colors) { |
| 338 |
|
attroff(A_STANDOUT); |
| 339 |
< |
attron(COLOR_PAIR(6)); |
| 339 |
> |
attroff(A_BOLD); |
| 340 |
|
} |
| 341 |
|
move(3, 54); |
| 342 |
|
printw("%5d", stats.process_count->sleeping); |
| 379 |
|
float f = 100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total; |
| 380 |
|
if (colors && f > THRESHOLD_ALERT_MEM) { |
| 381 |
|
attron(A_STANDOUT); |
| 382 |
+ |
attron(A_BOLD); |
| 383 |
|
} |
| 384 |
|
else if (colors && f > THRESHOLD_WARN_MEM) { |
| 385 |
|
attron(A_BOLD); |
| 396 |
|
float f = 100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total; |
| 397 |
|
if (colors && f > THRESHOLD_ALERT_SWAP) { |
| 398 |
|
attron(A_STANDOUT); |
| 399 |
+ |
attron(A_BOLD); |
| 400 |
|
} |
| 401 |
|
else if (colors && f > THRESHOLD_WARN_SWAP) { |
| 402 |
|
attron(A_BOLD); |
| 515 |
|
move(line, 73); |
| 516 |
|
if(colors && 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail)) > THRESHOLD_ALERT_DISK) { |
| 517 |
|
attron(A_STANDOUT); |
| 518 |
+ |
attron(A_BOLD); |
| 519 |
|
} else if (colors && 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail)) > THRESHOLD_WARN_DISK) { |
| 520 |
|
attron(A_BOLD); |
| 521 |
|
} |
| 534 |
|
} |
| 535 |
|
|
| 536 |
|
void sig_winch_handler(int dummy){ |
| 537 |
< |
clear(); |
| 532 |
< |
display_headings(); |
| 533 |
< |
display_data(0); |
| 537 |
> |
sig_winch_flag = 1; |
| 538 |
|
signal(SIGWINCH, sig_winch_handler); |
| 539 |
|
} |
| 540 |
|
|
| 561 |
|
} |
| 562 |
|
|
| 563 |
|
void usage(char *progname){ |
| 564 |
+ |
#ifdef COLOR_SUPPORT |
| 565 |
|
fprintf(stderr, "Usage: %s [-d delay] [-c] [-v] [-h]\n\n", progname); |
| 566 |
+ |
#else |
| 567 |
+ |
fprintf(stderr, "Usage: %s [-d delay] [-v] [-h]\n\n", progname); |
| 568 |
+ |
#endif |
| 569 |
|
fprintf(stderr, " -d Sets the update time in seconds\n"); |
| 570 |
+ |
#ifdef COLOR_SUPPORT |
| 571 |
|
fprintf(stderr, " -c Enables coloured output\n"); |
| 572 |
+ |
#endif |
| 573 |
|
fprintf(stderr, " -v Prints version number\n"); |
| 574 |
|
fprintf(stderr, " -h Displays this help information.\n"); |
| 575 |
|
fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
| 595 |
|
return 1; |
| 596 |
|
} |
| 597 |
|
|
| 598 |
+ |
#ifdef COLOR_SUPPORT |
| 599 |
|
while ((c = getopt(argc, argv, "d:cvh")) != -1){ |
| 600 |
+ |
#else |
| 601 |
+ |
while ((c = getopt(argc, argv, "d:vh")) != -1){ |
| 602 |
+ |
#endif |
| 603 |
|
switch (c){ |
| 604 |
|
case 'd': |
| 605 |
|
delay = atoi(optarg); |
| 608 |
|
exit(1); |
| 609 |
|
} |
| 610 |
|
break; |
| 611 |
+ |
#ifdef COLOR_SUPPORT |
| 612 |
|
case 'c': |
| 613 |
|
colouron = 1; |
| 614 |
|
break; |
| 615 |
+ |
#endif |
| 616 |
|
case 'v': |
| 617 |
|
version_num(argv[0]); |
| 618 |
|
break; |
| 626 |
|
|
| 627 |
|
signal(SIGWINCH, sig_winch_handler); |
| 628 |
|
initscr(); |
| 629 |
+ |
#ifdef COLOR_SUPPORT |
| 630 |
|
/* turn on colour */ |
| 631 |
|
if (colouron) { |
| 632 |
|
if (has_colors()) { |
| 643 |
|
colouron = 0; |
| 644 |
|
} |
| 645 |
|
} |
| 646 |
+ |
#endif |
| 647 |
|
nonl(); |
| 648 |
+ |
curs_set(0); |
| 649 |
|
cbreak(); |
| 650 |
|
noecho(); |
| 651 |
|
timeout(delay * 1000); |
| 676 |
|
get_stats(); |
| 677 |
|
} |
| 678 |
|
last_update = now; |
| 679 |
+ |
|
| 680 |
+ |
if(sig_winch_flag) { |
| 681 |
+ |
clear(); |
| 682 |
+ |
display_headings(); |
| 683 |
+ |
sig_winch_flag = 0; |
| 684 |
+ |
} |
| 685 |
|
|
| 686 |
|
display_data(colouron); |
| 687 |
|
} |