Package: saidar Version: 0.13-1 Severity: wishlist Most X terminals today can do at the very least basic color output but saidar has no built in color support.
I have attached a patch for color support, a man page patch and a brief readme, screenshot here: http://bzgirl.org/images/saidar.png ogg movie: http://bzgirl.org/tmp/zombie.ogg
--- libstatgrab-0.13/src/saidar/saidar.c 2005-09-07 10:15:40.000000000 -0400 +++ libstatgrab-0.13-local/src/saidar/saidar.c 2006-11-26 14:52:42.000000000 -0500 @@ -36,6 +36,7 @@ #include <sys/times.h> #include <limits.h> #include <time.h> +#include <math.h> /* fabs() */ #ifdef HAVE_NCURSES_H #include <ncurses.h> @@ -43,6 +44,14 @@ #include <curses.h> #endif +#define THRESHOLD_LOAD 0.5 +#define THRESHOLD_WARN_ZMB 0 +#define THRESHOLD_WARN_CPU 60.0 +#define THRESHOLD_ALERT_CPU 90.0 +#define THRESHOLD_WARN_SWAP 0 +#define THRESHOLD_WARN_DISC 75.0 +#define THRESHOLD_ALERT_DISC 90.0 + typedef struct{ sg_cpu_percents *cpu_percents; sg_mem_stats *mem_stats; @@ -211,7 +220,7 @@ refresh(); } -void display_data(){ +void display_data(int colors){ char cur_time[20]; struct tm *tm_time; time_t epoc_time; @@ -237,6 +246,9 @@ if (ptr != NULL){ *ptr = '\0'; } + if (colors) { + attron(COLOR_PAIR(1)); + } printw("%s", hostname); move(0,36); printw("%s", hr_uptime(stats.host_info->uptime)); @@ -245,16 +257,46 @@ strftime(cur_time, 20, "%Y-%m-%d %T", tm_time); move(0,61); printw("%s", cur_time); + if (colors) { + attroff(COLOR_PAIR(1)); + } } if (stats.load_stats != NULL) { /* Load */ + if (colors) { + attron(COLOR_PAIR(6)); + } move(2,12); + if (fabs(stats.load_stats->min1 - stats.load_stats->min5) > THRESHOLD_LOAD) { + if (colors) { + attron(A_BOLD); + } + } printw("%6.2f", stats.load_stats->min1); + if (colors) { + attroff(A_BOLD); + } move(3,12); + if (fabs(stats.load_stats->min5 - stats.load_stats->min15) > THRESHOLD_LOAD) { + if (colors) { + attron(A_BOLD); + } + } printw("%6.2f", stats.load_stats->min5); + if (colors) { + attroff(A_BOLD); + } move(4,12); + if (fabs(stats.load_stats->min1 - stats.load_stats->min15) > THRESHOLD_LOAD) { + if (colors) { + attron(A_BOLD); + } + } printw("%6.2f", stats.load_stats->min15); + if (colors) { + attroff(A_BOLD); + } } if (stats.cpu_percents != NULL) { @@ -264,7 +306,23 @@ move(3,33); printw("%6.2f%%", (stats.cpu_percents->kernel + stats.cpu_percents->iowait + stats.cpu_percents->swap)); move(4,33); + if (stats.cpu_percents->user + stats.cpu_percents->nice > THRESHOLD_ALERT_CPU) { + if(colors) { + attron(COLOR_PAIR(1)); + attron(A_STANDOUT); + } + } else if (stats.cpu_percents->user + stats.cpu_percents->nice > THRESHOLD_WARN_CPU) { + if(colors) { + attron(A_BOLD); + } + } printw("%6.2f%%", (stats.cpu_percents->user + stats.cpu_percents->nice)); + if(colors) { + attroff(COLOR_PAIR(1)); + attroff(A_BOLD); + attroff(A_STANDOUT); + attron(COLOR_PAIR(6)); + } } if (stats.process_count != NULL) { @@ -272,7 +330,20 @@ move(2, 54); printw("%5d", stats.process_count->running); move(2,74); + if (stats.process_count->zombie > THRESHOLD_WARN_ZMB) { + if (colors) { + attron(COLOR_PAIR(1)); + attron(A_BLINK); + attron(A_BOLD); + } + } printw("%5d", stats.process_count->zombie); + if(colors) { + attroff(COLOR_PAIR(1)); + attroff(A_BLINK); + attroff(A_BOLD); + attron(COLOR_PAIR(6)); + } move(3, 54); printw("%5d", stats.process_count->sleeping); move(3, 74); @@ -284,7 +355,10 @@ move(4,74); printw("%5d", stats.user_stats->num_entries); } - + if(colors) { + attroff(COLOR_PAIR(6)); + attron(COLOR_PAIR(5)); + } if (stats.mem_stats != NULL) { /* Mem */ move(6, 12); @@ -300,7 +374,15 @@ move(6, 32); printw("%8s", size_conv(stats.swap_stats->total)); move(7, 32); + if (stats.swap_stats->used > THRESHOLD_WARN_SWAP) { + if (colors) { + attron(A_STANDOUT); + } + } printw("%8s", size_conv(stats.swap_stats->used)); + if (colors) { + attroff(A_STANDOUT); + } move(8, 32); printw("%8s", size_conv(stats.swap_stats->free)); } @@ -327,6 +409,9 @@ move(7, 74); printw("%5d", (stats.page_stats->systime)? (stats.page_stats->pages_pageout / stats.page_stats->systime) : stats.page_stats->pages_pageout); } + if (colors) { + attroff(COLOR_PAIR(5)); + } line = 11; if (stats.disk_io_stats != NULL) { @@ -342,6 +427,9 @@ printw("%s", name); move(line, 12); rt = (disk_io_stat_ptr->systime)? (disk_io_stat_ptr->read_bytes/disk_io_stat_ptr->systime): disk_io_stat_ptr->read_bytes; + if(colors) { + attron(COLOR_PAIR(4)); + } printw("%7s", size_conv(rt)); r+=rt; move(line, 26); @@ -350,14 +438,23 @@ w+=wt; disk_io_stat_ptr++; line++; + if(colors) { + attroff(COLOR_PAIR(4)); + } } line++; move(line, 0); printw("Total"); move(line, 12); + if(colors) { + attron(COLOR_PAIR(4)); + } printw("%7s", size_conv(r)); move(line, 26); printw("%7s", size_conv(w)); + if(colors) { + attroff(COLOR_PAIR(4)); + } } line = 11; @@ -372,12 +469,18 @@ printw("%s", name); move(line, 62); rt = (network_stat_ptr->systime)? (network_stat_ptr->rx / network_stat_ptr->systime): network_stat_ptr->rx; + if(colors) { + attron(COLOR_PAIR(4)); + } printw("%7s", size_conv(rt)); move(line, 72); wt = (network_stat_ptr->systime)? (network_stat_ptr->tx / network_stat_ptr->systime): network_stat_ptr->tx; printw("%7s", size_conv(wt)); network_stat_ptr++; line++; + if(colors) { + attroff(COLOR_PAIR(4)); + } } line += 2; } @@ -392,11 +495,29 @@ move(line, 42); printw("%s", name); move(line, 62); + if(colors) { + attron(COLOR_PAIR(2)); + } printw("%7s", size_conv(disk_stat_ptr->avail)); move(line, 73); + if(100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail)) > THRESHOLD_ALERT_DISC) { + if(colors) { + attron(A_STANDOUT); + } + } else if (100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail)) > THRESHOLD_WARN_DISC) { + if(colors) { + attron(A_BOLD); + } + } printw("%6.2f%%", 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail))); disk_stat_ptr++; line++; + if(colors) { + attroff(COLOR_PAIR(2)); + attroff(COLOR_PAIR(1)); + attroff(A_STANDOUT); + attroff(A_BOLD); + } } } @@ -406,7 +527,7 @@ void sig_winch_handler(int dummy){ clear(); display_headings(); - display_data(); + display_data(0); signal(SIGWINCH, sig_winch_handler); } @@ -436,6 +557,7 @@ fprintf(stderr, "Usage: %s [-d delay] [-v] [-h]\n\n", progname); fprintf(stderr, " -d Sets the update time in seconds\n"); fprintf(stderr, " -v Prints version number\n"); + fprintf(stderr, " -c Enable colorized output\n"); fprintf(stderr, " -h Displays this help information.\n"); fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); exit(1); @@ -445,6 +567,7 @@ extern char *optarg; int c; + int coloron = 0; time_t last_update = 0; @@ -460,7 +583,7 @@ return 1; } - while ((c = getopt(argc, argv, "vhd:")) != -1){ + while ((c = getopt(argc, argv, "vhcd:")) != -1){ switch (c){ case 'd': delay = atoi(optarg); @@ -472,6 +595,9 @@ case 'v': version_num(argv[0]); break; + case 'c': + coloron = 1; + break; case 'h': default: usage(argv[0]); @@ -482,6 +608,22 @@ signal(SIGWINCH, sig_winch_handler); initscr(); + /* turn on color */ + if (coloron) { + if (has_colors()) { + start_color(); + use_default_colors(); + init_pair(1,COLOR_RED,-1); + init_pair(2,COLOR_GREEN,-1); + init_pair(3,COLOR_YELLOW,-1); + init_pair(4,COLOR_BLUE,-1); + init_pair(5,COLOR_MAGENTA,-1); + init_pair(6,COLOR_CYAN,-1); + } else { + fprintf(stderr, "Color disabled, your terminal does not support color."); + coloron = 0; + } + } nonl(); cbreak(); noecho(); @@ -514,7 +656,7 @@ } last_update = now; - display_data(); + display_data(coloron); } endwin();
--- libstatgrab-0.13/docs/saidar/saidar.1 2006-03-18 05:44:15.000000000 -0500 +++ libstatgrab-0.13-local/docs/saidar/saidar.1 2006-11-26 12:15:20.000000000 -0500 @@ -17,6 +17,9 @@ \fB\-v\fR Prints the version number .TP +\fB\-c\fR +Enables colored output +.TP \fB\-h\fR Display help and exits .SH SEE\ ALSO
Angelina Carlton <[EMAIL PROTECTED]> saidar color support ==================== saidar's output has 6 distinct sections. a host section (hostname, uptime etc) a process section (load, cpu, zombie etc) a memory section (virtual, swap, paging) a disc i/o section a network section a disc capacity section the host section is colored red the process section is cyan the memory section is magenta the disc i/o and network section is blue the disc capacity section is green because the disc i/o and network sections sit on the same line visually they share one color. the load average numbers change to `bold' based on how much they change in relationship to each other inbetween updates, but it is not anything scientific, it simply gives a reasonably good visual cue of when the system is under load. the user cpu entry bolds at 60% usage and then changes to `standout' at 90% anytime the system starts using swap space the swap used number is given `standout' disc space is `bold' at 75% full and `standout' at 90% full. I didn't touch network and disc i/o because its difficult to determine what one would on average think is high or low for these numbers. (basically too much work :-)) any zombie process is bold red and blinks. probally blinking should be removed as its generally considered annoying, but then zombies are annoying too. I added a -c option to enable or disable colors. I would perhaps later like to add user defined colors via ~/.saidarrc file
-- System Information: Debian Release: 4.0 APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.18-1-486 Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8) Versions of packages saidar depends on: ii libc6 2.3.6.ds1-8 GNU C Library: Shared libraries ii libncurses5 5.5-5 Shared libraries for terminal hand ii libstatgrab6 0.13-1 library being useful interface to saidar recommends no packages. -- no debconf information -- -----Angelina Carlton----- orchid on irc.freenode.net [EMAIL PROTECTED] http://bzgirl.org --------------------------