32 |
|
#include <netinet/in.h> |
33 |
|
#include <netdb.h> |
34 |
|
#include <sys/termios.h> |
35 |
+ |
#include <signal.h> |
36 |
+ |
#include <errno.h> |
37 |
|
|
38 |
|
#include <libxml/xmlmemory.h> |
39 |
|
#include <libxml/parser.h> |
176 |
|
int pages_in; |
177 |
|
int pages_out; |
178 |
|
|
179 |
< |
int processes_total; |
178 |
< |
int processes_sleeping; |
179 |
< |
int processes_cpu; |
180 |
< |
int processes_zombie; |
181 |
< |
int processes_stopped; |
179 |
> |
int processes; |
180 |
|
|
181 |
|
int network_io_total_tx; |
182 |
|
int network_io_total_rx; |
221 |
|
#define DISKIOW "DiskIO writes" |
222 |
|
#define DISKIO "Total DiskIO (reads+writes)" |
223 |
|
|
224 |
+ |
int sig_winch=0; |
225 |
|
|
227 |
– |
/* |
228 |
– |
int cmp_cpu(machine_data_list_t *a, machine_data_list_t *b){ |
229 |
– |
|
230 |
– |
if(a->cpu_used == b->cpu_used){ |
231 |
– |
if(a->load_1 == b->load_1) return 0; |
232 |
– |
if(a->load_1 > b->load_1){ |
233 |
– |
return -1; |
234 |
– |
}else{ |
235 |
– |
return 1; |
236 |
– |
} |
237 |
– |
} |
238 |
– |
|
239 |
– |
if((a->cpu_used) > (b->cpu_used)){ |
240 |
– |
return -1; |
241 |
– |
}else{ |
242 |
– |
return 1; |
243 |
– |
} |
244 |
– |
} |
245 |
– |
*/ |
246 |
– |
|
226 |
|
#ifndef HAVE_ATOLL |
227 |
|
long long int atoll (const char *nptr){ |
228 |
|
return strtoll (nptr, (char **) NULL, 10); |
697 |
|
printw("%5s", "(1m)"); |
698 |
|
x+=6; |
699 |
|
} |
700 |
+ |
|
701 |
|
if(display_config->pages_in && (display_config->maxx > x+6)){ |
702 |
|
move(1,x); |
703 |
|
printw("%5s", "Page"); |
705 |
|
printw("%5s", "ins"); |
706 |
|
x+=6; |
707 |
|
} |
708 |
+ |
|
709 |
|
if(display_config->pages_out && (display_config->maxx > x+6)){ |
710 |
|
move(1,x); |
711 |
|
printw("%5s", "Page"); |
713 |
|
printw("%5s", "outs"); |
714 |
|
x+=6; |
715 |
|
} |
716 |
+ |
|
717 |
|
if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ |
718 |
|
move(1,x); |
719 |
|
printw("%5s", "Mem"); |
721 |
|
printw("%5s", "used"); |
722 |
|
x+=6; |
723 |
|
} |
724 |
+ |
|
725 |
|
if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ |
726 |
|
move(1,x); |
727 |
|
printw("%5s", "Swap"); |
729 |
|
printw("%5s", "used"); |
730 |
|
x+=6; |
731 |
|
} |
732 |
+ |
|
733 |
|
if(display_config->network_io_total_rx){ |
734 |
|
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
735 |
|
move(1,x); |
738 |
|
printw("%8s", "rx"); |
739 |
|
x+=9; |
740 |
|
} |
741 |
+ |
|
742 |
|
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
743 |
|
move(1,x); |
744 |
|
printw("%5s", "Net"); |
746 |
|
printw("%5s", "rx"); |
747 |
|
x+=6; |
748 |
|
} |
749 |
< |
if(display_config->units=='m' && (display_config->maxx > x+5)){ |
749 |
> |
|
750 |
> |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
751 |
|
move(1,x); |
752 |
< |
printw("%4s", "Net"); |
752 |
> |
printw("%5s", "Net"); |
753 |
|
move(2,x); |
754 |
< |
printw("%4s", "rx"); |
755 |
< |
x+=5; |
754 |
> |
printw("%5s", "rx"); |
755 |
> |
x+=6; |
756 |
|
} |
757 |
+ |
|
758 |
|
} |
759 |
+ |
|
760 |
|
if(display_config->network_io_total_tx){ |
761 |
|
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
762 |
|
move(1,x); |
765 |
|
printw("%8s", "tx"); |
766 |
|
x+=9; |
767 |
|
} |
768 |
+ |
|
769 |
|
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
770 |
|
move(1,x); |
771 |
|
printw("%5s", "Net"); |
773 |
|
printw("%5s", "tx"); |
774 |
|
x+=6; |
775 |
|
} |
776 |
< |
if(display_config->units=='m' && (display_config->maxx > x+5)){ |
776 |
> |
|
777 |
> |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
778 |
|
move(1,x); |
779 |
< |
printw("%4s", "Net"); |
779 |
> |
printw("%5s", "Net"); |
780 |
|
move(2,x); |
781 |
< |
printw("%4s", "tx"); |
782 |
< |
x+=5; |
781 |
> |
printw("%5s", "tx"); |
782 |
> |
x+=6; |
783 |
|
} |
784 |
+ |
|
785 |
|
} |
786 |
|
|
787 |
|
if(display_config->disk_io_total_read){ |
792 |
|
printw("%9s", "read"); |
793 |
|
x+=10; |
794 |
|
} |
795 |
+ |
|
796 |
|
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
797 |
|
move(1,x); |
798 |
|
printw("%6s", "Disk"); |
800 |
|
printw("%6s", "read"); |
801 |
|
x+=7; |
802 |
|
} |
803 |
< |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
803 |
> |
|
804 |
> |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
805 |
|
move(1,x); |
806 |
< |
printw("%5s", "Disk"); |
806 |
> |
printw("%6s", "Disk"); |
807 |
|
move(2,x); |
808 |
< |
printw("%5s", "read"); |
809 |
< |
x+=6; |
808 |
> |
printw("%6s", "read"); |
809 |
> |
x+=7; |
810 |
|
} |
811 |
+ |
|
812 |
|
} |
813 |
|
|
814 |
|
if(display_config->disk_io_total_read){ |
819 |
|
printw("%9s", "write"); |
820 |
|
x+=10; |
821 |
|
} |
822 |
+ |
|
823 |
|
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
824 |
|
move(1,x); |
825 |
|
printw("%6s", "Disk"); |
827 |
|
printw("%6s", "write"); |
828 |
|
x+=7; |
829 |
|
} |
830 |
< |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
830 |
> |
|
831 |
> |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
832 |
|
move(1,x); |
833 |
< |
printw("%5s", "Disk"); |
833 |
> |
printw("%6s", "Disk"); |
834 |
|
move(2,x); |
835 |
< |
printw("%5s", "write"); |
836 |
< |
x+=6; |
835 |
> |
printw("%6s", "write"); |
836 |
> |
x+=7; |
837 |
|
} |
838 |
+ |
|
839 |
|
} |
840 |
< |
|
840 |
> |
|
841 |
> |
if(display_config->processes && (display_config->maxx > x+25)){ |
842 |
> |
move(1,x); |
843 |
> |
printw("%-24s", " Number of Process"); |
844 |
> |
move(2,x); |
845 |
> |
printw("%-24s", " Run Slep Zomb Stop Tot"); |
846 |
> |
x+=25; |
847 |
> |
} |
848 |
> |
|
849 |
|
*title=0; |
850 |
|
} |
851 |
|
|
890 |
|
printw(" %5lld", machine_data_list->network_io_total_rx/1024); |
891 |
|
x+=6; |
892 |
|
} |
893 |
< |
if(display_config->units=='m' && (display_config->maxx > x+5)){ |
894 |
< |
printw(" %4.1f", (double)(machine_data_list->network_io_total_rx/(1024.00*1024.00))); |
895 |
< |
x+=5; |
893 |
> |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
894 |
> |
printw(" %5.2f", (double)(machine_data_list->network_io_total_rx/(1024.00*1024.00))); |
895 |
> |
x+=6; |
896 |
|
} |
897 |
|
} |
898 |
|
|
905 |
|
printw(" %5lld", machine_data_list->network_io_total_tx/1024); |
906 |
|
x+=6; |
907 |
|
} |
908 |
< |
if(display_config->units=='m' && (display_config->maxx > x+5)){ |
909 |
< |
printw(" %4.1f", (double)(machine_data_list->network_io_total_tx/(1024.00*1024.00))); |
910 |
< |
x+=5; |
908 |
> |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
909 |
> |
printw(" %5.2f", (double)(machine_data_list->network_io_total_tx/(1024.00*1024.00))); |
910 |
> |
x+=6; |
911 |
|
} |
912 |
|
} |
913 |
|
|
920 |
|
printw(" %6lld", machine_data_list->disk_io_total_read/1024); |
921 |
|
x+=7; |
922 |
|
} |
923 |
< |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
924 |
< |
printw(" %5.1f", (double)(machine_data_list->disk_io_total_read/(1024.00*1024.00))); |
925 |
< |
x+=6; |
923 |
> |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
924 |
> |
printw(" %6.2f", (double)(machine_data_list->disk_io_total_read/(1024.00*1024.00))); |
925 |
> |
x+=7; |
926 |
|
} |
927 |
|
} |
928 |
|
|
935 |
|
printw(" %6lld", machine_data_list->disk_io_total_write/1024); |
936 |
|
x+=7; |
937 |
|
} |
938 |
< |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
939 |
< |
printw(" %5.1f", (double)(machine_data_list->disk_io_total_write/(1024.00*1024.00))); |
940 |
< |
x+=6; |
938 |
> |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
939 |
> |
printw(" %6.2f", (double)(machine_data_list->disk_io_total_write/(1024.00*1024.00))); |
940 |
> |
x+=7; |
941 |
|
} |
942 |
|
} |
943 |
+ |
if(display_config->processes && display_config->maxx > x+25){ |
944 |
+ |
printw(" %4d %4d %4d %4d %4d", machine_data_list->processes_cpu, \ |
945 |
+ |
machine_data_list->processes_sleeping, \ |
946 |
+ |
machine_data_list->processes_zombie, \ |
947 |
+ |
machine_data_list->processes_stopped, \ |
948 |
+ |
machine_data_list->processes_total); |
949 |
+ |
x+=25; |
950 |
+ |
} |
951 |
|
|
952 |
|
machine_data_list=machine_data_list->next; |
953 |
|
} |
957 |
|
|
958 |
|
} |
959 |
|
|
960 |
+ |
void sig_winch_handler(int sig){ |
961 |
+ |
|
962 |
+ |
sig_winch=1; |
963 |
+ |
signal(SIGWINCH, sig_winch_handler); |
964 |
+ |
} |
965 |
+ |
|
966 |
|
int main(int argc, char **argv){ |
967 |
|
WINDOW *window; |
968 |
|
fd_set infds; |
986 |
|
int cmdopt; |
987 |
|
extern int optind; |
988 |
|
extern char *optarg; |
989 |
+ |
|
990 |
+ |
extern int errno; |
991 |
|
|
992 |
|
display_config_t display_config; |
993 |
|
char ch; |
1023 |
|
display_config.pages_in=1; |
1024 |
|
display_config.pages_out=1; |
1025 |
|
|
1026 |
< |
display_config.processes_total=0; |
1006 |
< |
display_config.processes_sleeping=0; |
1007 |
< |
display_config.processes_cpu=0; |
1008 |
< |
display_config.processes_zombie=0; |
1009 |
< |
display_config.processes_stopped=0; |
1026 |
> |
display_config.processes=1; |
1027 |
|
|
1028 |
|
display_config.network_io_total_tx=1; |
1029 |
|
display_config.network_io_total_rx=1; |
1034 |
|
display_config.disk_io_all_stats=0; |
1035 |
|
|
1036 |
|
display_config.disk_total_used=0; |
1037 |
< |
display_config.disk_all_stats=0; |
1037 |
> |
display_config.disk_all_stats=0; |
1038 |
|
|
1039 |
+ |
signal(SIGWINCH, sig_winch_handler); |
1040 |
+ |
|
1041 |
|
while((cmdopt=getopt(argc, argv, "s:")) != -1){ |
1042 |
|
switch(cmdopt){ |
1043 |
|
case 's': |
1070 |
|
strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME); |
1071 |
|
} |
1072 |
|
|
1073 |
< |
if(argc<(optind+2)){ |
1074 |
< |
printf("Usage is %s <-d lines> hostname port <machine list>\n", argv[0]); |
1075 |
< |
exit(1); |
1073 |
> |
servername=DEF_SERVER_NAME; |
1074 |
> |
server_control_port=DEF_SERVER_PORT; |
1075 |
> |
|
1076 |
> |
if(argc>=(optind+2)){ |
1077 |
> |
servername=argv[optind]; |
1078 |
> |
server_control_port=atoi(argv[optind+1]); |
1079 |
|
} |
1080 |
|
|
1059 |
– |
servername=argv[optind]; |
1060 |
– |
server_control_port=atoi(argv[optind+1]); |
1061 |
– |
|
1081 |
|
control=create_tcp_connection(servername, server_control_port); |
1082 |
|
if(control==NULL){ |
1083 |
|
errf("Failed to connect (%m)"); |
1128 |
|
exit(1); |
1129 |
|
} |
1130 |
|
|
1112 |
– |
/* |
1113 |
– |
printf("\033[2J"); |
1114 |
– |
printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); |
1115 |
– |
printf("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
1116 |
– |
*/ |
1117 |
– |
|
1131 |
|
initscr(); |
1132 |
|
nonl(); |
1133 |
|
cbreak(); |
1134 |
< |
echo(); |
1134 |
> |
noecho(); |
1135 |
|
window=newwin(0, 0, 0, 0); |
1136 |
|
getmaxyx(window, display_config.maxy, display_config.maxx); |
1137 |
|
|
1144 |
|
FD_SET(stdin_fileno, &infds); |
1145 |
|
FD_SET(data_fileno, &infds); |
1146 |
|
if((select(biggest_fileno, &infds, NULL, NULL, NULL))==-1){ |
1147 |
+ |
if(errno!=EINTR){ |
1148 |
+ |
errf("select failed with (%m)"); |
1149 |
+ |
exit(1); |
1150 |
+ |
} |
1151 |
+ |
} |
1152 |
+ |
|
1153 |
+ |
if(sig_winch){ |
1154 |
|
if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { |
1155 |
|
resizeterm(size.ws_row, size.ws_col); |
1156 |
|
wrefresh(curscr); |
1159 |
|
title=1; |
1160 |
|
display(machine_data_list, &display_config, &title); |
1161 |
|
refresh(); |
1162 |
+ |
sig_winch=0; |
1163 |
|
continue; |
1164 |
|
} |
1165 |
|
|
1166 |
|
if(FD_ISSET(stdin_fileno, &infds)){ |
1167 |
|
|
1168 |
< |
ch=getc(stdin); |
1168 |
> |
ch=getch(); |
1169 |
|
switch(ch){ |
1170 |
+ |
case KEY_RESIZE: |
1171 |
+ |
sig_winch=1; |
1172 |
+ |
break; |
1173 |
|
|
1174 |
|
/* Quit */ |
1175 |
|
case 'Q': |
1293 |
|
display_config.cpu_used=1; |
1294 |
|
} |
1295 |
|
break; |
1296 |
+ |
case 'r': |
1297 |
+ |
if(display_config.processes){ |
1298 |
+ |
display_config.processes=0; |
1299 |
+ |
}else{ |
1300 |
+ |
display_config.processes=1; |
1301 |
+ |
} |
1302 |
+ |
break; |
1303 |
|
|
1304 |
|
default: |
1305 |
< |
/* Invalid key.. Ignore.. Set Title to -1, as the |
1275 |
< |
* title++ will then make that "0" (false) so a |
1276 |
< |
* screen redraw will not happen */ |
1277 |
< |
title=-1; |
1278 |
< |
break; |
1305 |
> |
continue; |
1306 |
|
} |
1307 |
|
|
1308 |
|
/* Increment title so it becomes true (and making the screen update */ |