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