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 |
|
|
309 |
|
move(4,33); |
310 |
|
if (colors && stats.cpu_percents->user + stats.cpu_percents->nice > THRESHOLD_ALERT_CPU) { |
311 |
|
attron(A_STANDOUT); |
312 |
+ |
attron(A_BOLD); |
313 |
|
} |
314 |
|
else if (colors && stats.cpu_percents->user + stats.cpu_percents->nice > THRESHOLD_WARN_CPU) { |
315 |
|
attron(A_BOLD); |
329 |
|
move(2,74); |
330 |
|
if (colors && stats.process_count->zombie > THRESHOLD_WARN_ZMB) { |
331 |
|
attron(A_STANDOUT); |
332 |
+ |
attron(A_BOLD); |
333 |
|
} |
334 |
|
printw("%5d", stats.process_count->zombie); |
335 |
|
if(colors) { |
336 |
|
attroff(A_STANDOUT); |
337 |
< |
attron(COLOR_PAIR(6)); |
337 |
> |
attroff(A_BOLD); |
338 |
|
} |
339 |
|
move(3, 54); |
340 |
|
printw("%5d", stats.process_count->sleeping); |
377 |
|
float f = 100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total; |
378 |
|
if (colors && f > THRESHOLD_ALERT_MEM) { |
379 |
|
attron(A_STANDOUT); |
380 |
+ |
attron(A_BOLD); |
381 |
|
} |
382 |
|
else if (colors && f > THRESHOLD_WARN_MEM) { |
383 |
|
attron(A_BOLD); |
394 |
|
float f = 100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total; |
395 |
|
if (colors && f > THRESHOLD_ALERT_SWAP) { |
396 |
|
attron(A_STANDOUT); |
397 |
+ |
attron(A_BOLD); |
398 |
|
} |
399 |
|
else if (colors && f > THRESHOLD_WARN_SWAP) { |
400 |
|
attron(A_BOLD); |
513 |
|
move(line, 73); |
514 |
|
if(colors && 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail)) > THRESHOLD_ALERT_DISK) { |
515 |
|
attron(A_STANDOUT); |
516 |
+ |
attron(A_BOLD); |
517 |
|
} else if (colors && 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail)) > THRESHOLD_WARN_DISK) { |
518 |
|
attron(A_BOLD); |
519 |
|
} |
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); |