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