| 145 |
|
|
| 146 |
|
#define SORTBYMAXNAME 128 |
| 147 |
|
typedef struct{ |
| 148 |
+ |
int maxx; |
| 149 |
+ |
int maxy; |
| 150 |
+ |
|
| 151 |
+ |
char units; |
| 152 |
+ |
|
| 153 |
|
int cpu_user; |
| 154 |
|
int cpu_idle; |
| 155 |
|
int cpu_iowait; |
| 681 |
|
|
| 682 |
|
} |
| 683 |
|
|
| 684 |
< |
void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int num_lines, int *title){ |
| 684 |
> |
void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int *title){ |
| 685 |
|
int line_num=4; |
| 686 |
|
int counter; |
| 687 |
|
int x=1; |
| 688 |
|
|
| 689 |
|
if(*title){ |
| 690 |
|
clear(); |
| 691 |
< |
move (num_lines-3, 1); |
| 691 |
> |
move (display_config->maxy-3, 1); |
| 692 |
|
printw("Sorting by %-64s", display_config->sortby); |
| 693 |
+ |
move (display_config->maxy-2, 1); |
| 694 |
+ |
if(display_config->units == 'b'){ |
| 695 |
+ |
printw("Units are measured in bytes/sec"); |
| 696 |
+ |
} |
| 697 |
+ |
if(display_config->units == 'k'){ |
| 698 |
+ |
printw("Units are measured in kilobytes/sec"); |
| 699 |
+ |
} |
| 700 |
+ |
if(display_config->units == 'm'){ |
| 701 |
+ |
printw("Units are measured in megabytes/sec"); |
| 702 |
+ |
} |
| 703 |
|
|
| 704 |
|
move(1,1); |
| 705 |
|
printw("%-11s", "Hostname"); |
| 706 |
|
x=x+11+1; |
| 707 |
< |
if(display_config->cpu_used){ |
| 707 |
> |
if(display_config->cpu_used && (display_config->maxx > x+6)){ |
| 708 |
|
move(1,x); |
| 709 |
|
printw("%5s", "CPU"); |
| 710 |
|
move(2,x); |
| 711 |
|
printw("%5s", "used%"); |
| 712 |
|
x+=6; |
| 713 |
|
} |
| 714 |
< |
if(display_config->load_1){ |
| 714 |
> |
if(display_config->load_1 && (display_config->maxx > x+6)){ |
| 715 |
|
move(1,x); |
| 716 |
|
printw("%5s", "Load"); |
| 717 |
|
move(2,x); |
| 718 |
|
printw("%5s", "(1m)"); |
| 719 |
|
x+=6; |
| 720 |
|
} |
| 721 |
< |
if(display_config->pages_in){ |
| 721 |
> |
if(display_config->pages_in && (display_config->maxx > x+6)){ |
| 722 |
|
move(1,x); |
| 723 |
|
printw("%5s", "Page"); |
| 724 |
|
move(2,x); |
| 725 |
|
printw("%5s", "ins"); |
| 726 |
|
x+=6; |
| 727 |
|
} |
| 728 |
< |
if(display_config->pages_out){ |
| 728 |
> |
if(display_config->pages_out && (display_config->maxx > x+6)){ |
| 729 |
|
move(1,x); |
| 730 |
|
printw("%5s", "Page"); |
| 731 |
|
move(2,x); |
| 732 |
|
printw("%5s", "outs"); |
| 733 |
|
x+=6; |
| 734 |
|
} |
| 735 |
< |
if(display_config->memory_used_pecent){ |
| 735 |
> |
if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ |
| 736 |
|
move(1,x); |
| 737 |
|
printw("%5s", "Mem"); |
| 738 |
|
move(2,x); |
| 739 |
|
printw("%5s", "used"); |
| 740 |
|
x+=6; |
| 741 |
|
} |
| 742 |
< |
if(display_config->swap_used_pecent){ |
| 742 |
> |
if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ |
| 743 |
|
move(1,x); |
| 744 |
|
printw("%5s", "Swap"); |
| 745 |
|
move(2,x); |
| 746 |
|
printw("%5s", "used"); |
| 747 |
|
x+=6; |
| 748 |
|
} |
| 749 |
< |
if(display_config->network_io_total_rx){ |
| 750 |
< |
move(1,x); |
| 751 |
< |
printw("%8s", "Net"); |
| 752 |
< |
move(2,x); |
| 753 |
< |
printw("%8s", "rx"); |
| 754 |
< |
x+=9; |
| 749 |
> |
if(display_config->network_io_total_rx){ |
| 750 |
> |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
| 751 |
> |
move(1,x); |
| 752 |
> |
printw("%8s", "Net"); |
| 753 |
> |
move(2,x); |
| 754 |
> |
printw("%8s", "rx"); |
| 755 |
> |
x+=9; |
| 756 |
> |
} |
| 757 |
> |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
| 758 |
> |
move(1,x); |
| 759 |
> |
printw("%5s", "Net"); |
| 760 |
> |
move(2,x); |
| 761 |
> |
printw("%5s", "rx"); |
| 762 |
> |
x+=6; |
| 763 |
> |
} |
| 764 |
> |
if(display_config->units=='m' && (display_config->maxx > x+5)){ |
| 765 |
> |
move(1,x); |
| 766 |
> |
printw("%4s", "Net"); |
| 767 |
> |
move(2,x); |
| 768 |
> |
printw("%4s", "rx"); |
| 769 |
> |
x+=5; |
| 770 |
> |
} |
| 771 |
|
} |
| 772 |
|
if(display_config->network_io_total_tx){ |
| 773 |
< |
move(1,x); |
| 774 |
< |
printw("%8s", "Net"); |
| 775 |
< |
move(2,x); |
| 776 |
< |
printw("%8s", "tx"); |
| 777 |
< |
x+=9; |
| 773 |
> |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
| 774 |
> |
move(1,x); |
| 775 |
> |
printw("%8s", "Net"); |
| 776 |
> |
move(2,x); |
| 777 |
> |
printw("%8s", "tx"); |
| 778 |
> |
x+=9; |
| 779 |
> |
} |
| 780 |
> |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
| 781 |
> |
move(1,x); |
| 782 |
> |
printw("%5s", "Net"); |
| 783 |
> |
move(2,x); |
| 784 |
> |
printw("%5s", "tx"); |
| 785 |
> |
x+=6; |
| 786 |
> |
} |
| 787 |
> |
if(display_config->units=='m' && (display_config->maxx > x+5)){ |
| 788 |
> |
move(1,x); |
| 789 |
> |
printw("%4s", "Net"); |
| 790 |
> |
move(2,x); |
| 791 |
> |
printw("%4s", "tx"); |
| 792 |
> |
x+=5; |
| 793 |
> |
} |
| 794 |
|
} |
| 795 |
+ |
|
| 796 |
|
if(display_config->disk_io_total_read){ |
| 797 |
< |
move(1,x); |
| 798 |
< |
printw("%9s", "Disk"); |
| 799 |
< |
move(2,x); |
| 800 |
< |
printw("%9s", "read"); |
| 801 |
< |
x+=10; |
| 797 |
> |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
| 798 |
> |
move(1,x); |
| 799 |
> |
printw("%9s", "Disk"); |
| 800 |
> |
move(2,x); |
| 801 |
> |
printw("%9s", "read"); |
| 802 |
> |
x+=10; |
| 803 |
> |
} |
| 804 |
> |
if(display_config->units=='k' && (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 |
> |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
| 812 |
> |
move(1,x); |
| 813 |
> |
printw("%5s", "Disk"); |
| 814 |
> |
move(2,x); |
| 815 |
> |
printw("%5s", "read"); |
| 816 |
> |
x+=6; |
| 817 |
> |
} |
| 818 |
|
} |
| 819 |
+ |
|
| 820 |
|
if(display_config->disk_io_total_read){ |
| 821 |
< |
move(1,x); |
| 822 |
< |
printw("%9s", "Disk"); |
| 823 |
< |
move(2,x); |
| 824 |
< |
printw("%9s", "write"); |
| 825 |
< |
x+=10; |
| 821 |
> |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
| 822 |
> |
move(1,x); |
| 823 |
> |
printw("%9s", "Disk"); |
| 824 |
> |
move(2,x); |
| 825 |
> |
printw("%9s", "write"); |
| 826 |
> |
x+=10; |
| 827 |
> |
} |
| 828 |
> |
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
| 829 |
> |
move(1,x); |
| 830 |
> |
printw("%6s", "Disk"); |
| 831 |
> |
move(2,x); |
| 832 |
> |
printw("%6s", "write"); |
| 833 |
> |
x+=7; |
| 834 |
> |
} |
| 835 |
> |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
| 836 |
> |
move(1,x); |
| 837 |
> |
printw("%5s", "Disk"); |
| 838 |
> |
move(2,x); |
| 839 |
> |
printw("%5s", "write"); |
| 840 |
> |
x+=6; |
| 841 |
> |
} |
| 842 |
|
} |
| 843 |
|
|
| 844 |
|
*title=0; |
| 845 |
|
} |
| 846 |
|
|
| 847 |
|
/* Counter starts at 8, for padding (eg, headers, borders etc) */ |
| 848 |
< |
for(counter=8;counter<num_lines;counter++){ |
| 848 |
> |
for(counter=8;counter<display_config->maxy;counter++){ |
| 849 |
|
if(machine_data_list==NULL) break; |
| 850 |
|
move(line_num++, 1); |
| 851 |
|
printw("%-11s", machine_data_list->sysname); |
| 852 |
+ |
x=13; |
| 853 |
|
|
| 854 |
< |
if(display_config->cpu_used) printw(" %5.1f", machine_data_list->cpu_used); |
| 855 |
< |
if(display_config->load_1) printw(" %5.1f", machine_data_list->load_1); |
| 856 |
< |
if(display_config->pages_in) printw(" %5d", machine_data_list->pages_in); |
| 857 |
< |
if(display_config->pages_out) printw(" %5d", machine_data_list->pages_out); |
| 858 |
< |
if(display_config->memory_used_pecent) printw(" %5.1f", machine_data_list->memory_used_pecent); |
| 859 |
< |
if(display_config->swap_used_pecent) printw(" %5.1f", machine_data_list->swap_used_pecent); |
| 860 |
< |
if(display_config->network_io_total_rx) printw(" %8lld", machine_data_list->network_io_total_rx); |
| 861 |
< |
if(display_config->network_io_total_tx) printw(" %8lld", machine_data_list->network_io_total_tx); |
| 862 |
< |
if(display_config->disk_io_total_read) printw(" %9lld", machine_data_list->disk_io_total_read); |
| 863 |
< |
if(display_config->disk_io_total_write) printw(" %9lld", machine_data_list->disk_io_total_write); |
| 854 |
> |
if(display_config->cpu_used && (display_config->maxx > x+6)){ |
| 855 |
> |
printw(" %5.1f", machine_data_list->cpu_used); |
| 856 |
> |
x+=6; |
| 857 |
> |
} |
| 858 |
> |
if(display_config->load_1 && (display_config->maxx > x+6)){ |
| 859 |
> |
printw(" %5.1f", machine_data_list->load_1); |
| 860 |
> |
x+=6; |
| 861 |
> |
} |
| 862 |
> |
if(display_config->pages_in && (display_config->maxx > x+6)){ |
| 863 |
> |
printw(" %5d", machine_data_list->pages_in); |
| 864 |
> |
x+=6; |
| 865 |
> |
} |
| 866 |
> |
if(display_config->pages_out && (display_config->maxx > x+6)){ |
| 867 |
> |
printw(" %5d", machine_data_list->pages_out); |
| 868 |
> |
x+=6; |
| 869 |
> |
} |
| 870 |
> |
if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ |
| 871 |
> |
printw(" %5.1f", machine_data_list->memory_used_pecent); |
| 872 |
> |
x+=6; |
| 873 |
> |
} |
| 874 |
> |
if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ |
| 875 |
> |
printw(" %5.1f", machine_data_list->swap_used_pecent); |
| 876 |
> |
x+=6; |
| 877 |
> |
} |
| 878 |
|
|
| 879 |
+ |
if(display_config->network_io_total_rx){ |
| 880 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
| 881 |
+ |
printw(" %8lld", machine_data_list->network_io_total_rx); |
| 882 |
+ |
x+=9; |
| 883 |
+ |
} |
| 884 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
| 885 |
+ |
printw(" %5lld", machine_data_list->network_io_total_rx/1024); |
| 886 |
+ |
x+=6; |
| 887 |
+ |
} |
| 888 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+5)){ |
| 889 |
+ |
printw(" %4.1f", (double)(machine_data_list->network_io_total_rx/(1024.00*1024.00))); |
| 890 |
+ |
x+=5; |
| 891 |
+ |
} |
| 892 |
+ |
} |
| 893 |
+ |
|
| 894 |
+ |
if(display_config->network_io_total_tx){ |
| 895 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
| 896 |
+ |
printw(" %8lld", machine_data_list->network_io_total_tx); |
| 897 |
+ |
x+=9; |
| 898 |
+ |
} |
| 899 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
| 900 |
+ |
printw(" %5lld", machine_data_list->network_io_total_tx/1024); |
| 901 |
+ |
x+=6; |
| 902 |
+ |
} |
| 903 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+5)){ |
| 904 |
+ |
printw(" %4.1f", (double)(machine_data_list->network_io_total_tx/(1024.00*1024.00))); |
| 905 |
+ |
x+=5; |
| 906 |
+ |
} |
| 907 |
+ |
} |
| 908 |
+ |
|
| 909 |
+ |
if(display_config->disk_io_total_read){ |
| 910 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
| 911 |
+ |
printw(" %9lld", machine_data_list->disk_io_total_read); |
| 912 |
+ |
x+=10; |
| 913 |
+ |
} |
| 914 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
| 915 |
+ |
printw(" %6lld", machine_data_list->disk_io_total_read/1024); |
| 916 |
+ |
x+=7; |
| 917 |
+ |
} |
| 918 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
| 919 |
+ |
printw(" %5.1f", (double)(machine_data_list->disk_io_total_read/(1024.00*1024.00))); |
| 920 |
+ |
x+=6; |
| 921 |
+ |
} |
| 922 |
+ |
} |
| 923 |
+ |
|
| 924 |
+ |
if(display_config->disk_io_total_write){ |
| 925 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
| 926 |
+ |
printw(" %9lld", machine_data_list->disk_io_total_write); |
| 927 |
+ |
x+=10; |
| 928 |
+ |
} |
| 929 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
| 930 |
+ |
printw(" %6lld", machine_data_list->disk_io_total_write/1024); |
| 931 |
+ |
x+=7; |
| 932 |
+ |
} |
| 933 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
| 934 |
+ |
printw(" %5.1f", (double)(machine_data_list->disk_io_total_write/(1024.00*1024.00))); |
| 935 |
+ |
x+=6; |
| 936 |
+ |
} |
| 937 |
+ |
} |
| 938 |
+ |
|
| 939 |
|
machine_data_list=machine_data_list->next; |
| 940 |
|
} |
| 941 |
|
|
| 947 |
|
int main(int argc, char **argv){ |
| 948 |
|
WINDOW *window; |
| 949 |
|
fd_set infds; |
| 794 |
– |
int maxx, maxy; |
| 950 |
|
struct winsize size; |
| 951 |
|
|
| 952 |
|
FILE *control; |
| 962 |
|
machine_data_list_t *machine_data_list=NULL; |
| 963 |
|
|
| 964 |
|
int num_hosts; |
| 810 |
– |
int max_display=0; |
| 965 |
|
int title=1; |
| 966 |
|
|
| 967 |
|
int cmdopt; |
| 976 |
|
sortby_ptr=NULL; |
| 977 |
|
|
| 978 |
|
/* What to display defaults */ |
| 979 |
+ |
display_config.units='b'; |
| 980 |
+ |
|
| 981 |
|
display_config.cpu_user=0; |
| 982 |
|
display_config.cpu_idle=0; |
| 983 |
|
display_config.cpu_iowait=0; |
| 1019 |
|
display_config.disk_total_used=0; |
| 1020 |
|
display_config.disk_all_stats=0; |
| 1021 |
|
|
| 1022 |
< |
while((cmdopt=getopt(argc, argv, "d:s:")) != -1){ |
| 1022 |
> |
while((cmdopt=getopt(argc, argv, "s:")) != -1){ |
| 1023 |
|
switch(cmdopt){ |
| 868 |
– |
case 'd': |
| 869 |
– |
max_display=atoi(optarg); |
| 870 |
– |
break; |
| 1024 |
|
case 's': |
| 1025 |
|
if(!strcmp(optarg, "cpu")){ |
| 1026 |
|
sortby_ptr=cmp_cpu_used; |
| 1120 |
|
cbreak(); |
| 1121 |
|
echo(); |
| 1122 |
|
window=newwin(0, 0, 0, 0); |
| 1123 |
< |
getmaxyx(window, maxy, maxx); |
| 1123 |
> |
getmaxyx(window, display_config.maxy, display_config.maxx); |
| 1124 |
|
|
| 1125 |
|
stdin_fileno=fileno(stdin); |
| 1126 |
|
data_fileno=fileno(data); |
| 1135 |
|
resizeterm(size.ws_row, size.ws_col); |
| 1136 |
|
wrefresh(curscr); |
| 1137 |
|
} |
| 1138 |
< |
getmaxyx(window, maxy, maxx); |
| 1138 |
> |
getmaxyx(window, display_config.maxy, display_config.maxx); |
| 1139 |
|
title=1; |
| 1140 |
< |
display(machine_data_list, &display_config, maxy, &title); |
| 1140 |
> |
display(machine_data_list, &display_config, &title); |
| 1141 |
|
refresh(); |
| 1142 |
|
continue; |
| 1143 |
|
} |
| 1153 |
|
endwin(); |
| 1154 |
|
exit(0); |
| 1155 |
|
break; |
| 1156 |
+ |
/* Units */ |
| 1157 |
+ |
case 'U': |
| 1158 |
+ |
case 'u': |
| 1159 |
+ |
if(display_config.units == 'b'){ |
| 1160 |
+ |
display_config.units = 'k'; |
| 1161 |
+ |
}else if(display_config.units == 'k'){ |
| 1162 |
+ |
display_config.units = 'm'; |
| 1163 |
+ |
}else{ |
| 1164 |
+ |
display_config.units = 'b'; |
| 1165 |
+ |
} |
| 1166 |
+ |
break; |
| 1167 |
|
|
| 1168 |
|
/* Sort by */ |
| 1169 |
|
case 'C': |
| 1294 |
|
num_hosts=parse_xml(response, &machine_data_list); |
| 1295 |
|
if(num_hosts==-1) continue; |
| 1296 |
|
machine_data_list=sort_machine_stats(machine_data_list, num_hosts, sortby_ptr); |
| 1297 |
< |
if(max_display==0){ |
| 1134 |
< |
display(machine_data_list, &display_config, maxy, &title); |
| 1135 |
< |
}else{ |
| 1136 |
< |
display(machine_data_list, &display_config, max_display, &title); |
| 1137 |
< |
} |
| 1297 |
> |
display(machine_data_list, &display_config, &title); |
| 1298 |
|
|
| 1299 |
|
} |
| 1300 |
|
exit(0); |