33 |
|
#include <libxml/xmlmemory.h> |
34 |
|
#include <libxml/parser.h> |
35 |
|
#include "genmergesort.h" |
36 |
+ |
|
37 |
+ |
#ifdef HAVE_NCURSES_H |
38 |
+ |
#include <ncurses.h> |
39 |
+ |
#else |
40 |
|
#include <curses.h> |
41 |
+ |
#endif |
42 |
|
|
43 |
|
struct host_line_t{ |
44 |
|
char *hostname; |
122 |
|
network_data_list_t *network_data_list; |
123 |
|
long long network_io_total_tx; |
124 |
|
long long network_io_total_rx; |
125 |
+ |
long long network_io_total; |
126 |
|
|
127 |
|
diskio_data_list_t *diskio_data_list; |
128 |
|
long long disk_io_total_write; |
129 |
|
long long disk_io_total_read; |
130 |
+ |
long long disk_io_total; |
131 |
|
|
132 |
|
/* Maybe in the future */ |
133 |
|
/* |
140 |
|
|
141 |
|
typedef struct machine_data_t machine_data_list_t; |
142 |
|
|
143 |
+ |
#define SORTBYMAXNAME 128 |
144 |
|
typedef struct{ |
145 |
|
int cpu_user; |
146 |
|
int cpu_idle; |
182 |
|
|
183 |
|
int disk_total_used; |
184 |
|
int disk_all_stats; |
185 |
+ |
|
186 |
+ |
char sortby[SORTBYMAXNAME]; |
187 |
|
}display_config_t; |
188 |
|
|
189 |
|
GENERIC_MERGE_SORT(static, sort_machine_stats, machine_data_list_t, next) |
195 |
|
|
196 |
|
MKCMP(cpu_used) |
197 |
|
MKCMP(load_1) |
198 |
+ |
MKCMP(network_io_total) |
199 |
|
MKCMP(network_io_total_tx) |
200 |
|
MKCMP(network_io_total_rx) |
201 |
+ |
MKCMP(disk_io_total) |
202 |
|
MKCMP(disk_io_total_write) |
203 |
|
MKCMP(disk_io_total_read) |
204 |
|
MKCMP(memory_used_pecent) |
205 |
|
MKCMP(swap_used_pecent) |
206 |
|
|
207 |
+ |
#define CPU_USED "CPU used" |
208 |
+ |
#define LOAD "Load (1)" |
209 |
+ |
#define NETIORX "total Network RX for all interfaces" |
210 |
+ |
#define NETIOTX "total Network TX for all interfaces" |
211 |
+ |
#define NETIO "total Network IO for all interfaces (rx+tx)" |
212 |
+ |
#define MEM "Memory usage" |
213 |
+ |
#define SWAP "Swap usage" |
214 |
+ |
#define DISKIOR "DiskIO reads" |
215 |
+ |
#define DISKIOW "DiskIO writes" |
216 |
+ |
#define DISKIO "Total DiskIO (reads+writes)" |
217 |
+ |
|
218 |
+ |
|
219 |
|
/* |
220 |
|
int cmp_cpu(machine_data_list_t *a, machine_data_list_t *b){ |
221 |
|
|
583 |
|
machine_data_list->network_io_total_rx+=ndl_ptr->rx; |
584 |
|
ndl_ptr=ndl_ptr->next; |
585 |
|
} |
586 |
+ |
machine_data_list->network_io_total=machine_data_list->network_io_total_rx+machine_data_list->network_io_total_tx; |
587 |
|
|
588 |
|
didl_ptr=machine_data_list->diskio_data_list; |
589 |
|
machine_data_list->disk_io_total_read=0; |
593 |
|
machine_data_list->disk_io_total_write+=didl_ptr->write; |
594 |
|
didl_ptr=didl_ptr->next; |
595 |
|
} |
596 |
+ |
machine_data_list->disk_io_total=machine_data_list->disk_io_total_read+machine_data_list->disk_io_total_write; |
597 |
|
|
598 |
|
xmlFreeDoc(doc); |
599 |
|
|
604 |
|
|
605 |
|
void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int num_lines, int *title){ |
606 |
|
int line_num=4; |
607 |
+ |
int counter; |
608 |
|
int x=1; |
609 |
|
|
610 |
|
if(*title){ |
611 |
< |
// printf("\033[2J"); |
612 |
< |
// printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); |
613 |
< |
// printw("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
611 |
> |
clear(); |
612 |
> |
move (num_lines-3, 1); |
613 |
> |
printw("Sorting by %-64s", display_config->sortby); |
614 |
> |
|
615 |
|
move(1,1); |
616 |
|
printw("%-11s", "Hostname"); |
617 |
|
x=x+11+1; |
689 |
|
*title=0; |
690 |
|
} |
691 |
|
|
692 |
< |
for(;num_lines;num_lines--){ |
692 |
> |
/* Counter starts at 8, for padding (eg, headers, borders etc) */ |
693 |
> |
for(counter=8;counter<num_lines;counter++){ |
694 |
|
if(machine_data_list==NULL) break; |
695 |
|
move(line_num++, 1); |
696 |
|
printw("%-11s", machine_data_list->sysname); |
717 |
|
int main(int argc, char **argv){ |
718 |
|
WINDOW *window; |
719 |
|
fd_set infds; |
720 |
+ |
int maxx, maxy; |
721 |
|
|
722 |
|
FILE *control; |
723 |
|
FILE *data; |
733 |
|
|
734 |
|
int num_hosts; |
735 |
|
int max_display=0; |
736 |
< |
int title; |
736 |
> |
int title=1; |
737 |
|
|
738 |
|
int cmdopt; |
739 |
|
extern int optind; |
779 |
|
|
780 |
|
display_config.network_io_total_tx=1; |
781 |
|
display_config.network_io_total_rx=1; |
782 |
< |
display_config.network_all_stats=1; |
782 |
> |
display_config.network_all_stats=0; |
783 |
|
|
784 |
< |
display_config.disk_io_total_write=0; |
785 |
< |
display_config.disk_io_total_read=0; |
784 |
> |
display_config.disk_io_total_write=1; |
785 |
> |
display_config.disk_io_total_read=1; |
786 |
|
display_config.disk_io_all_stats=0; |
787 |
|
|
788 |
|
display_config.disk_total_used=0; |
796 |
|
case 's': |
797 |
|
if(!strcmp(optarg, "cpu")){ |
798 |
|
sortby_ptr=cmp_cpu_used; |
799 |
+ |
strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); |
800 |
|
} |
801 |
|
if(!strcmp(optarg, "load")){ |
802 |
|
sortby_ptr=cmp_load_1; |
803 |
+ |
strlcpy(display_config.sortby, LOAD, SORTBYMAXNAME); |
804 |
|
} |
805 |
|
if(!strcmp(optarg, "mem")){ |
806 |
|
sortby_ptr=cmp_memory_used_pecent; |
807 |
+ |
strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); |
808 |
|
} |
809 |
+ |
if(!strcmp(optarg, "swap")){ |
810 |
+ |
sortby_ptr=cmp_swap_used_pecent; |
811 |
+ |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
812 |
+ |
} |
813 |
|
if(sortby_ptr==NULL){ |
814 |
|
errf("Invalid sort type"); |
815 |
|
exit(1); |
818 |
|
} |
819 |
|
} |
820 |
|
|
821 |
< |
if(sortby_ptr==NULL) sortby_ptr=cmp_cpu_used; |
821 |
> |
if(sortby_ptr==NULL){ |
822 |
> |
sortby_ptr=cmp_cpu_used; |
823 |
> |
strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME); |
824 |
> |
} |
825 |
|
|
826 |
|
if(argc<(optind+2)){ |
827 |
|
printf("Usage is %s <-d lines> hostname port <machine list>\n", argv[0]); |
890 |
|
cbreak(); |
891 |
|
echo(); |
892 |
|
window=newwin(0, 0, 0, 0); |
893 |
+ |
getmaxyx(window, maxy, maxx); |
894 |
|
|
895 |
|
stdin_fileno=fileno(stdin); |
896 |
|
data_fileno=fileno(data); |
897 |
|
biggest_fileno=(data_fileno>stdin_fileno) ? (data_fileno+1) : (stdin_fileno+1); |
898 |
< |
|
898 |
> |
|
899 |
|
for(;;){ |
900 |
|
FD_ZERO(&infds); |
901 |
|
FD_SET(stdin_fileno, &infds); |
905 |
|
if(FD_ISSET(stdin_fileno, &infds)){ |
906 |
|
|
907 |
|
ch=getc(stdin); |
908 |
+ |
switch(ch){ |
909 |
|
|
910 |
< |
if(ch=='q'){ |
911 |
< |
endwin(); |
912 |
< |
exit(0); |
910 |
> |
/* Quit */ |
911 |
> |
case 'Q': |
912 |
> |
case 'q': |
913 |
> |
endwin(); |
914 |
> |
exit(0); |
915 |
> |
break; |
916 |
> |
|
917 |
> |
/* Sort by */ |
918 |
> |
case 'C': |
919 |
> |
sortby_ptr=cmp_cpu_used; |
920 |
> |
strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); |
921 |
> |
break; |
922 |
> |
|
923 |
> |
case 'M': |
924 |
> |
sortby_ptr=cmp_memory_used_pecent; |
925 |
> |
strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); |
926 |
> |
break; |
927 |
> |
|
928 |
> |
case 'L': |
929 |
> |
sortby_ptr=cmp_load_1; |
930 |
> |
strlcpy(display_config.sortby, LOAD, SORTBYMAXNAME); |
931 |
> |
break; |
932 |
> |
|
933 |
> |
case 'S': |
934 |
> |
sortby_ptr=cmp_swap_used_pecent; |
935 |
> |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
936 |
> |
break; |
937 |
> |
|
938 |
> |
case 'N': |
939 |
> |
if(sortby_ptr==cmp_network_io_total){ |
940 |
> |
strlcpy(display_config.sortby, NETIORX, SORTBYMAXNAME); |
941 |
> |
sortby_ptr=cmp_network_io_total_rx; |
942 |
> |
}else if(sortby_ptr==cmp_network_io_total_rx){ |
943 |
> |
strlcpy(display_config.sortby, NETIOTX, SORTBYMAXNAME); |
944 |
> |
sortby_ptr=cmp_network_io_total_tx; |
945 |
> |
}else{ |
946 |
> |
strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME); |
947 |
> |
sortby_ptr=cmp_network_io_total; |
948 |
> |
} |
949 |
> |
break; |
950 |
> |
case 'D': |
951 |
> |
if(sortby_ptr==cmp_disk_io_total){ |
952 |
> |
strlcpy(display_config.sortby, DISKIOR, SORTBYMAXNAME); |
953 |
> |
sortby_ptr=cmp_disk_io_total_read; |
954 |
> |
}else if(sortby_ptr==cmp_disk_io_total_read){ |
955 |
> |
strlcpy(display_config.sortby, DISKIOW, SORTBYMAXNAME); |
956 |
> |
sortby_ptr=cmp_disk_io_total_write; |
957 |
> |
}else{ |
958 |
> |
strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME); |
959 |
> |
sortby_ptr=cmp_disk_io_total; |
960 |
> |
} |
961 |
> |
break; |
962 |
> |
|
963 |
> |
/* Display */ |
964 |
> |
|
965 |
> |
case 'd': |
966 |
> |
if(display_config.disk_io_total_read){ |
967 |
> |
display_config.disk_io_total_read=0; |
968 |
> |
display_config.disk_io_total_write=0; |
969 |
> |
}else{ |
970 |
> |
display_config.disk_io_total_read=1; |
971 |
> |
display_config.disk_io_total_write=1; |
972 |
> |
} |
973 |
> |
break; |
974 |
> |
case 'n': |
975 |
> |
if(display_config.network_io_total_rx){ |
976 |
> |
display_config.network_io_total_rx=0; |
977 |
> |
display_config.network_io_total_tx=0; |
978 |
> |
}else{ |
979 |
> |
display_config.network_io_total_rx=1; |
980 |
> |
display_config.network_io_total_tx=1; |
981 |
> |
} |
982 |
> |
break; |
983 |
> |
case 'm': |
984 |
> |
if(display_config.memory_used_pecent){ |
985 |
> |
display_config.memory_used_pecent=0; |
986 |
> |
}else{ |
987 |
> |
display_config.memory_used_pecent=1; |
988 |
> |
} |
989 |
> |
break; |
990 |
> |
|
991 |
> |
case 's': |
992 |
> |
if(display_config.swap_used_pecent){ |
993 |
> |
display_config.swap_used_pecent=0; |
994 |
> |
}else{ |
995 |
> |
display_config.swap_used_pecent=1; |
996 |
> |
} |
997 |
> |
break; |
998 |
> |
case 'l': |
999 |
> |
if(display_config.load_1){ |
1000 |
> |
display_config.load_1=0; |
1001 |
> |
}else{ |
1002 |
> |
display_config.load_1=1; |
1003 |
> |
} |
1004 |
> |
break; |
1005 |
> |
case 'p': |
1006 |
> |
if(display_config.pages_in){ |
1007 |
> |
display_config.pages_in=0; |
1008 |
> |
display_config.pages_out=0; |
1009 |
> |
}else{ |
1010 |
> |
display_config.pages_in=1; |
1011 |
> |
display_config.pages_out=1; |
1012 |
> |
} |
1013 |
> |
break; |
1014 |
> |
case 'c': |
1015 |
> |
if(display_config.cpu_used){ |
1016 |
> |
display_config.cpu_used=0; |
1017 |
> |
}else{ |
1018 |
> |
display_config.cpu_used=1; |
1019 |
> |
} |
1020 |
> |
break; |
1021 |
> |
|
1022 |
> |
default: |
1023 |
> |
/* Invalid key.. Ignore.. Set Title to -1, as the |
1024 |
> |
* title++ will then make that "0" (false) so a |
1025 |
> |
* screen redraw will not happen */ |
1026 |
> |
title=-1; |
1027 |
> |
break; |
1028 |
|
} |
1029 |
+ |
|
1030 |
+ |
/* Increment title so it becomes true (and making the screen update */ |
1031 |
+ |
title++; |
1032 |
+ |
|
1033 |
|
} |
1034 |
|
if(FD_ISSET(data_fileno, &infds)){ |
1035 |
|
response=fpgetline(data); |
1044 |
|
if(num_hosts==-1) continue; |
1045 |
|
machine_data_list=sort_machine_stats(machine_data_list, num_hosts, sortby_ptr); |
1046 |
|
if(max_display==0){ |
1047 |
< |
display(machine_data_list, &display_config, num_hosts, &title); |
1047 |
> |
display(machine_data_list, &display_config, maxy, &title); |
1048 |
|
}else{ |
1049 |
|
display(machine_data_list, &display_config, max_display, &title); |
1050 |
|
} |