--- projects/cms/source/idar/idar.c 2003/04/09 21:55:10 1.14 +++ projects/cms/source/idar/idar.c 2003/04/10 12:31:19 1.15 @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -174,11 +176,7 @@ typedef struct{ int pages_in; int pages_out; - int processes_total; - int processes_sleeping; - int processes_cpu; - int processes_zombie; - int processes_stopped; + int processes; int network_io_total_tx; int network_io_total_rx; @@ -223,27 +221,8 @@ MKCMP(swap_used_pecent) #define DISKIOW "DiskIO writes" #define DISKIO "Total DiskIO (reads+writes)" +int sig_winch=0; -/* -int cmp_cpu(machine_data_list_t *a, machine_data_list_t *b){ - - if(a->cpu_used == b->cpu_used){ - if(a->load_1 == b->load_1) return 0; - if(a->load_1 > b->load_1){ - return -1; - }else{ - return 1; - } - } - - if((a->cpu_used) > (b->cpu_used)){ - return -1; - }else{ - return 1; - } -} -*/ - #ifndef HAVE_ATOLL long long int atoll (const char *nptr){ return strtoll (nptr, (char **) NULL, 10); @@ -718,6 +697,7 @@ void display(machine_data_list_t *machine_data_list, d printw("%5s", "(1m)"); x+=6; } + if(display_config->pages_in && (display_config->maxx > x+6)){ move(1,x); printw("%5s", "Page"); @@ -725,6 +705,7 @@ void display(machine_data_list_t *machine_data_list, d printw("%5s", "ins"); x+=6; } + if(display_config->pages_out && (display_config->maxx > x+6)){ move(1,x); printw("%5s", "Page"); @@ -732,6 +713,7 @@ void display(machine_data_list_t *machine_data_list, d printw("%5s", "outs"); x+=6; } + if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ move(1,x); printw("%5s", "Mem"); @@ -739,6 +721,7 @@ void display(machine_data_list_t *machine_data_list, d printw("%5s", "used"); x+=6; } + if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ move(1,x); printw("%5s", "Swap"); @@ -746,6 +729,7 @@ void display(machine_data_list_t *machine_data_list, d printw("%5s", "used"); x+=6; } + if(display_config->network_io_total_rx){ if(display_config->units=='b' && (display_config->maxx > x+9)){ move(1,x); @@ -754,6 +738,7 @@ void display(machine_data_list_t *machine_data_list, d printw("%8s", "rx"); x+=9; } + if(display_config->units=='k' && (display_config->maxx > x+6)){ move(1,x); printw("%5s", "Net"); @@ -761,14 +746,17 @@ void display(machine_data_list_t *machine_data_list, d printw("%5s", "rx"); x+=6; } - if(display_config->units=='m' && (display_config->maxx > x+5)){ + + if(display_config->units=='m' && (display_config->maxx > x+6)){ move(1,x); - printw("%4s", "Net"); + printw("%5s", "Net"); move(2,x); - printw("%4s", "rx"); - x+=5; + printw("%5s", "rx"); + x+=6; } + } + if(display_config->network_io_total_tx){ if(display_config->units=='b' && (display_config->maxx > x+9)){ move(1,x); @@ -777,6 +765,7 @@ void display(machine_data_list_t *machine_data_list, d printw("%8s", "tx"); x+=9; } + if(display_config->units=='k' && (display_config->maxx > x+6)){ move(1,x); printw("%5s", "Net"); @@ -784,13 +773,15 @@ void display(machine_data_list_t *machine_data_list, d printw("%5s", "tx"); x+=6; } - if(display_config->units=='m' && (display_config->maxx > x+5)){ + + if(display_config->units=='m' && (display_config->maxx > x+6)){ move(1,x); - printw("%4s", "Net"); + printw("%5s", "Net"); move(2,x); - printw("%4s", "tx"); - x+=5; + printw("%5s", "tx"); + x+=6; } + } if(display_config->disk_io_total_read){ @@ -801,6 +792,7 @@ void display(machine_data_list_t *machine_data_list, d printw("%9s", "read"); x+=10; } + if(display_config->units=='k' && (display_config->maxx > x+7)){ move(1,x); printw("%6s", "Disk"); @@ -808,13 +800,15 @@ void display(machine_data_list_t *machine_data_list, d printw("%6s", "read"); x+=7; } - if(display_config->units=='m' && (display_config->maxx > x+6)){ + + if(display_config->units=='m' && (display_config->maxx > x+7)){ move(1,x); - printw("%5s", "Disk"); + printw("%6s", "Disk"); move(2,x); - printw("%5s", "read"); - x+=6; + printw("%6s", "read"); + x+=7; } + } if(display_config->disk_io_total_read){ @@ -825,6 +819,7 @@ void display(machine_data_list_t *machine_data_list, d printw("%9s", "write"); x+=10; } + if(display_config->units=='k' && (display_config->maxx > x+7)){ move(1,x); printw("%6s", "Disk"); @@ -832,15 +827,25 @@ void display(machine_data_list_t *machine_data_list, d printw("%6s", "write"); x+=7; } - if(display_config->units=='m' && (display_config->maxx > x+6)){ + + if(display_config->units=='m' && (display_config->maxx > x+7)){ move(1,x); - printw("%5s", "Disk"); + printw("%6s", "Disk"); move(2,x); - printw("%5s", "write"); - x+=6; + printw("%6s", "write"); + x+=7; } + } - + + if(display_config->processes && (display_config->maxx > x+25)){ + move(1,x); + printw("%-24s", " Number of Process"); + move(2,x); + printw("%-24s", " Run Slep Zomb Stop Tot"); + x+=25; + } + *title=0; } @@ -885,9 +890,9 @@ void display(machine_data_list_t *machine_data_list, d printw(" %5lld", machine_data_list->network_io_total_rx/1024); x+=6; } - if(display_config->units=='m' && (display_config->maxx > x+5)){ - printw(" %4.1f", (double)(machine_data_list->network_io_total_rx/(1024.00*1024.00))); - x+=5; + if(display_config->units=='m' && (display_config->maxx > x+6)){ + printw(" %5.2f", (double)(machine_data_list->network_io_total_rx/(1024.00*1024.00))); + x+=6; } } @@ -900,9 +905,9 @@ void display(machine_data_list_t *machine_data_list, d printw(" %5lld", machine_data_list->network_io_total_tx/1024); x+=6; } - if(display_config->units=='m' && (display_config->maxx > x+5)){ - printw(" %4.1f", (double)(machine_data_list->network_io_total_tx/(1024.00*1024.00))); - x+=5; + if(display_config->units=='m' && (display_config->maxx > x+6)){ + printw(" %5.2f", (double)(machine_data_list->network_io_total_tx/(1024.00*1024.00))); + x+=6; } } @@ -915,9 +920,9 @@ void display(machine_data_list_t *machine_data_list, d printw(" %6lld", machine_data_list->disk_io_total_read/1024); x+=7; } - if(display_config->units=='m' && (display_config->maxx > x+6)){ - printw(" %5.1f", (double)(machine_data_list->disk_io_total_read/(1024.00*1024.00))); - x+=6; + if(display_config->units=='m' && (display_config->maxx > x+7)){ + printw(" %6.2f", (double)(machine_data_list->disk_io_total_read/(1024.00*1024.00))); + x+=7; } } @@ -930,11 +935,19 @@ void display(machine_data_list_t *machine_data_list, d printw(" %6lld", machine_data_list->disk_io_total_write/1024); x+=7; } - if(display_config->units=='m' && (display_config->maxx > x+6)){ - printw(" %5.1f", (double)(machine_data_list->disk_io_total_write/(1024.00*1024.00))); - x+=6; + if(display_config->units=='m' && (display_config->maxx > x+7)){ + printw(" %6.2f", (double)(machine_data_list->disk_io_total_write/(1024.00*1024.00))); + x+=7; } } + if(display_config->processes && display_config->maxx > x+25){ + printw(" %4d %4d %4d %4d %4d", machine_data_list->processes_cpu, \ + machine_data_list->processes_sleeping, \ + machine_data_list->processes_zombie, \ + machine_data_list->processes_stopped, \ + machine_data_list->processes_total); + x+=25; + } machine_data_list=machine_data_list->next; } @@ -944,6 +957,12 @@ void display(machine_data_list_t *machine_data_list, d } +void sig_winch_handler(int sig){ + + sig_winch=1; + signal(SIGWINCH, sig_winch_handler); +} + int main(int argc, char **argv){ WINDOW *window; fd_set infds; @@ -967,6 +986,8 @@ int main(int argc, char **argv){ int cmdopt; extern int optind; extern char *optarg; + + extern int errno; display_config_t display_config; char ch; @@ -1002,11 +1023,7 @@ int main(int argc, char **argv){ display_config.pages_in=1; display_config.pages_out=1; - display_config.processes_total=0; - display_config.processes_sleeping=0; - display_config.processes_cpu=0; - display_config.processes_zombie=0; - display_config.processes_stopped=0; + display_config.processes=1; display_config.network_io_total_tx=1; display_config.network_io_total_rx=1; @@ -1017,8 +1034,10 @@ int main(int argc, char **argv){ display_config.disk_io_all_stats=0; display_config.disk_total_used=0; - display_config.disk_all_stats=0; + display_config.disk_all_stats=0; + signal(SIGWINCH, sig_winch_handler); + while((cmdopt=getopt(argc, argv, "s:")) != -1){ switch(cmdopt){ case 's': @@ -1109,16 +1128,10 @@ int main(int argc, char **argv){ exit(1); } - /* - printf("\033[2J"); - printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); - printf("\033[2;1H used%% (1m) ins outs used used rx tx read write"); - */ - initscr(); nonl(); cbreak(); - echo(); + noecho(); window=newwin(0, 0, 0, 0); getmaxyx(window, display_config.maxy, display_config.maxx); @@ -1131,6 +1144,13 @@ int main(int argc, char **argv){ FD_SET(stdin_fileno, &infds); FD_SET(data_fileno, &infds); if((select(biggest_fileno, &infds, NULL, NULL, NULL))==-1){ + if(errno!=EINTR){ + errf("select failed with (%m)"); + exit(1); + } + } + + if(sig_winch){ if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { resizeterm(size.ws_row, size.ws_col); wrefresh(curscr); @@ -1139,13 +1159,17 @@ int main(int argc, char **argv){ title=1; display(machine_data_list, &display_config, &title); refresh(); + sig_winch=0; continue; } if(FD_ISSET(stdin_fileno, &infds)){ - ch=getc(stdin); + ch=getch(); switch(ch){ + case KEY_RESIZE: + sig_winch=1; + break; /* Quit */ case 'Q': @@ -1269,13 +1293,16 @@ int main(int argc, char **argv){ display_config.cpu_used=1; } break; + case 'r': + if(display_config.processes){ + display_config.processes=0; + }else{ + display_config.processes=1; + } + break; default: - /* Invalid key.. Ignore.. Set Title to -1, as the - * title++ will then make that "0" (false) so a - * screen redraw will not happen */ - title=-1; - break; + continue; } /* Increment title so it becomes true (and making the screen update */