31 |
|
#include <ukcprog.h> |
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> |
147 |
|
|
148 |
|
#define SORTBYMAXNAME 128 |
149 |
|
typedef struct{ |
150 |
+ |
int maxx; |
151 |
+ |
int maxy; |
152 |
+ |
|
153 |
+ |
char units; |
154 |
+ |
|
155 |
|
int cpu_user; |
156 |
|
int cpu_idle; |
157 |
|
int cpu_iowait; |
176 |
|
int pages_in; |
177 |
|
int pages_out; |
178 |
|
|
179 |
< |
int processes_total; |
172 |
< |
int processes_sleeping; |
173 |
< |
int processes_cpu; |
174 |
< |
int processes_zombie; |
175 |
< |
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 |
|
|
221 |
– |
/* |
222 |
– |
int cmp_cpu(machine_data_list_t *a, machine_data_list_t *b){ |
223 |
– |
|
224 |
– |
if(a->cpu_used == b->cpu_used){ |
225 |
– |
if(a->load_1 == b->load_1) return 0; |
226 |
– |
if(a->load_1 > b->load_1){ |
227 |
– |
return -1; |
228 |
– |
}else{ |
229 |
– |
return 1; |
230 |
– |
} |
231 |
– |
} |
232 |
– |
|
233 |
– |
if((a->cpu_used) > (b->cpu_used)){ |
234 |
– |
return -1; |
235 |
– |
}else{ |
236 |
– |
return 1; |
237 |
– |
} |
238 |
– |
} |
239 |
– |
*/ |
240 |
– |
|
226 |
|
#ifndef HAVE_ATOLL |
227 |
|
long long int atoll (const char *nptr){ |
228 |
|
return strtoll (nptr, (char **) NULL, 10); |
660 |
|
|
661 |
|
} |
662 |
|
|
663 |
< |
void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int num_lines, int *title){ |
663 |
> |
void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int *title){ |
664 |
|
int line_num=4; |
665 |
|
int counter; |
666 |
|
int x=1; |
667 |
|
|
668 |
|
if(*title){ |
669 |
|
clear(); |
670 |
< |
move (num_lines-3, 1); |
670 |
> |
move (display_config->maxy-3, 1); |
671 |
|
printw("Sorting by %-64s", display_config->sortby); |
672 |
+ |
move (display_config->maxy-2, 1); |
673 |
+ |
if(display_config->units == 'b'){ |
674 |
+ |
printw("Units are measured in bytes/sec"); |
675 |
+ |
} |
676 |
+ |
if(display_config->units == 'k'){ |
677 |
+ |
printw("Units are measured in kilobytes/sec"); |
678 |
+ |
} |
679 |
+ |
if(display_config->units == 'm'){ |
680 |
+ |
printw("Units are measured in megabytes/sec"); |
681 |
+ |
} |
682 |
|
|
683 |
|
move(1,1); |
684 |
|
printw("%-11s", "Hostname"); |
685 |
|
x=x+11+1; |
686 |
< |
if(display_config->cpu_used){ |
686 |
> |
if(display_config->cpu_used && (display_config->maxx > x+6)){ |
687 |
|
move(1,x); |
688 |
|
printw("%5s", "CPU"); |
689 |
|
move(2,x); |
690 |
|
printw("%5s", "used%"); |
691 |
|
x+=6; |
692 |
|
} |
693 |
< |
if(display_config->load_1){ |
693 |
> |
if(display_config->load_1 && (display_config->maxx > x+6)){ |
694 |
|
move(1,x); |
695 |
|
printw("%5s", "Load"); |
696 |
|
move(2,x); |
697 |
|
printw("%5s", "(1m)"); |
698 |
|
x+=6; |
699 |
|
} |
700 |
< |
if(display_config->pages_in){ |
700 |
> |
|
701 |
> |
if(display_config->pages_in && (display_config->maxx > x+6)){ |
702 |
|
move(1,x); |
703 |
|
printw("%5s", "Page"); |
704 |
|
move(2,x); |
705 |
|
printw("%5s", "ins"); |
706 |
|
x+=6; |
707 |
|
} |
708 |
< |
if(display_config->pages_out){ |
708 |
> |
|
709 |
> |
if(display_config->pages_out && (display_config->maxx > x+6)){ |
710 |
|
move(1,x); |
711 |
|
printw("%5s", "Page"); |
712 |
|
move(2,x); |
713 |
|
printw("%5s", "outs"); |
714 |
|
x+=6; |
715 |
|
} |
716 |
< |
if(display_config->memory_used_pecent){ |
716 |
> |
|
717 |
> |
if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ |
718 |
|
move(1,x); |
719 |
|
printw("%5s", "Mem"); |
720 |
|
move(2,x); |
721 |
|
printw("%5s", "used"); |
722 |
|
x+=6; |
723 |
|
} |
724 |
< |
if(display_config->swap_used_pecent){ |
724 |
> |
|
725 |
> |
if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ |
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 |
< |
move(1,x); |
734 |
< |
printw("%8s", "Net"); |
735 |
< |
move(2,x); |
736 |
< |
printw("%8s", "rx"); |
737 |
< |
x+=9; |
732 |
> |
|
733 |
> |
if(display_config->network_io_total_rx){ |
734 |
> |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
735 |
> |
move(1,x); |
736 |
> |
printw("%8s", "Net"); |
737 |
> |
move(2,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"); |
745 |
> |
move(2,x); |
746 |
> |
printw("%5s", "rx"); |
747 |
> |
x+=6; |
748 |
> |
} |
749 |
> |
|
750 |
> |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
751 |
> |
move(1,x); |
752 |
> |
printw("%5s", "Net"); |
753 |
> |
move(2,x); |
754 |
> |
printw("%5s", "rx"); |
755 |
> |
x+=6; |
756 |
> |
} |
757 |
> |
|
758 |
|
} |
759 |
+ |
|
760 |
|
if(display_config->network_io_total_tx){ |
761 |
< |
move(1,x); |
762 |
< |
printw("%8s", "Net"); |
763 |
< |
move(2,x); |
764 |
< |
printw("%8s", "tx"); |
765 |
< |
x+=9; |
761 |
> |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
762 |
> |
move(1,x); |
763 |
> |
printw("%8s", "Net"); |
764 |
> |
move(2,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"); |
772 |
> |
move(2,x); |
773 |
> |
printw("%5s", "tx"); |
774 |
> |
x+=6; |
775 |
> |
} |
776 |
> |
|
777 |
> |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
778 |
> |
move(1,x); |
779 |
> |
printw("%5s", "Net"); |
780 |
> |
move(2,x); |
781 |
> |
printw("%5s", "tx"); |
782 |
> |
x+=6; |
783 |
> |
} |
784 |
> |
|
785 |
|
} |
786 |
+ |
|
787 |
|
if(display_config->disk_io_total_read){ |
788 |
< |
move(1,x); |
789 |
< |
printw("%9s", "Disk"); |
790 |
< |
move(2,x); |
791 |
< |
printw("%9s", "read"); |
792 |
< |
x+=10; |
788 |
> |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
789 |
> |
move(1,x); |
790 |
> |
printw("%9s", "Disk"); |
791 |
> |
move(2,x); |
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"); |
799 |
> |
move(2,x); |
800 |
> |
printw("%6s", "read"); |
801 |
> |
x+=7; |
802 |
> |
} |
803 |
> |
|
804 |
> |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
805 |
> |
move(1,x); |
806 |
> |
printw("%6s", "Disk"); |
807 |
> |
move(2,x); |
808 |
> |
printw("%6s", "read"); |
809 |
> |
x+=7; |
810 |
> |
} |
811 |
> |
|
812 |
|
} |
813 |
+ |
|
814 |
|
if(display_config->disk_io_total_read){ |
815 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
816 |
+ |
move(1,x); |
817 |
+ |
printw("%9s", "Disk"); |
818 |
+ |
move(2,x); |
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"); |
826 |
+ |
move(2,x); |
827 |
+ |
printw("%6s", "write"); |
828 |
+ |
x+=7; |
829 |
+ |
} |
830 |
+ |
|
831 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
832 |
+ |
move(1,x); |
833 |
+ |
printw("%6s", "Disk"); |
834 |
+ |
move(2,x); |
835 |
+ |
printw("%6s", "write"); |
836 |
+ |
x+=7; |
837 |
+ |
} |
838 |
+ |
|
839 |
+ |
} |
840 |
+ |
|
841 |
+ |
if(display_config->processes && (display_config->maxx > x+25)){ |
842 |
|
move(1,x); |
843 |
< |
printw("%9s", "Disk"); |
843 |
> |
printw("%-24s", " Number of Process"); |
844 |
|
move(2,x); |
845 |
< |
printw("%9s", "write"); |
846 |
< |
x+=10; |
847 |
< |
} |
848 |
< |
|
845 |
> |
printw("%-24s", " Run Slep Zomb Stop Tot"); |
846 |
> |
x+=25; |
847 |
> |
} |
848 |
> |
|
849 |
|
*title=0; |
850 |
|
} |
851 |
|
|
852 |
|
/* Counter starts at 8, for padding (eg, headers, borders etc) */ |
853 |
< |
for(counter=8;counter<num_lines;counter++){ |
853 |
> |
for(counter=8;counter<display_config->maxy;counter++){ |
854 |
|
if(machine_data_list==NULL) break; |
855 |
|
move(line_num++, 1); |
856 |
|
printw("%-11s", machine_data_list->sysname); |
857 |
+ |
x=13; |
858 |
|
|
859 |
< |
if(display_config->cpu_used) printw(" %5.1f", machine_data_list->cpu_used); |
860 |
< |
if(display_config->load_1) printw(" %5.1f", machine_data_list->load_1); |
861 |
< |
if(display_config->pages_in) printw(" %5d", machine_data_list->pages_in); |
862 |
< |
if(display_config->pages_out) printw(" %5d", machine_data_list->pages_out); |
863 |
< |
if(display_config->memory_used_pecent) printw(" %5.1f", machine_data_list->memory_used_pecent); |
864 |
< |
if(display_config->swap_used_pecent) printw(" %5.1f", machine_data_list->swap_used_pecent); |
865 |
< |
if(display_config->network_io_total_rx) printw(" %8lld", machine_data_list->network_io_total_rx); |
866 |
< |
if(display_config->network_io_total_tx) printw(" %8lld", machine_data_list->network_io_total_tx); |
867 |
< |
if(display_config->disk_io_total_read) printw(" %9lld", machine_data_list->disk_io_total_read); |
868 |
< |
if(display_config->disk_io_total_write) printw(" %9lld", machine_data_list->disk_io_total_write); |
859 |
> |
if(display_config->cpu_used && (display_config->maxx > x+6)){ |
860 |
> |
printw(" %5.1f", machine_data_list->cpu_used); |
861 |
> |
x+=6; |
862 |
> |
} |
863 |
> |
if(display_config->load_1 && (display_config->maxx > x+6)){ |
864 |
> |
printw(" %5.1f", machine_data_list->load_1); |
865 |
> |
x+=6; |
866 |
> |
} |
867 |
> |
if(display_config->pages_in && (display_config->maxx > x+6)){ |
868 |
> |
printw(" %5d", machine_data_list->pages_in); |
869 |
> |
x+=6; |
870 |
> |
} |
871 |
> |
if(display_config->pages_out && (display_config->maxx > x+6)){ |
872 |
> |
printw(" %5d", machine_data_list->pages_out); |
873 |
> |
x+=6; |
874 |
> |
} |
875 |
> |
if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ |
876 |
> |
printw(" %5.1f", machine_data_list->memory_used_pecent); |
877 |
> |
x+=6; |
878 |
> |
} |
879 |
> |
if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ |
880 |
> |
printw(" %5.1f", machine_data_list->swap_used_pecent); |
881 |
> |
x+=6; |
882 |
> |
} |
883 |
|
|
884 |
+ |
if(display_config->network_io_total_rx){ |
885 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
886 |
+ |
printw(" %8lld", machine_data_list->network_io_total_rx); |
887 |
+ |
x+=9; |
888 |
+ |
} |
889 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
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+6)){ |
894 |
+ |
printw(" %5.2f", (double)(machine_data_list->network_io_total_rx/(1024.00*1024.00))); |
895 |
+ |
x+=6; |
896 |
+ |
} |
897 |
+ |
} |
898 |
+ |
|
899 |
+ |
if(display_config->network_io_total_tx){ |
900 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
901 |
+ |
printw(" %8lld", machine_data_list->network_io_total_tx); |
902 |
+ |
x+=9; |
903 |
+ |
} |
904 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
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+6)){ |
909 |
+ |
printw(" %5.2f", (double)(machine_data_list->network_io_total_tx/(1024.00*1024.00))); |
910 |
+ |
x+=6; |
911 |
+ |
} |
912 |
+ |
} |
913 |
+ |
|
914 |
+ |
if(display_config->disk_io_total_read){ |
915 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
916 |
+ |
printw(" %9lld", machine_data_list->disk_io_total_read); |
917 |
+ |
x+=10; |
918 |
+ |
} |
919 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
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+7)){ |
924 |
+ |
printw(" %6.2f", (double)(machine_data_list->disk_io_total_read/(1024.00*1024.00))); |
925 |
+ |
x+=7; |
926 |
+ |
} |
927 |
+ |
} |
928 |
+ |
|
929 |
+ |
if(display_config->disk_io_total_write){ |
930 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
931 |
+ |
printw(" %9lld", machine_data_list->disk_io_total_write); |
932 |
+ |
x+=10; |
933 |
+ |
} |
934 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
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+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 |
|
} |
954 |
|
|
957 |
|
|
958 |
|
} |
959 |
|
|
960 |
+ |
void sig_winch_handler(int sig){ |
961 |
+ |
|
962 |
+ |
sig_winch=1; |
963 |
+ |
signal(SIGWINCH, sig_winch_handler); |
964 |
+ |
} |
965 |
+ |
|
966 |
+ |
void usage() { |
967 |
+ |
printf("Usage: idar [-o order] [-s server] [-p port] [-l list] [-h]\n\n"); |
968 |
+ |
printf(" -o Sets the initial sort order. Accepted arguments are one of:\n"); |
969 |
+ |
printf(" cpu load mem swap net disk\n"); |
970 |
+ |
printf(" -s Specifies the i-scream server to connect to.\n"); |
971 |
+ |
printf(" default: %s\n", DEF_SERVER_NAME); |
972 |
+ |
printf(" -p Specifies the i-scream server port.\n"); |
973 |
+ |
printf(" default: %d\n", DEF_SERVER_PORT); |
974 |
+ |
printf(" -l Sets the list of hosts to monitor in a semi-colon separated list.\n"); |
975 |
+ |
printf(" -h Displays this help information.\n"); |
976 |
+ |
printf("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
977 |
+ |
exit(1); |
978 |
+ |
} |
979 |
+ |
|
980 |
|
int main(int argc, char **argv){ |
981 |
|
WINDOW *window; |
982 |
|
fd_set infds; |
983 |
< |
int maxx, maxy; |
983 |
> |
struct winsize size; |
984 |
|
|
985 |
|
FILE *control; |
986 |
|
FILE *data; |
988 |
|
char *machine_list=NULL; |
989 |
|
char *response=NULL; |
990 |
|
|
991 |
< |
char *servername; |
991 |
> |
char *server_name; |
992 |
|
int server_control_port; |
993 |
|
int server_data_port; |
994 |
|
|
995 |
|
machine_data_list_t *machine_data_list=NULL; |
996 |
|
|
997 |
|
int num_hosts; |
808 |
– |
int max_display=0; |
998 |
|
int title=1; |
999 |
|
|
1000 |
|
int cmdopt; |
1001 |
|
extern int optind; |
1002 |
|
extern char *optarg; |
1003 |
+ |
|
1004 |
+ |
extern int errno; |
1005 |
|
|
1006 |
|
display_config_t display_config; |
1007 |
|
char ch; |
1011 |
|
sortby_ptr=NULL; |
1012 |
|
|
1013 |
|
/* What to display defaults */ |
1014 |
+ |
display_config.units='b'; |
1015 |
+ |
|
1016 |
|
display_config.cpu_user=0; |
1017 |
|
display_config.cpu_idle=0; |
1018 |
|
display_config.cpu_iowait=0; |
1037 |
|
display_config.pages_in=1; |
1038 |
|
display_config.pages_out=1; |
1039 |
|
|
1040 |
< |
display_config.processes_total=0; |
848 |
< |
display_config.processes_sleeping=0; |
849 |
< |
display_config.processes_cpu=0; |
850 |
< |
display_config.processes_zombie=0; |
851 |
< |
display_config.processes_stopped=0; |
1040 |
> |
display_config.processes=1; |
1041 |
|
|
1042 |
|
display_config.network_io_total_tx=1; |
1043 |
|
display_config.network_io_total_rx=1; |
1048 |
|
display_config.disk_io_all_stats=0; |
1049 |
|
|
1050 |
|
display_config.disk_total_used=0; |
1051 |
< |
display_config.disk_all_stats=0; |
1051 |
> |
display_config.disk_all_stats=0; |
1052 |
|
|
1053 |
< |
while((cmdopt=getopt(argc, argv, "d:s:")) != -1){ |
1053 |
> |
signal(SIGWINCH, sig_winch_handler); |
1054 |
> |
|
1055 |
> |
server_name=DEF_SERVER_NAME; |
1056 |
> |
server_control_port=DEF_SERVER_PORT; |
1057 |
> |
|
1058 |
> |
while((cmdopt=getopt(argc, argv, "o:s:p:l:h")) != -1){ |
1059 |
|
switch(cmdopt){ |
1060 |
< |
case 'd': |
867 |
< |
max_display=atoi(optarg); |
868 |
< |
break; |
869 |
< |
case 's': |
1060 |
> |
case 'o': |
1061 |
|
if(!strcmp(optarg, "cpu")){ |
1062 |
|
sortby_ptr=cmp_cpu_used; |
1063 |
|
strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); |
1071 |
|
strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); |
1072 |
|
} |
1073 |
|
if(!strcmp(optarg, "swap")){ |
1074 |
< |
sortby_ptr=cmp_swap_used_pecent; |
1075 |
< |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
1076 |
< |
} |
1074 |
> |
sortby_ptr=cmp_swap_used_pecent; |
1075 |
> |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
1076 |
> |
} |
1077 |
> |
if(!strcmp(optarg, "net")){ |
1078 |
> |
sortby_ptr=cmp_network_io_total; |
1079 |
> |
strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME); |
1080 |
> |
} |
1081 |
> |
if(!strcmp(optarg, "disk")){ |
1082 |
> |
sortby_ptr=cmp_disk_io_total; |
1083 |
> |
strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME); |
1084 |
> |
} |
1085 |
|
if(sortby_ptr==NULL){ |
1086 |
< |
errf("Invalid sort type"); |
1087 |
< |
exit(1); |
1086 |
> |
errf("Invalid order given."); |
1087 |
> |
usage(); |
1088 |
|
} |
1089 |
< |
break; |
1089 |
> |
break; |
1090 |
> |
case 's': |
1091 |
> |
server_name=optarg; |
1092 |
> |
break; |
1093 |
> |
case 'p': |
1094 |
> |
server_control_port=atoi(optarg); |
1095 |
> |
break; |
1096 |
> |
case 'l': |
1097 |
> |
/* We've been passed a machine list */ |
1098 |
> |
/* list currently needs to be ; seperated */ |
1099 |
> |
machine_list=strdup(optarg); |
1100 |
> |
break; |
1101 |
> |
case 'h': |
1102 |
> |
usage(); |
1103 |
> |
break; |
1104 |
|
} |
1105 |
|
} |
1106 |
|
|
1107 |
+ |
/* Don't take any other arguments */ |
1108 |
+ |
if(argc>optind){ |
1109 |
+ |
usage(); |
1110 |
+ |
} |
1111 |
+ |
|
1112 |
|
if(sortby_ptr==NULL){ |
1113 |
|
sortby_ptr=cmp_cpu_used; |
1114 |
|
strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME); |
1115 |
|
} |
1116 |
|
|
1117 |
< |
if(argc<(optind+2)){ |
900 |
< |
printf("Usage is %s <-d lines> hostname port <machine list>\n", argv[0]); |
901 |
< |
exit(1); |
902 |
< |
} |
903 |
< |
|
904 |
< |
servername=argv[optind]; |
905 |
< |
server_control_port=atoi(argv[optind+1]); |
906 |
< |
|
907 |
< |
control=create_tcp_connection(servername, server_control_port); |
1117 |
> |
control=create_tcp_connection(server_name, server_control_port); |
1118 |
|
if(control==NULL){ |
1119 |
|
errf("Failed to connect (%m)"); |
1120 |
|
exit(1); |
1121 |
|
} |
1122 |
|
|
913 |
– |
if(argc==4){ |
914 |
– |
/* We've been passed a machine list */ |
915 |
– |
/* list currently needs to be ; seperated */ |
916 |
– |
machine_list=strdup(argv[3]); |
917 |
– |
} |
918 |
– |
|
1123 |
|
if((tcp_comm(control, NULL, &response, "PROTOCOL 1.1"))!=0){ |
1124 |
|
errf("Incorrect version number (%s)", response); |
1125 |
|
exit(1); |
1152 |
|
exit(1); |
1153 |
|
} |
1154 |
|
|
1155 |
< |
data=create_tcp_connection(servername, server_data_port); |
1155 |
> |
data=create_tcp_connection(server_name, server_data_port); |
1156 |
|
if(data==NULL){ |
1157 |
< |
errf("Failed to connect to host %s on port %d (%m)",servername, server_data_port); |
1157 |
> |
errf("Failed to connect to host %s on port %d (%m)",server_name, server_data_port); |
1158 |
> |
exit(1); |
1159 |
|
} |
1160 |
|
|
956 |
– |
/* |
957 |
– |
printf("\033[2J"); |
958 |
– |
printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); |
959 |
– |
printf("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
960 |
– |
*/ |
961 |
– |
|
1161 |
|
initscr(); |
1162 |
|
nonl(); |
1163 |
|
cbreak(); |
1164 |
< |
echo(); |
1164 |
> |
noecho(); |
1165 |
|
window=newwin(0, 0, 0, 0); |
1166 |
< |
getmaxyx(window, maxy, maxx); |
1166 |
> |
getmaxyx(window, display_config.maxy, display_config.maxx); |
1167 |
|
|
1168 |
|
stdin_fileno=fileno(stdin); |
1169 |
|
data_fileno=fileno(data); |
1173 |
|
FD_ZERO(&infds); |
1174 |
|
FD_SET(stdin_fileno, &infds); |
1175 |
|
FD_SET(data_fileno, &infds); |
1176 |
< |
select(biggest_fileno, &infds, NULL, NULL, NULL); |
1176 |
> |
if((select(biggest_fileno, &infds, NULL, NULL, NULL))==-1){ |
1177 |
> |
if(errno!=EINTR){ |
1178 |
> |
errf("select failed with (%m)"); |
1179 |
> |
exit(1); |
1180 |
> |
} |
1181 |
> |
} |
1182 |
> |
|
1183 |
> |
if(sig_winch){ |
1184 |
> |
if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { |
1185 |
> |
resizeterm(size.ws_row, size.ws_col); |
1186 |
> |
wrefresh(curscr); |
1187 |
> |
} |
1188 |
> |
getmaxyx(window, display_config.maxy, display_config.maxx); |
1189 |
> |
title=1; |
1190 |
> |
display(machine_data_list, &display_config, &title); |
1191 |
> |
refresh(); |
1192 |
> |
sig_winch=0; |
1193 |
> |
continue; |
1194 |
> |
} |
1195 |
|
|
1196 |
|
if(FD_ISSET(stdin_fileno, &infds)){ |
1197 |
|
|
1198 |
< |
ch=getc(stdin); |
1198 |
> |
ch=getch(); |
1199 |
|
switch(ch){ |
1200 |
+ |
case KEY_RESIZE: |
1201 |
+ |
sig_winch=1; |
1202 |
+ |
break; |
1203 |
|
|
1204 |
|
/* Quit */ |
1205 |
|
case 'Q': |
1207 |
|
endwin(); |
1208 |
|
exit(0); |
1209 |
|
break; |
1210 |
+ |
/* Units */ |
1211 |
+ |
case 'U': |
1212 |
+ |
case 'u': |
1213 |
+ |
if(display_config.units == 'b'){ |
1214 |
+ |
display_config.units = 'k'; |
1215 |
+ |
}else if(display_config.units == 'k'){ |
1216 |
+ |
display_config.units = 'm'; |
1217 |
+ |
}else{ |
1218 |
+ |
display_config.units = 'b'; |
1219 |
+ |
} |
1220 |
+ |
break; |
1221 |
|
|
1222 |
|
/* Sort by */ |
1223 |
|
case 'C': |
1323 |
|
display_config.cpu_used=1; |
1324 |
|
} |
1325 |
|
break; |
1326 |
+ |
case 'r': |
1327 |
+ |
if(display_config.processes){ |
1328 |
+ |
display_config.processes=0; |
1329 |
+ |
}else{ |
1330 |
+ |
display_config.processes=1; |
1331 |
+ |
} |
1332 |
+ |
break; |
1333 |
|
|
1334 |
|
default: |
1335 |
< |
/* Invalid key.. Ignore.. Set Title to -1, as the |
1098 |
< |
* title++ will then make that "0" (false) so a |
1099 |
< |
* screen redraw will not happen */ |
1100 |
< |
title=-1; |
1101 |
< |
break; |
1335 |
> |
continue; |
1336 |
|
} |
1337 |
|
|
1338 |
|
/* Increment title so it becomes true (and making the screen update */ |
1351 |
|
num_hosts=parse_xml(response, &machine_data_list); |
1352 |
|
if(num_hosts==-1) continue; |
1353 |
|
machine_data_list=sort_machine_stats(machine_data_list, num_hosts, sortby_ptr); |
1354 |
< |
if(max_display==0){ |
1121 |
< |
display(machine_data_list, &display_config, maxy, &title); |
1122 |
< |
}else{ |
1123 |
< |
display(machine_data_list, &display_config, max_display, &title); |
1124 |
< |
} |
1354 |
> |
display(machine_data_list, &display_config, &title); |
1355 |
|
|
1356 |
|
} |
1357 |
|
exit(0); |