--- projects/cms/source/idar/idar.c 2003/03/28 15:37:05 1.1 +++ projects/cms/source/idar/idar.c 2003/08/21 21:10:34 1.20 @@ -1,15 +1,51 @@ +/* + * i-scream central monitoring system + * http://www.i-scream.org.uk + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include #include +#include #include #include #include +#include +#include +#include +#include +#include #include #include #include "genmergesort.h" +#ifdef HAVE_NCURSES_H +#include +#else +#include +#endif + struct host_line_t{ char *hostname; int line; @@ -92,10 +128,12 @@ struct machine_data_t{ network_data_list_t *network_data_list; long long network_io_total_tx; long long network_io_total_rx; + long long network_io_total; diskio_data_list_t *diskio_data_list; long long disk_io_total_write; long long disk_io_total_read; + long long disk_io_total; /* Maybe in the future */ /* @@ -108,7 +146,13 @@ struct machine_data_t{ typedef struct machine_data_t machine_data_list_t; +#define SORTBYMAXNAME 128 typedef struct{ + int maxx; + int maxy; + + char units; + int cpu_user; int cpu_idle; int cpu_iowait; @@ -133,11 +177,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; @@ -149,27 +189,111 @@ typedef struct{ int disk_total_used; int disk_all_stats; + + char sortby[SORTBYMAXNAME]; }display_config_t; GENERIC_MERGE_SORT(static, sort_machine_stats, machine_data_list_t, next) -int cmp_cpu(machine_data_list_t *a, machine_data_list_t *b){ +#define MKCMP(x) int cmp_##x(machine_data_list_t *a, machine_data_list_t *b){return ((a->x) == (b->x)? 0 : (((a->x) > (b->x))? -1 : 1));} - 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; - } +int (*sortby_ptr)(machine_data_list_t *a, machine_data_list_t *b); + +MKCMP(cpu_used) +MKCMP(load_1) +MKCMP(network_io_total) +MKCMP(network_io_total_tx) +MKCMP(network_io_total_rx) +MKCMP(disk_io_total) +MKCMP(disk_io_total_write) +MKCMP(disk_io_total_read) +MKCMP(memory_used_pecent) +MKCMP(swap_used_pecent) + +#define CPU_USED "CPU used" +#define LOAD "Load (1)" +#define NETIORX "total Network RX for all interfaces" +#define NETIOTX "total Network TX for all interfaces" +#define NETIO "total Network IO for all interfaces (rx+tx)" +#define MEM "Memory usage" +#define SWAP "Swap usage" +#define DISKIOR "DiskIO reads" +#define DISKIOW "DiskIO writes" +#define DISKIO "Total DiskIO (reads+writes)" + +int sig_winch=0; + +#ifndef HAVE_ATOLL +long long int atoll (const char *nptr){ + return strtoll (nptr, (char **) NULL, 10); } +#endif + +#ifndef HAVE_STRLCPY +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +#endif + FILE *create_tcp_connection(char *hostname, int port){ int sock; @@ -518,6 +642,7 @@ int parse_xml(char *xml, machine_data_list_t **md){ machine_data_list->network_io_total_rx+=ndl_ptr->rx; ndl_ptr=ndl_ptr->next; } + machine_data_list->network_io_total=machine_data_list->network_io_total_rx+machine_data_list->network_io_total_tx; didl_ptr=machine_data_list->diskio_data_list; machine_data_list->disk_io_total_read=0; @@ -527,6 +652,7 @@ int parse_xml(char *xml, machine_data_list_t **md){ machine_data_list->disk_io_total_write+=didl_ptr->write; didl_ptr=didl_ptr->next; } + machine_data_list->disk_io_total=machine_data_list->disk_io_total_read+machine_data_list->disk_io_total_write; xmlFreeDoc(doc); @@ -535,54 +661,359 @@ int parse_xml(char *xml, machine_data_list_t **md){ } -void display(machine_data_list_t *machine_data_list, int num_lines){ +void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int *title){ int line_num=4; + int counter; + int x=1; - for(;num_lines;num_lines--){ + if(*title){ + clear(); + move (display_config->maxy-3, 1); + printw("Sorting by %-64s", display_config->sortby); + move (display_config->maxy-2, 1); + if(display_config->units == 'b'){ + printw("Units are measured in bytes/sec"); + } + if(display_config->units == 'k'){ + printw("Units are measured in kilobytes/sec"); + } + if(display_config->units == 'm'){ + printw("Units are measured in megabytes/sec"); + } + + move(1,1); + printw("%-11s", "Hostname"); + x=x+11+1; + if(display_config->cpu_used && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "CPU"); + move(2,x); + printw("%5s", "used%"); + x+=6; + } + if(display_config->load_1 && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "Load"); + move(2,x); + printw("%5s", "(1m)"); + x+=6; + } + + if(display_config->pages_in && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "Page"); + move(2,x); + printw("%5s", "ins"); + x+=6; + } + + if(display_config->pages_out && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "Page"); + move(2,x); + printw("%5s", "outs"); + x+=6; + } + + if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "Mem"); + move(2,x); + printw("%5s", "used"); + x+=6; + } + + if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "Swap"); + move(2,x); + 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); + printw("%8s", "Net"); + move(2,x); + printw("%8s", "rx"); + x+=9; + } + + if(display_config->units=='k' && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "Net"); + move(2,x); + printw("%5s", "rx"); + x+=6; + } + + if(display_config->units=='m' && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "Net"); + move(2,x); + 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); + printw("%8s", "Net"); + move(2,x); + printw("%8s", "tx"); + x+=9; + } + + if(display_config->units=='k' && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "Net"); + move(2,x); + printw("%5s", "tx"); + x+=6; + } + + if(display_config->units=='m' && (display_config->maxx > x+6)){ + move(1,x); + printw("%5s", "Net"); + move(2,x); + printw("%5s", "tx"); + x+=6; + } + + } + + if(display_config->disk_io_total_read){ + if(display_config->units=='b' && (display_config->maxx > x+10)){ + move(1,x); + printw("%9s", "Disk"); + move(2,x); + printw("%9s", "read"); + x+=10; + } + + if(display_config->units=='k' && (display_config->maxx > x+7)){ + move(1,x); + printw("%6s", "Disk"); + move(2,x); + printw("%6s", "read"); + x+=7; + } + + if(display_config->units=='m' && (display_config->maxx > x+7)){ + move(1,x); + printw("%6s", "Disk"); + move(2,x); + printw("%6s", "read"); + x+=7; + } + + } + + if(display_config->disk_io_total_read){ + if(display_config->units=='b' && (display_config->maxx > x+10)){ + move(1,x); + printw("%9s", "Disk"); + move(2,x); + printw("%9s", "write"); + x+=10; + } + + if(display_config->units=='k' && (display_config->maxx > x+7)){ + move(1,x); + printw("%6s", "Disk"); + move(2,x); + printw("%6s", "write"); + x+=7; + } + + if(display_config->units=='m' && (display_config->maxx > x+7)){ + move(1,x); + printw("%6s", "Disk"); + move(2,x); + 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; + } + + /* Counter starts at 8, for padding (eg, headers, borders etc) */ + for(counter=8;countermaxy;counter++){ if(machine_data_list==NULL) break; - printf("\033[%d;%dH%-11s %5.1f %5.1f %5d %5d %5.1f %5.1f %8lld %8lld %9lld %9lld", \ - line_num++, 1, \ - machine_data_list->sysname, - machine_data_list->cpu_used, - machine_data_list->load_1, - machine_data_list->pages_in, - machine_data_list->pages_out, - machine_data_list->memory_used_pecent, - machine_data_list->swap_used_pecent, - machine_data_list->network_io_total_rx, - machine_data_list->network_io_total_tx, - machine_data_list->disk_io_total_read, - machine_data_list->disk_io_total_write); + move(line_num++, 1); + printw("%-11s", machine_data_list->sysname); + x=13; + + if(display_config->cpu_used && (display_config->maxx > x+6)){ + printw(" %5.1f", machine_data_list->cpu_used); + x+=6; + } + if(display_config->load_1 && (display_config->maxx > x+6)){ + printw(" %5.1f", machine_data_list->load_1); + x+=6; + } + if(display_config->pages_in && (display_config->maxx > x+6)){ + printw(" %5d", machine_data_list->pages_in); + x+=6; + } + if(display_config->pages_out && (display_config->maxx > x+6)){ + printw(" %5d", machine_data_list->pages_out); + x+=6; + } + if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ + printw(" %5.1f", machine_data_list->memory_used_pecent); + x+=6; + } + if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ + printw(" %5.1f", machine_data_list->swap_used_pecent); + x+=6; + } + + if(display_config->network_io_total_rx){ + if(display_config->units=='b' && (display_config->maxx > x+9)){ + printw(" %8lld", machine_data_list->network_io_total_rx); + x+=9; + } + if(display_config->units=='k' && (display_config->maxx > x+6)){ + printw(" %5lld", machine_data_list->network_io_total_rx/1024); + x+=6; + } + 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; + } + } + + if(display_config->network_io_total_tx){ + if(display_config->units=='b' && (display_config->maxx > x+9)){ + printw(" %8lld", machine_data_list->network_io_total_tx); + x+=9; + } + if(display_config->units=='k' && (display_config->maxx > x+6)){ + printw(" %5lld", machine_data_list->network_io_total_tx/1024); + x+=6; + } + 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; + } + } + + if(display_config->disk_io_total_read){ + if(display_config->units=='b' && (display_config->maxx > x+10)){ + printw(" %9lld", machine_data_list->disk_io_total_read); + x+=10; + } + if(display_config->units=='k' && (display_config->maxx > x+7)){ + printw(" %6lld", machine_data_list->disk_io_total_read/1024); + x+=7; + } + 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; + } + } + + if(display_config->disk_io_total_write){ + if(display_config->units=='b' && (display_config->maxx > x+10)){ + printw(" %9lld", machine_data_list->disk_io_total_write); + x+=10; + } + if(display_config->units=='k' && (display_config->maxx > x+7)){ + printw(" %6lld", machine_data_list->disk_io_total_write/1024); + x+=7; + } + 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; } - fflush(stdout); + + refresh(); } +void sig_winch_handler(int sig){ + + sig_winch=1; + signal(SIGWINCH, sig_winch_handler); +} + +void usage() { + printf("Usage: idar [-o order] [-s server] [-p port] [-l list] [-h]\n\n"); + printf(" -o Sets the initial sort order. Accepted arguments are one of:\n"); + printf(" cpu load mem swap net disk\n"); + printf(" -s Specifies the i-scream server to connect to.\n"); + printf(" default: %s\n", DEF_SERVER_NAME); + printf(" -p Specifies the i-scream server port.\n"); + printf(" default: %d\n", DEF_SERVER_PORT); + printf(" -l Sets the list of hosts to monitor in a semi-colon separated list.\n"); + printf(" -h Displays this help information.\n"); + printf("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); + exit(1); +} + int main(int argc, char **argv){ + WINDOW *window; + fd_set infds; + struct winsize size; + FILE *control; FILE *data; char *machine_list=NULL; char *response=NULL; - char *servername; + char *server_name; int server_control_port; int server_data_port; machine_data_list_t *machine_data_list=NULL; int num_hosts; - int max_display=0; + int title=1; int cmdopt; extern int optind; extern char *optarg; + + extern int errno; display_config_t display_config; + char ch; + int data_fileno, stdin_fileno, biggest_fileno; + + sortby_ptr=NULL; + /* What to display defaults */ + display_config.units='b'; + display_config.cpu_user=0; display_config.cpu_idle=0; display_config.cpu_iowait=0; @@ -607,51 +1038,90 @@ 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=0; - display_config.network_io_total_rx=0; - display_config.network_all_stats=1; + display_config.network_io_total_tx=1; + display_config.network_io_total_rx=1; + display_config.network_all_stats=0; - display_config.disk_io_total_write=0; - display_config.disk_io_total_read=0; - display_config.disk_io_all_stats=1; + display_config.disk_io_total_write=1; + display_config.disk_io_total_read=1; + 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; - while((cmdopt=getopt(argc, argv, "d:")) != -1){ + signal(SIGWINCH, sig_winch_handler); + + server_name=DEF_SERVER_NAME; + server_control_port=DEF_SERVER_PORT; + + while((cmdopt=getopt(argc, argv, "o:s:p:l:h")) != -1){ switch(cmdopt){ - case 'd': - max_display=atoi(optarg); - break; + case 'o': + if(!strcmp(optarg, "cpu")){ + sortby_ptr=cmp_cpu_used; + strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); + } + if(!strcmp(optarg, "load")){ + sortby_ptr=cmp_load_1; + strlcpy(display_config.sortby, LOAD, SORTBYMAXNAME); + } + if(!strcmp(optarg, "mem")){ + sortby_ptr=cmp_memory_used_pecent; + strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); + } + if(!strcmp(optarg, "swap")){ + sortby_ptr=cmp_swap_used_pecent; + strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); + } + if(!strcmp(optarg, "net")){ + sortby_ptr=cmp_network_io_total; + strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME); + } + if(!strcmp(optarg, "disk")){ + sortby_ptr=cmp_disk_io_total; + strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME); + } + if(sortby_ptr==NULL){ + errf("Invalid order given."); + usage(); + } + break; + case 's': + server_name=optarg; + break; + case 'p': + server_control_port=atoi(optarg); + break; + case 'l': + /* We've been passed a machine list */ + /* list currently needs to be ; seperated */ + machine_list=strdup(optarg); + break; + case 'h': + default: + usage(); + break; } } + /* Don't take any other arguments */ + if(argc>optind){ + usage(); + } - if(argc<(optind+2)){ - printf("Usage is %s <-d lines> hostname port \n", argv[0]); - exit(1); + if(sortby_ptr==NULL){ + sortby_ptr=cmp_cpu_used; + strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME); } - servername=argv[optind]; - server_control_port=atoi(argv[optind+1]); - - control=create_tcp_connection(servername, server_control_port); + control=create_tcp_connection(server_name, server_control_port); if(control==NULL){ errf("Failed to connect (%m)"); + exit(1); } - if(argc==4){ - /* We've been passed a machine list */ - /* list currently needs to be ; seperated */ - machine_list=strdup(argv[3]); - } - if((tcp_comm(control, NULL, &response, "PROTOCOL 1.1"))!=0){ errf("Incorrect version number (%s)", response); exit(1); @@ -684,31 +1154,206 @@ int main(int argc, char **argv){ exit(1); } - data=create_tcp_connection(servername, server_data_port); + data=create_tcp_connection(server_name, server_data_port); if(data==NULL){ - errf("Failed to connect to host %s on port %d (%m)",servername, server_data_port); + errf("Failed to connect to host %s on port %d (%m)",server_name, server_data_port); + 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"); - fflush(stdout); + initscr(); + nonl(); + cbreak(); + noecho(); + window=newwin(0, 0, 0, 0); + getmaxyx(window, display_config.maxy, display_config.maxx); + + stdin_fileno=fileno(stdin); + data_fileno=fileno(data); + biggest_fileno=(data_fileno>stdin_fileno) ? (data_fileno+1) : (stdin_fileno+1); + for(;;){ - response=fpgetline(data); - if (response==NULL){ - errf("Failed to read data (%m)"); - exit(1); + FD_ZERO(&infds); + 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); + } + getmaxyx(window, display_config.maxy, display_config.maxx); + title=1; + display(machine_data_list, &display_config, &title); + refresh(); + sig_winch=0; + continue; + } + + if(FD_ISSET(stdin_fileno, &infds)){ + + ch=getch(); + switch(ch){ + case KEY_RESIZE: + sig_winch=1; + break; + + /* Quit */ + case 'Q': + case 'q': + endwin(); + exit(0); + break; + /* Units */ + case 'U': + case 'u': + if(display_config.units == 'b'){ + display_config.units = 'k'; + }else if(display_config.units == 'k'){ + display_config.units = 'm'; + }else{ + display_config.units = 'b'; + } + break; + + /* Sort by */ + case 'C': + sortby_ptr=cmp_cpu_used; + strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); + break; + + case 'M': + sortby_ptr=cmp_memory_used_pecent; + strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); + break; + + case 'L': + sortby_ptr=cmp_load_1; + strlcpy(display_config.sortby, LOAD, SORTBYMAXNAME); + break; + + case 'S': + sortby_ptr=cmp_swap_used_pecent; + strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); + break; + + case 'N': + if(sortby_ptr==cmp_network_io_total){ + strlcpy(display_config.sortby, NETIORX, SORTBYMAXNAME); + sortby_ptr=cmp_network_io_total_rx; + }else if(sortby_ptr==cmp_network_io_total_rx){ + strlcpy(display_config.sortby, NETIOTX, SORTBYMAXNAME); + sortby_ptr=cmp_network_io_total_tx; + }else{ + strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME); + sortby_ptr=cmp_network_io_total; + } + break; + case 'D': + if(sortby_ptr==cmp_disk_io_total){ + strlcpy(display_config.sortby, DISKIOR, SORTBYMAXNAME); + sortby_ptr=cmp_disk_io_total_read; + }else if(sortby_ptr==cmp_disk_io_total_read){ + strlcpy(display_config.sortby, DISKIOW, SORTBYMAXNAME); + sortby_ptr=cmp_disk_io_total_write; + }else{ + strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME); + sortby_ptr=cmp_disk_io_total; + } + break; + + /* Display */ + + case 'd': + if(display_config.disk_io_total_read){ + display_config.disk_io_total_read=0; + display_config.disk_io_total_write=0; + }else{ + display_config.disk_io_total_read=1; + display_config.disk_io_total_write=1; + } + break; + case 'n': + if(display_config.network_io_total_rx){ + display_config.network_io_total_rx=0; + display_config.network_io_total_tx=0; + }else{ + display_config.network_io_total_rx=1; + display_config.network_io_total_tx=1; + } + break; + case 'm': + if(display_config.memory_used_pecent){ + display_config.memory_used_pecent=0; + }else{ + display_config.memory_used_pecent=1; + } + break; + + case 's': + if(display_config.swap_used_pecent){ + display_config.swap_used_pecent=0; + }else{ + display_config.swap_used_pecent=1; + } + break; + case 'l': + if(display_config.load_1){ + display_config.load_1=0; + }else{ + display_config.load_1=1; + } + break; + case 'p': + if(display_config.pages_in){ + display_config.pages_in=0; + display_config.pages_out=0; + }else{ + display_config.pages_in=1; + display_config.pages_out=1; + } + break; + case 'c': + if(display_config.cpu_used){ + display_config.cpu_used=0; + }else{ + display_config.cpu_used=1; + } + break; + case 'r': + if(display_config.processes){ + display_config.processes=0; + }else{ + display_config.processes=1; + } + break; + + default: + continue; + } + + /* Increment title so it becomes true (and making the screen update */ + title++; + + } + if(FD_ISSET(data_fileno, &infds)){ + response=fpgetline(data); + if (response==NULL){ + errf("Failed to read data (%m)"); + exit(1); + } + } + + num_hosts=parse_xml(response, &machine_data_list); if(num_hosts==-1) continue; - machine_data_list=sort_machine_stats(machine_data_list, num_hosts, cmp_cpu); - if(max_display==0){ - display(machine_data_list, num_hosts); - }else{ - display(machine_data_list, max_display); - } + machine_data_list=sort_machine_stats(machine_data_list, num_hosts, sortby_ptr); + display(machine_data_list, &display_config, &title); } exit(0);