| 29 |
|
#include <unistd.h> |
| 30 |
|
#include <stdlib.h> |
| 31 |
|
#include <ukcprog.h> |
| 32 |
+ |
#include <netinet/in.h> |
| 33 |
+ |
#include <netdb.h> |
| 34 |
|
|
| 35 |
|
#include <libxml/xmlmemory.h> |
| 36 |
|
#include <libxml/parser.h> |
| 37 |
|
#include "genmergesort.h" |
| 38 |
|
|
| 39 |
+ |
#ifdef HAVE_NCURSES_H |
| 40 |
+ |
#include <ncurses.h> |
| 41 |
+ |
#else |
| 42 |
+ |
#include <curses.h> |
| 43 |
+ |
#endif |
| 44 |
+ |
|
| 45 |
|
struct host_line_t{ |
| 46 |
|
char *hostname; |
| 47 |
|
int line; |
| 124 |
|
network_data_list_t *network_data_list; |
| 125 |
|
long long network_io_total_tx; |
| 126 |
|
long long network_io_total_rx; |
| 127 |
+ |
long long network_io_total; |
| 128 |
|
|
| 129 |
|
diskio_data_list_t *diskio_data_list; |
| 130 |
|
long long disk_io_total_write; |
| 131 |
|
long long disk_io_total_read; |
| 132 |
+ |
long long disk_io_total; |
| 133 |
|
|
| 134 |
|
/* Maybe in the future */ |
| 135 |
|
/* |
| 142 |
|
|
| 143 |
|
typedef struct machine_data_t machine_data_list_t; |
| 144 |
|
|
| 145 |
+ |
#define SORTBYMAXNAME 128 |
| 146 |
|
typedef struct{ |
| 147 |
|
int cpu_user; |
| 148 |
|
int cpu_idle; |
| 184 |
|
|
| 185 |
|
int disk_total_used; |
| 186 |
|
int disk_all_stats; |
| 187 |
+ |
|
| 188 |
+ |
char sortby[SORTBYMAXNAME]; |
| 189 |
|
}display_config_t; |
| 190 |
|
|
| 191 |
|
GENERIC_MERGE_SORT(static, sort_machine_stats, machine_data_list_t, next) |
| 197 |
|
|
| 198 |
|
MKCMP(cpu_used) |
| 199 |
|
MKCMP(load_1) |
| 200 |
+ |
MKCMP(network_io_total) |
| 201 |
|
MKCMP(network_io_total_tx) |
| 202 |
|
MKCMP(network_io_total_rx) |
| 203 |
+ |
MKCMP(disk_io_total) |
| 204 |
|
MKCMP(disk_io_total_write) |
| 205 |
|
MKCMP(disk_io_total_read) |
| 206 |
|
MKCMP(memory_used_pecent) |
| 207 |
|
MKCMP(swap_used_pecent) |
| 208 |
|
|
| 209 |
+ |
#define CPU_USED "CPU used" |
| 210 |
+ |
#define LOAD "Load (1)" |
| 211 |
+ |
#define NETIORX "total Network RX for all interfaces" |
| 212 |
+ |
#define NETIOTX "total Network TX for all interfaces" |
| 213 |
+ |
#define NETIO "total Network IO for all interfaces (rx+tx)" |
| 214 |
+ |
#define MEM "Memory usage" |
| 215 |
+ |
#define SWAP "Swap usage" |
| 216 |
+ |
#define DISKIOR "DiskIO reads" |
| 217 |
+ |
#define DISKIOW "DiskIO writes" |
| 218 |
+ |
#define DISKIO "Total DiskIO (reads+writes)" |
| 219 |
+ |
|
| 220 |
+ |
|
| 221 |
|
/* |
| 222 |
|
int cmp_cpu(machine_data_list_t *a, machine_data_list_t *b){ |
| 223 |
|
|
| 237 |
|
} |
| 238 |
|
} |
| 239 |
|
*/ |
| 240 |
+ |
|
| 241 |
+ |
#ifndef HAVE_ATOLL |
| 242 |
+ |
long long int atoll (const char *nptr){ |
| 243 |
+ |
return strtoll (nptr, (char **) NULL, 10); |
| 244 |
+ |
} |
| 245 |
+ |
#endif |
| 246 |
+ |
|
| 247 |
+ |
#ifndef HAVE_STRLCPY |
| 248 |
+ |
/* |
| 249 |
+ |
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
| 250 |
+ |
* All rights reserved. |
| 251 |
+ |
* |
| 252 |
+ |
* Redistribution and use in source and binary forms, with or without |
| 253 |
+ |
* modification, are permitted provided that the following conditions |
| 254 |
+ |
* are met: |
| 255 |
+ |
* 1. Redistributions of source code must retain the above copyright |
| 256 |
+ |
* notice, this list of conditions and the following disclaimer. |
| 257 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
| 258 |
+ |
* notice, this list of conditions and the following disclaimer in the |
| 259 |
+ |
* documentation and/or other materials provided with the distribution. |
| 260 |
+ |
* 3. The name of the author may not be used to endorse or promote products |
| 261 |
+ |
* derived from this software without specific prior written permission. |
| 262 |
+ |
* |
| 263 |
+ |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 264 |
+ |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
| 265 |
+ |
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 266 |
+ |
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 267 |
+ |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 268 |
+ |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 269 |
+ |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 270 |
+ |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 271 |
+ |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 272 |
+ |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 273 |
+ |
*/ |
| 274 |
+ |
|
| 275 |
+ |
/* |
| 276 |
+ |
* Copy src to string dst of size siz. At most siz-1 characters |
| 277 |
+ |
* will be copied. Always NUL terminates (unless siz == 0). |
| 278 |
+ |
* Returns strlen(src); if retval >= siz, truncation occurred. |
| 279 |
+ |
*/ |
| 280 |
+ |
size_t |
| 281 |
+ |
strlcpy(dst, src, siz) |
| 282 |
+ |
char *dst; |
| 283 |
+ |
const char *src; |
| 284 |
+ |
size_t siz; |
| 285 |
+ |
{ |
| 286 |
+ |
register char *d = dst; |
| 287 |
+ |
register const char *s = src; |
| 288 |
+ |
register size_t n = siz; |
| 289 |
+ |
|
| 290 |
+ |
/* Copy as many bytes as will fit */ |
| 291 |
+ |
if (n != 0 && --n != 0) { |
| 292 |
+ |
do { |
| 293 |
+ |
if ((*d++ = *s++) == 0) |
| 294 |
+ |
break; |
| 295 |
+ |
} while (--n != 0); |
| 296 |
+ |
} |
| 297 |
+ |
|
| 298 |
+ |
/* Not enough room in dst, add NUL and traverse rest of src */ |
| 299 |
+ |
if (n == 0) { |
| 300 |
+ |
if (siz != 0) |
| 301 |
+ |
*d = '\0'; /* NUL-terminate dst */ |
| 302 |
+ |
while (*s++) |
| 303 |
+ |
; |
| 304 |
+ |
} |
| 305 |
+ |
|
| 306 |
+ |
return(s - src - 1); /* count does not include NUL */ |
| 307 |
+ |
} |
| 308 |
+ |
|
| 309 |
+ |
#endif |
| 310 |
+ |
|
| 311 |
|
|
| 312 |
|
FILE *create_tcp_connection(char *hostname, int port){ |
| 313 |
|
int sock; |
| 656 |
|
machine_data_list->network_io_total_rx+=ndl_ptr->rx; |
| 657 |
|
ndl_ptr=ndl_ptr->next; |
| 658 |
|
} |
| 659 |
+ |
machine_data_list->network_io_total=machine_data_list->network_io_total_rx+machine_data_list->network_io_total_tx; |
| 660 |
|
|
| 661 |
|
didl_ptr=machine_data_list->diskio_data_list; |
| 662 |
|
machine_data_list->disk_io_total_read=0; |
| 666 |
|
machine_data_list->disk_io_total_write+=didl_ptr->write; |
| 667 |
|
didl_ptr=didl_ptr->next; |
| 668 |
|
} |
| 669 |
+ |
machine_data_list->disk_io_total=machine_data_list->disk_io_total_read+machine_data_list->disk_io_total_write; |
| 670 |
|
|
| 671 |
|
xmlFreeDoc(doc); |
| 672 |
|
|
| 677 |
|
|
| 678 |
|
void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int num_lines, int *title){ |
| 679 |
|
int line_num=4; |
| 680 |
+ |
int counter; |
| 681 |
|
int x=1; |
| 682 |
|
|
| 683 |
|
if(*title){ |
| 684 |
< |
printf("\033[2J"); |
| 685 |
< |
// printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); |
| 686 |
< |
// printf("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
| 687 |
< |
printf("\033[1;1H%-11s", "Hostname"); |
| 684 |
> |
clear(); |
| 685 |
> |
move (num_lines-3, 1); |
| 686 |
> |
printw("Sorting by %-64s", display_config->sortby); |
| 687 |
> |
|
| 688 |
> |
move(1,1); |
| 689 |
> |
printw("%-11s", "Hostname"); |
| 690 |
|
x=x+11+1; |
| 691 |
|
if(display_config->cpu_used){ |
| 692 |
< |
printf("\033[1;%dH%5s", x, "CPU"); |
| 693 |
< |
printf("\033[2;%dH%5s", x, "used%"); |
| 692 |
> |
move(1,x); |
| 693 |
> |
printw("%5s", "CPU"); |
| 694 |
> |
move(2,x); |
| 695 |
> |
printw("%5s", "used%"); |
| 696 |
|
x+=6; |
| 697 |
|
} |
| 698 |
|
if(display_config->load_1){ |
| 699 |
< |
printf("\033[1;%dH%5s", x, "Load"); |
| 700 |
< |
printf("\033[2;%dH%5s", x, "(1m)"); |
| 699 |
> |
move(1,x); |
| 700 |
> |
printw("%5s", "Load"); |
| 701 |
> |
move(2,x); |
| 702 |
> |
printw("%5s", "(1m)"); |
| 703 |
|
x+=6; |
| 704 |
|
} |
| 705 |
|
if(display_config->pages_in){ |
| 706 |
< |
printf("\033[1;%dH%5s", x, "Page"); |
| 707 |
< |
printf("\033[2;%dH%5s", x, "ins"); |
| 706 |
> |
move(1,x); |
| 707 |
> |
printw("%5s", "Page"); |
| 708 |
> |
move(2,x); |
| 709 |
> |
printw("%5s", "ins"); |
| 710 |
|
x+=6; |
| 711 |
|
} |
| 712 |
|
if(display_config->pages_out){ |
| 713 |
< |
printf("\033[1;%dH%5s", x, "Page"); |
| 714 |
< |
printf("\033[2;%dH%5s", x, "outs"); |
| 713 |
> |
move(1,x); |
| 714 |
> |
printw("%5s", "Page"); |
| 715 |
> |
move(2,x); |
| 716 |
> |
printw("%5s", "outs"); |
| 717 |
|
x+=6; |
| 718 |
|
} |
| 719 |
|
if(display_config->memory_used_pecent){ |
| 720 |
< |
printf("\033[1;%dH%5s", x, "Mem"); |
| 721 |
< |
printf("\033[2;%dH%5s", x, "used"); |
| 720 |
> |
move(1,x); |
| 721 |
> |
printw("%5s", "Mem"); |
| 722 |
> |
move(2,x); |
| 723 |
> |
printw("%5s", "used"); |
| 724 |
|
x+=6; |
| 725 |
|
} |
| 726 |
|
if(display_config->swap_used_pecent){ |
| 727 |
< |
printf("\033[1;%dH%5s", x, "Swap"); |
| 728 |
< |
printf("\033[2;%dH%5s", x, "used"); |
| 727 |
> |
move(1,x); |
| 728 |
> |
printw("%5s", "Swap"); |
| 729 |
> |
move(2,x); |
| 730 |
> |
printw("%5s", "used"); |
| 731 |
|
x+=6; |
| 732 |
|
} |
| 733 |
|
if(display_config->network_io_total_rx){ |
| 734 |
< |
printf("\033[1;%dH%8s", x, "Net"); |
| 735 |
< |
printf("\033[2;%dH%8s", x, "rx"); |
| 734 |
> |
move(1,x); |
| 735 |
> |
printw("%8s", "Net"); |
| 736 |
> |
move(2,x); |
| 737 |
> |
printw("%8s", "rx"); |
| 738 |
|
x+=9; |
| 739 |
|
} |
| 740 |
|
if(display_config->network_io_total_tx){ |
| 741 |
< |
printf("\033[1;%dH%8s", x, "Net"); |
| 742 |
< |
printf("\033[2;%dH%8s", x, "tx"); |
| 741 |
> |
move(1,x); |
| 742 |
> |
printw("%8s", "Net"); |
| 743 |
> |
move(2,x); |
| 744 |
> |
printw("%8s", "tx"); |
| 745 |
|
x+=9; |
| 746 |
|
} |
| 747 |
|
if(display_config->disk_io_total_read){ |
| 748 |
< |
printf("\033[1;%dH%9s", x, "Disk"); |
| 749 |
< |
printf("\033[2;%dH%9s", x, "read"); |
| 748 |
> |
move(1,x); |
| 749 |
> |
printw("%9s", "Disk"); |
| 750 |
> |
move(2,x); |
| 751 |
> |
printw("%9s", "read"); |
| 752 |
|
x+=10; |
| 753 |
|
} |
| 754 |
|
if(display_config->disk_io_total_read){ |
| 755 |
< |
printf("\033[1;%dH%9s", x, "Disk"); |
| 756 |
< |
printf("\033[2;%dH%9s", x, "write"); |
| 755 |
> |
move(1,x); |
| 756 |
> |
printw("%9s", "Disk"); |
| 757 |
> |
move(2,x); |
| 758 |
> |
printw("%9s", "write"); |
| 759 |
|
x+=10; |
| 760 |
|
} |
| 761 |
|
|
| 762 |
|
*title=0; |
| 763 |
|
} |
| 764 |
|
|
| 765 |
< |
for(;num_lines;num_lines--){ |
| 765 |
> |
/* Counter starts at 8, for padding (eg, headers, borders etc) */ |
| 766 |
> |
for(counter=8;counter<num_lines;counter++){ |
| 767 |
|
if(machine_data_list==NULL) break; |
| 768 |
+ |
move(line_num++, 1); |
| 769 |
+ |
printw("%-11s", machine_data_list->sysname); |
| 770 |
|
|
| 771 |
< |
printf("\033[%d;%dH%-11s", line_num++, 1, machine_data_list->sysname); |
| 771 |
> |
if(display_config->cpu_used) printw(" %5.1f", machine_data_list->cpu_used); |
| 772 |
> |
if(display_config->load_1) printw(" %5.1f", machine_data_list->load_1); |
| 773 |
> |
if(display_config->pages_in) printw(" %5d", machine_data_list->pages_in); |
| 774 |
> |
if(display_config->pages_out) printw(" %5d", machine_data_list->pages_out); |
| 775 |
> |
if(display_config->memory_used_pecent) printw(" %5.1f", machine_data_list->memory_used_pecent); |
| 776 |
> |
if(display_config->swap_used_pecent) printw(" %5.1f", machine_data_list->swap_used_pecent); |
| 777 |
> |
if(display_config->network_io_total_rx) printw(" %8lld", machine_data_list->network_io_total_rx); |
| 778 |
> |
if(display_config->network_io_total_tx) printw(" %8lld", machine_data_list->network_io_total_tx); |
| 779 |
> |
if(display_config->disk_io_total_read) printw(" %9lld", machine_data_list->disk_io_total_read); |
| 780 |
> |
if(display_config->disk_io_total_write) printw(" %9lld", machine_data_list->disk_io_total_write); |
| 781 |
|
|
| 647 |
– |
if(display_config->cpu_used) printf(" %5.1f", machine_data_list->cpu_used); |
| 648 |
– |
if(display_config->load_1) printf(" %5.1f", machine_data_list->load_1); |
| 649 |
– |
if(display_config->pages_in) printf(" %5d", machine_data_list->pages_in); |
| 650 |
– |
if(display_config->pages_out) printf(" %5d", machine_data_list->pages_out); |
| 651 |
– |
if(display_config->memory_used_pecent) printf(" %5.1f", machine_data_list->memory_used_pecent); |
| 652 |
– |
if(display_config->swap_used_pecent) printf(" %5.1f", machine_data_list->swap_used_pecent); |
| 653 |
– |
if(display_config->network_io_total_rx) printf(" %8lld", machine_data_list->network_io_total_rx); |
| 654 |
– |
if(display_config->network_io_total_tx) printf(" %8lld", machine_data_list->network_io_total_tx); |
| 655 |
– |
if(display_config->disk_io_total_read) printf(" %9lld", machine_data_list->disk_io_total_read); |
| 656 |
– |
if(display_config->disk_io_total_write) printf(" %9lld", machine_data_list->disk_io_total_write); |
| 657 |
– |
|
| 782 |
|
machine_data_list=machine_data_list->next; |
| 783 |
|
} |
| 784 |
|
|
| 785 |
|
|
| 786 |
< |
fflush(stdout); |
| 786 |
> |
refresh(); |
| 787 |
|
|
| 788 |
|
} |
| 789 |
|
|
| 790 |
|
int main(int argc, char **argv){ |
| 791 |
+ |
WINDOW *window; |
| 792 |
+ |
fd_set infds; |
| 793 |
+ |
int maxx, maxy; |
| 794 |
+ |
|
| 795 |
|
FILE *control; |
| 796 |
|
FILE *data; |
| 797 |
|
|
| 806 |
|
|
| 807 |
|
int num_hosts; |
| 808 |
|
int max_display=0; |
| 809 |
< |
int title; |
| 809 |
> |
int title=1; |
| 810 |
|
|
| 811 |
|
int cmdopt; |
| 812 |
|
extern int optind; |
| 813 |
|
extern char *optarg; |
| 686 |
– |
sortby_ptr=NULL; |
| 814 |
|
|
| 815 |
|
display_config_t display_config; |
| 816 |
+ |
char ch; |
| 817 |
|
|
| 818 |
+ |
int data_fileno, stdin_fileno, biggest_fileno; |
| 819 |
+ |
|
| 820 |
+ |
sortby_ptr=NULL; |
| 821 |
+ |
|
| 822 |
|
/* What to display defaults */ |
| 823 |
|
display_config.cpu_user=0; |
| 824 |
|
display_config.cpu_idle=0; |
| 852 |
|
|
| 853 |
|
display_config.network_io_total_tx=1; |
| 854 |
|
display_config.network_io_total_rx=1; |
| 855 |
< |
display_config.network_all_stats=1; |
| 855 |
> |
display_config.network_all_stats=0; |
| 856 |
|
|
| 857 |
|
display_config.disk_io_total_write=1; |
| 858 |
|
display_config.disk_io_total_read=1; |
| 861 |
|
display_config.disk_total_used=0; |
| 862 |
|
display_config.disk_all_stats=0; |
| 863 |
|
|
| 732 |
– |
|
| 864 |
|
while((cmdopt=getopt(argc, argv, "d:s:")) != -1){ |
| 865 |
|
switch(cmdopt){ |
| 866 |
|
case 'd': |
| 869 |
|
case 's': |
| 870 |
|
if(!strcmp(optarg, "cpu")){ |
| 871 |
|
sortby_ptr=cmp_cpu_used; |
| 872 |
+ |
strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); |
| 873 |
|
} |
| 874 |
|
if(!strcmp(optarg, "load")){ |
| 875 |
|
sortby_ptr=cmp_load_1; |
| 876 |
+ |
strlcpy(display_config.sortby, LOAD, SORTBYMAXNAME); |
| 877 |
|
} |
| 878 |
|
if(!strcmp(optarg, "mem")){ |
| 879 |
|
sortby_ptr=cmp_memory_used_pecent; |
| 880 |
+ |
strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); |
| 881 |
|
} |
| 882 |
+ |
if(!strcmp(optarg, "swap")){ |
| 883 |
+ |
sortby_ptr=cmp_swap_used_pecent; |
| 884 |
+ |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
| 885 |
+ |
} |
| 886 |
|
if(sortby_ptr==NULL){ |
| 887 |
|
errf("Invalid sort type"); |
| 888 |
|
exit(1); |
| 891 |
|
} |
| 892 |
|
} |
| 893 |
|
|
| 894 |
< |
if(sortby_ptr==NULL) sortby_ptr=cmp_cpu_used; |
| 894 |
> |
if(sortby_ptr==NULL){ |
| 895 |
> |
sortby_ptr=cmp_cpu_used; |
| 896 |
> |
strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME); |
| 897 |
> |
} |
| 898 |
|
|
| 899 |
|
if(argc<(optind+2)){ |
| 900 |
|
printf("Usage is %s <-d lines> hostname port <machine list>\n", argv[0]); |
| 957 |
|
printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); |
| 958 |
|
printf("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
| 959 |
|
*/ |
| 960 |
< |
fflush(stdout); |
| 960 |
> |
|
| 961 |
> |
initscr(); |
| 962 |
> |
nonl(); |
| 963 |
> |
cbreak(); |
| 964 |
> |
echo(); |
| 965 |
> |
window=newwin(0, 0, 0, 0); |
| 966 |
> |
getmaxyx(window, maxy, maxx); |
| 967 |
> |
|
| 968 |
> |
stdin_fileno=fileno(stdin); |
| 969 |
> |
data_fileno=fileno(data); |
| 970 |
> |
biggest_fileno=(data_fileno>stdin_fileno) ? (data_fileno+1) : (stdin_fileno+1); |
| 971 |
> |
|
| 972 |
|
for(;;){ |
| 973 |
< |
response=fpgetline(data); |
| 974 |
< |
if (response==NULL){ |
| 975 |
< |
errf("Failed to read data (%m)"); |
| 976 |
< |
exit(1); |
| 973 |
> |
FD_ZERO(&infds); |
| 974 |
> |
FD_SET(stdin_fileno, &infds); |
| 975 |
> |
FD_SET(data_fileno, &infds); |
| 976 |
> |
select(biggest_fileno, &infds, NULL, NULL, NULL); |
| 977 |
> |
|
| 978 |
> |
if(FD_ISSET(stdin_fileno, &infds)){ |
| 979 |
> |
|
| 980 |
> |
ch=getc(stdin); |
| 981 |
> |
switch(ch){ |
| 982 |
> |
|
| 983 |
> |
/* Quit */ |
| 984 |
> |
case 'Q': |
| 985 |
> |
case 'q': |
| 986 |
> |
endwin(); |
| 987 |
> |
exit(0); |
| 988 |
> |
break; |
| 989 |
> |
|
| 990 |
> |
/* Sort by */ |
| 991 |
> |
case 'C': |
| 992 |
> |
sortby_ptr=cmp_cpu_used; |
| 993 |
> |
strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); |
| 994 |
> |
break; |
| 995 |
> |
|
| 996 |
> |
case 'M': |
| 997 |
> |
sortby_ptr=cmp_memory_used_pecent; |
| 998 |
> |
strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); |
| 999 |
> |
break; |
| 1000 |
> |
|
| 1001 |
> |
case 'L': |
| 1002 |
> |
sortby_ptr=cmp_load_1; |
| 1003 |
> |
strlcpy(display_config.sortby, LOAD, SORTBYMAXNAME); |
| 1004 |
> |
break; |
| 1005 |
> |
|
| 1006 |
> |
case 'S': |
| 1007 |
> |
sortby_ptr=cmp_swap_used_pecent; |
| 1008 |
> |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
| 1009 |
> |
break; |
| 1010 |
> |
|
| 1011 |
> |
case 'N': |
| 1012 |
> |
if(sortby_ptr==cmp_network_io_total){ |
| 1013 |
> |
strlcpy(display_config.sortby, NETIORX, SORTBYMAXNAME); |
| 1014 |
> |
sortby_ptr=cmp_network_io_total_rx; |
| 1015 |
> |
}else if(sortby_ptr==cmp_network_io_total_rx){ |
| 1016 |
> |
strlcpy(display_config.sortby, NETIOTX, SORTBYMAXNAME); |
| 1017 |
> |
sortby_ptr=cmp_network_io_total_tx; |
| 1018 |
> |
}else{ |
| 1019 |
> |
strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME); |
| 1020 |
> |
sortby_ptr=cmp_network_io_total; |
| 1021 |
> |
} |
| 1022 |
> |
break; |
| 1023 |
> |
case 'D': |
| 1024 |
> |
if(sortby_ptr==cmp_disk_io_total){ |
| 1025 |
> |
strlcpy(display_config.sortby, DISKIOR, SORTBYMAXNAME); |
| 1026 |
> |
sortby_ptr=cmp_disk_io_total_read; |
| 1027 |
> |
}else if(sortby_ptr==cmp_disk_io_total_read){ |
| 1028 |
> |
strlcpy(display_config.sortby, DISKIOW, SORTBYMAXNAME); |
| 1029 |
> |
sortby_ptr=cmp_disk_io_total_write; |
| 1030 |
> |
}else{ |
| 1031 |
> |
strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME); |
| 1032 |
> |
sortby_ptr=cmp_disk_io_total; |
| 1033 |
> |
} |
| 1034 |
> |
break; |
| 1035 |
> |
|
| 1036 |
> |
/* Display */ |
| 1037 |
> |
|
| 1038 |
> |
case 'd': |
| 1039 |
> |
if(display_config.disk_io_total_read){ |
| 1040 |
> |
display_config.disk_io_total_read=0; |
| 1041 |
> |
display_config.disk_io_total_write=0; |
| 1042 |
> |
}else{ |
| 1043 |
> |
display_config.disk_io_total_read=1; |
| 1044 |
> |
display_config.disk_io_total_write=1; |
| 1045 |
> |
} |
| 1046 |
> |
break; |
| 1047 |
> |
case 'n': |
| 1048 |
> |
if(display_config.network_io_total_rx){ |
| 1049 |
> |
display_config.network_io_total_rx=0; |
| 1050 |
> |
display_config.network_io_total_tx=0; |
| 1051 |
> |
}else{ |
| 1052 |
> |
display_config.network_io_total_rx=1; |
| 1053 |
> |
display_config.network_io_total_tx=1; |
| 1054 |
> |
} |
| 1055 |
> |
break; |
| 1056 |
> |
case 'm': |
| 1057 |
> |
if(display_config.memory_used_pecent){ |
| 1058 |
> |
display_config.memory_used_pecent=0; |
| 1059 |
> |
}else{ |
| 1060 |
> |
display_config.memory_used_pecent=1; |
| 1061 |
> |
} |
| 1062 |
> |
break; |
| 1063 |
> |
|
| 1064 |
> |
case 's': |
| 1065 |
> |
if(display_config.swap_used_pecent){ |
| 1066 |
> |
display_config.swap_used_pecent=0; |
| 1067 |
> |
}else{ |
| 1068 |
> |
display_config.swap_used_pecent=1; |
| 1069 |
> |
} |
| 1070 |
> |
break; |
| 1071 |
> |
case 'l': |
| 1072 |
> |
if(display_config.load_1){ |
| 1073 |
> |
display_config.load_1=0; |
| 1074 |
> |
}else{ |
| 1075 |
> |
display_config.load_1=1; |
| 1076 |
> |
} |
| 1077 |
> |
break; |
| 1078 |
> |
case 'p': |
| 1079 |
> |
if(display_config.pages_in){ |
| 1080 |
> |
display_config.pages_in=0; |
| 1081 |
> |
display_config.pages_out=0; |
| 1082 |
> |
}else{ |
| 1083 |
> |
display_config.pages_in=1; |
| 1084 |
> |
display_config.pages_out=1; |
| 1085 |
> |
} |
| 1086 |
> |
break; |
| 1087 |
> |
case 'c': |
| 1088 |
> |
if(display_config.cpu_used){ |
| 1089 |
> |
display_config.cpu_used=0; |
| 1090 |
> |
}else{ |
| 1091 |
> |
display_config.cpu_used=1; |
| 1092 |
> |
} |
| 1093 |
> |
break; |
| 1094 |
> |
|
| 1095 |
> |
default: |
| 1096 |
> |
/* Invalid key.. Ignore.. Set Title to -1, as the |
| 1097 |
> |
* title++ will then make that "0" (false) so a |
| 1098 |
> |
* screen redraw will not happen */ |
| 1099 |
> |
title=-1; |
| 1100 |
> |
break; |
| 1101 |
> |
} |
| 1102 |
> |
|
| 1103 |
> |
/* Increment title so it becomes true (and making the screen update */ |
| 1104 |
> |
title++; |
| 1105 |
> |
|
| 1106 |
|
} |
| 1107 |
+ |
if(FD_ISSET(data_fileno, &infds)){ |
| 1108 |
+ |
response=fpgetline(data); |
| 1109 |
+ |
if (response==NULL){ |
| 1110 |
+ |
errf("Failed to read data (%m)"); |
| 1111 |
+ |
exit(1); |
| 1112 |
+ |
} |
| 1113 |
+ |
} |
| 1114 |
|
|
| 1115 |
+ |
|
| 1116 |
|
num_hosts=parse_xml(response, &machine_data_list); |
| 1117 |
|
if(num_hosts==-1) continue; |
| 1118 |
|
machine_data_list=sort_machine_stats(machine_data_list, num_hosts, sortby_ptr); |
| 1119 |
|
if(max_display==0){ |
| 1120 |
< |
display(machine_data_list, &display_config, num_hosts, &title); |
| 1120 |
> |
display(machine_data_list, &display_config, maxy, &title); |
| 1121 |
|
}else{ |
| 1122 |
|
display(machine_data_list, &display_config, max_display, &title); |
| 1123 |
|
} |