| 1 |
|
/* |
| 2 |
|
* i-scream central monitoring system |
| 3 |
< |
* http://www.i-scream.org.uk |
| 3 |
> |
* http://www.i-scream.org |
| 4 |
|
* Copyright (C) 2000-2002 i-scream |
| 5 |
|
* |
| 6 |
|
* This program is free software; you can redistribute it and/or |
| 26 |
|
#include <string.h> |
| 27 |
|
#include <sys/types.h> |
| 28 |
|
#include <sys/socket.h> |
| 29 |
+ |
#include <sys/ioctl.h> |
| 30 |
|
#include <unistd.h> |
| 31 |
|
#include <stdlib.h> |
| 32 |
|
#include <ukcprog.h> |
| 33 |
+ |
#include <netinet/in.h> |
| 34 |
+ |
#include <netdb.h> |
| 35 |
+ |
#include <sys/termios.h> |
| 36 |
+ |
#include <signal.h> |
| 37 |
+ |
#include <errno.h> |
| 38 |
|
|
| 39 |
|
#include <libxml/xmlmemory.h> |
| 40 |
|
#include <libxml/parser.h> |
| 148 |
|
|
| 149 |
|
#define SORTBYMAXNAME 128 |
| 150 |
|
typedef struct{ |
| 151 |
+ |
int maxx; |
| 152 |
+ |
int maxy; |
| 153 |
+ |
|
| 154 |
+ |
char units; |
| 155 |
+ |
|
| 156 |
|
int cpu_user; |
| 157 |
|
int cpu_idle; |
| 158 |
|
int cpu_iowait; |
| 177 |
|
int pages_in; |
| 178 |
|
int pages_out; |
| 179 |
|
|
| 180 |
< |
int processes_total; |
| 170 |
< |
int processes_sleeping; |
| 171 |
< |
int processes_cpu; |
| 172 |
< |
int processes_zombie; |
| 173 |
< |
int processes_stopped; |
| 180 |
> |
int processes; |
| 181 |
|
|
| 182 |
|
int network_io_total_tx; |
| 183 |
|
int network_io_total_rx; |
| 222 |
|
#define DISKIOW "DiskIO writes" |
| 223 |
|
#define DISKIO "Total DiskIO (reads+writes)" |
| 224 |
|
|
| 225 |
+ |
int sig_winch=0; |
| 226 |
|
|
| 219 |
– |
/* |
| 220 |
– |
int cmp_cpu(machine_data_list_t *a, machine_data_list_t *b){ |
| 221 |
– |
|
| 222 |
– |
if(a->cpu_used == b->cpu_used){ |
| 223 |
– |
if(a->load_1 == b->load_1) return 0; |
| 224 |
– |
if(a->load_1 > b->load_1){ |
| 225 |
– |
return -1; |
| 226 |
– |
}else{ |
| 227 |
– |
return 1; |
| 228 |
– |
} |
| 229 |
– |
} |
| 230 |
– |
|
| 231 |
– |
if((a->cpu_used) > (b->cpu_used)){ |
| 232 |
– |
return -1; |
| 233 |
– |
}else{ |
| 234 |
– |
return 1; |
| 235 |
– |
} |
| 236 |
– |
} |
| 237 |
– |
*/ |
| 238 |
– |
|
| 227 |
|
#ifndef HAVE_ATOLL |
| 228 |
|
long long int atoll (const char *nptr){ |
| 229 |
|
return strtoll (nptr, (char **) NULL, 10); |
| 414 |
|
machine_data_list->diskio_data_list=NULL; |
| 415 |
|
*md=machine_data_list; |
| 416 |
|
num_hosts++; |
| 417 |
+ |
} else { |
| 418 |
+ |
xmlFree(hostname); |
| 419 |
|
} |
| 420 |
|
|
| 421 |
|
/* Now we want to pull out the data */ |
| 663 |
|
|
| 664 |
|
} |
| 665 |
|
|
| 666 |
< |
void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int num_lines, int *title){ |
| 666 |
> |
void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int *title){ |
| 667 |
|
int line_num=4; |
| 668 |
|
int counter; |
| 669 |
|
int x=1; |
| 670 |
|
|
| 671 |
|
if(*title){ |
| 672 |
|
clear(); |
| 673 |
< |
move (num_lines-3, 1); |
| 673 |
> |
move (display_config->maxy-3, 1); |
| 674 |
|
printw("Sorting by %-64s", display_config->sortby); |
| 675 |
+ |
move (display_config->maxy-2, 1); |
| 676 |
+ |
if(display_config->units == 'b'){ |
| 677 |
+ |
printw("Units are measured in bytes/sec"); |
| 678 |
+ |
} |
| 679 |
+ |
if(display_config->units == 'k'){ |
| 680 |
+ |
printw("Units are measured in kilobytes/sec"); |
| 681 |
+ |
} |
| 682 |
+ |
if(display_config->units == 'm'){ |
| 683 |
+ |
printw("Units are measured in megabytes/sec"); |
| 684 |
+ |
} |
| 685 |
|
|
| 686 |
|
move(1,1); |
| 687 |
|
printw("%-11s", "Hostname"); |
| 688 |
|
x=x+11+1; |
| 689 |
< |
if(display_config->cpu_used){ |
| 689 |
> |
if(display_config->cpu_used && (display_config->maxx > x+6)){ |
| 690 |
|
move(1,x); |
| 691 |
|
printw("%5s", "CPU"); |
| 692 |
|
move(2,x); |
| 693 |
|
printw("%5s", "used%"); |
| 694 |
|
x+=6; |
| 695 |
|
} |
| 696 |
< |
if(display_config->load_1){ |
| 696 |
> |
if(display_config->load_1 && (display_config->maxx > x+6)){ |
| 697 |
|
move(1,x); |
| 698 |
|
printw("%5s", "Load"); |
| 699 |
|
move(2,x); |
| 700 |
|
printw("%5s", "(1m)"); |
| 701 |
|
x+=6; |
| 702 |
|
} |
| 703 |
< |
if(display_config->pages_in){ |
| 703 |
> |
|
| 704 |
> |
if(display_config->pages_in && (display_config->maxx > x+6)){ |
| 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){ |
| 711 |
> |
|
| 712 |
> |
if(display_config->pages_out && (display_config->maxx > x+6)){ |
| 713 |
|
move(1,x); |
| 714 |
|
printw("%5s", "Page"); |
| 715 |
|
move(2,x); |
| 716 |
|
printw("%5s", "outs"); |
| 717 |
|
x+=6; |
| 718 |
|
} |
| 719 |
< |
if(display_config->memory_used_pecent){ |
| 719 |
> |
|
| 720 |
> |
if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ |
| 721 |
|
move(1,x); |
| 722 |
|
printw("%5s", "Mem"); |
| 723 |
|
move(2,x); |
| 724 |
|
printw("%5s", "used"); |
| 725 |
|
x+=6; |
| 726 |
|
} |
| 727 |
< |
if(display_config->swap_used_pecent){ |
| 727 |
> |
|
| 728 |
> |
if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ |
| 729 |
|
move(1,x); |
| 730 |
|
printw("%5s", "Swap"); |
| 731 |
|
move(2,x); |
| 732 |
|
printw("%5s", "used"); |
| 733 |
|
x+=6; |
| 734 |
|
} |
| 735 |
< |
if(display_config->network_io_total_rx){ |
| 736 |
< |
move(1,x); |
| 737 |
< |
printw("%8s", "Net"); |
| 738 |
< |
move(2,x); |
| 739 |
< |
printw("%8s", "rx"); |
| 740 |
< |
x+=9; |
| 735 |
> |
|
| 736 |
> |
if(display_config->network_io_total_rx){ |
| 737 |
> |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
| 738 |
> |
move(1,x); |
| 739 |
> |
printw("%8s", "Net"); |
| 740 |
> |
move(2,x); |
| 741 |
> |
printw("%8s", "rx"); |
| 742 |
> |
x+=9; |
| 743 |
> |
} |
| 744 |
> |
|
| 745 |
> |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
| 746 |
> |
move(1,x); |
| 747 |
> |
printw("%5s", "Net"); |
| 748 |
> |
move(2,x); |
| 749 |
> |
printw("%5s", "rx"); |
| 750 |
> |
x+=6; |
| 751 |
> |
} |
| 752 |
> |
|
| 753 |
> |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
| 754 |
> |
move(1,x); |
| 755 |
> |
printw("%5s", "Net"); |
| 756 |
> |
move(2,x); |
| 757 |
> |
printw("%5s", "rx"); |
| 758 |
> |
x+=6; |
| 759 |
> |
} |
| 760 |
> |
|
| 761 |
|
} |
| 762 |
+ |
|
| 763 |
|
if(display_config->network_io_total_tx){ |
| 764 |
< |
move(1,x); |
| 765 |
< |
printw("%8s", "Net"); |
| 766 |
< |
move(2,x); |
| 767 |
< |
printw("%8s", "tx"); |
| 768 |
< |
x+=9; |
| 764 |
> |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
| 765 |
> |
move(1,x); |
| 766 |
> |
printw("%8s", "Net"); |
| 767 |
> |
move(2,x); |
| 768 |
> |
printw("%8s", "tx"); |
| 769 |
> |
x+=9; |
| 770 |
> |
} |
| 771 |
> |
|
| 772 |
> |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
| 773 |
> |
move(1,x); |
| 774 |
> |
printw("%5s", "Net"); |
| 775 |
> |
move(2,x); |
| 776 |
> |
printw("%5s", "tx"); |
| 777 |
> |
x+=6; |
| 778 |
> |
} |
| 779 |
> |
|
| 780 |
> |
if(display_config->units=='m' && (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 |
> |
|
| 788 |
|
} |
| 789 |
+ |
|
| 790 |
|
if(display_config->disk_io_total_read){ |
| 791 |
< |
move(1,x); |
| 792 |
< |
printw("%9s", "Disk"); |
| 793 |
< |
move(2,x); |
| 794 |
< |
printw("%9s", "read"); |
| 795 |
< |
x+=10; |
| 791 |
> |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
| 792 |
> |
move(1,x); |
| 793 |
> |
printw("%9s", "Disk"); |
| 794 |
> |
move(2,x); |
| 795 |
> |
printw("%9s", "read"); |
| 796 |
> |
x+=10; |
| 797 |
> |
} |
| 798 |
> |
|
| 799 |
> |
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
| 800 |
> |
move(1,x); |
| 801 |
> |
printw("%6s", "Disk"); |
| 802 |
> |
move(2,x); |
| 803 |
> |
printw("%6s", "read"); |
| 804 |
> |
x+=7; |
| 805 |
> |
} |
| 806 |
> |
|
| 807 |
> |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
| 808 |
> |
move(1,x); |
| 809 |
> |
printw("%6s", "Disk"); |
| 810 |
> |
move(2,x); |
| 811 |
> |
printw("%6s", "read"); |
| 812 |
> |
x+=7; |
| 813 |
> |
} |
| 814 |
> |
|
| 815 |
|
} |
| 816 |
+ |
|
| 817 |
|
if(display_config->disk_io_total_read){ |
| 818 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
| 819 |
+ |
move(1,x); |
| 820 |
+ |
printw("%9s", "Disk"); |
| 821 |
+ |
move(2,x); |
| 822 |
+ |
printw("%9s", "write"); |
| 823 |
+ |
x+=10; |
| 824 |
+ |
} |
| 825 |
+ |
|
| 826 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
| 827 |
+ |
move(1,x); |
| 828 |
+ |
printw("%6s", "Disk"); |
| 829 |
+ |
move(2,x); |
| 830 |
+ |
printw("%6s", "write"); |
| 831 |
+ |
x+=7; |
| 832 |
+ |
} |
| 833 |
+ |
|
| 834 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
| 835 |
+ |
move(1,x); |
| 836 |
+ |
printw("%6s", "Disk"); |
| 837 |
+ |
move(2,x); |
| 838 |
+ |
printw("%6s", "write"); |
| 839 |
+ |
x+=7; |
| 840 |
+ |
} |
| 841 |
+ |
|
| 842 |
+ |
} |
| 843 |
+ |
|
| 844 |
+ |
if(display_config->processes && (display_config->maxx > x+25)){ |
| 845 |
|
move(1,x); |
| 846 |
< |
printw("%9s", "Disk"); |
| 846 |
> |
printw("%-24s", " Number of Process"); |
| 847 |
|
move(2,x); |
| 848 |
< |
printw("%9s", "write"); |
| 849 |
< |
x+=10; |
| 850 |
< |
} |
| 851 |
< |
|
| 848 |
> |
printw("%-24s", " Run Slep Zomb Stop Tot"); |
| 849 |
> |
x+=25; |
| 850 |
> |
} |
| 851 |
> |
|
| 852 |
|
*title=0; |
| 853 |
|
} |
| 854 |
|
|
| 855 |
|
/* Counter starts at 8, for padding (eg, headers, borders etc) */ |
| 856 |
< |
for(counter=8;counter<num_lines;counter++){ |
| 856 |
> |
for(counter=8;counter<display_config->maxy;counter++){ |
| 857 |
|
if(machine_data_list==NULL) break; |
| 858 |
|
move(line_num++, 1); |
| 859 |
|
printw("%-11s", machine_data_list->sysname); |
| 860 |
+ |
x=13; |
| 861 |
|
|
| 862 |
< |
if(display_config->cpu_used) printw(" %5.1f", machine_data_list->cpu_used); |
| 863 |
< |
if(display_config->load_1) printw(" %5.1f", machine_data_list->load_1); |
| 864 |
< |
if(display_config->pages_in) printw(" %5d", machine_data_list->pages_in); |
| 865 |
< |
if(display_config->pages_out) printw(" %5d", machine_data_list->pages_out); |
| 866 |
< |
if(display_config->memory_used_pecent) printw(" %5.1f", machine_data_list->memory_used_pecent); |
| 867 |
< |
if(display_config->swap_used_pecent) printw(" %5.1f", machine_data_list->swap_used_pecent); |
| 868 |
< |
if(display_config->network_io_total_rx) printw(" %8lld", machine_data_list->network_io_total_rx); |
| 869 |
< |
if(display_config->network_io_total_tx) printw(" %8lld", machine_data_list->network_io_total_tx); |
| 870 |
< |
if(display_config->disk_io_total_read) printw(" %9lld", machine_data_list->disk_io_total_read); |
| 871 |
< |
if(display_config->disk_io_total_write) printw(" %9lld", machine_data_list->disk_io_total_write); |
| 862 |
> |
if(display_config->cpu_used && (display_config->maxx > x+6)){ |
| 863 |
> |
printw(" %5.1f", machine_data_list->cpu_used); |
| 864 |
> |
x+=6; |
| 865 |
> |
} |
| 866 |
> |
if(display_config->load_1 && (display_config->maxx > x+6)){ |
| 867 |
> |
printw(" %5.1f", machine_data_list->load_1); |
| 868 |
> |
x+=6; |
| 869 |
> |
} |
| 870 |
> |
if(display_config->pages_in && (display_config->maxx > x+6)){ |
| 871 |
> |
printw(" %5d", machine_data_list->pages_in); |
| 872 |
> |
x+=6; |
| 873 |
> |
} |
| 874 |
> |
if(display_config->pages_out && (display_config->maxx > x+6)){ |
| 875 |
> |
printw(" %5d", machine_data_list->pages_out); |
| 876 |
> |
x+=6; |
| 877 |
> |
} |
| 878 |
> |
if(display_config->memory_used_pecent && (display_config->maxx > x+6)){ |
| 879 |
> |
printw(" %5.1f", machine_data_list->memory_used_pecent); |
| 880 |
> |
x+=6; |
| 881 |
> |
} |
| 882 |
> |
if(display_config->swap_used_pecent && (display_config->maxx > x+6)){ |
| 883 |
> |
printw(" %5.1f", machine_data_list->swap_used_pecent); |
| 884 |
> |
x+=6; |
| 885 |
> |
} |
| 886 |
|
|
| 887 |
+ |
if(display_config->network_io_total_rx){ |
| 888 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
| 889 |
+ |
printw(" %8lld", machine_data_list->network_io_total_rx); |
| 890 |
+ |
x+=9; |
| 891 |
+ |
} |
| 892 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
| 893 |
+ |
printw(" %5lld", machine_data_list->network_io_total_rx/1024); |
| 894 |
+ |
x+=6; |
| 895 |
+ |
} |
| 896 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
| 897 |
+ |
printw(" %5.2f", (double)(machine_data_list->network_io_total_rx/(1024.00*1024.00))); |
| 898 |
+ |
x+=6; |
| 899 |
+ |
} |
| 900 |
+ |
} |
| 901 |
+ |
|
| 902 |
+ |
if(display_config->network_io_total_tx){ |
| 903 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+9)){ |
| 904 |
+ |
printw(" %8lld", machine_data_list->network_io_total_tx); |
| 905 |
+ |
x+=9; |
| 906 |
+ |
} |
| 907 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+6)){ |
| 908 |
+ |
printw(" %5lld", machine_data_list->network_io_total_tx/1024); |
| 909 |
+ |
x+=6; |
| 910 |
+ |
} |
| 911 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+6)){ |
| 912 |
+ |
printw(" %5.2f", (double)(machine_data_list->network_io_total_tx/(1024.00*1024.00))); |
| 913 |
+ |
x+=6; |
| 914 |
+ |
} |
| 915 |
+ |
} |
| 916 |
+ |
|
| 917 |
+ |
if(display_config->disk_io_total_read){ |
| 918 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
| 919 |
+ |
printw(" %9lld", machine_data_list->disk_io_total_read); |
| 920 |
+ |
x+=10; |
| 921 |
+ |
} |
| 922 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
| 923 |
+ |
printw(" %6lld", machine_data_list->disk_io_total_read/1024); |
| 924 |
+ |
x+=7; |
| 925 |
+ |
} |
| 926 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
| 927 |
+ |
printw(" %6.2f", (double)(machine_data_list->disk_io_total_read/(1024.00*1024.00))); |
| 928 |
+ |
x+=7; |
| 929 |
+ |
} |
| 930 |
+ |
} |
| 931 |
+ |
|
| 932 |
+ |
if(display_config->disk_io_total_write){ |
| 933 |
+ |
if(display_config->units=='b' && (display_config->maxx > x+10)){ |
| 934 |
+ |
printw(" %9lld", machine_data_list->disk_io_total_write); |
| 935 |
+ |
x+=10; |
| 936 |
+ |
} |
| 937 |
+ |
if(display_config->units=='k' && (display_config->maxx > x+7)){ |
| 938 |
+ |
printw(" %6lld", machine_data_list->disk_io_total_write/1024); |
| 939 |
+ |
x+=7; |
| 940 |
+ |
} |
| 941 |
+ |
if(display_config->units=='m' && (display_config->maxx > x+7)){ |
| 942 |
+ |
printw(" %6.2f", (double)(machine_data_list->disk_io_total_write/(1024.00*1024.00))); |
| 943 |
+ |
x+=7; |
| 944 |
+ |
} |
| 945 |
+ |
} |
| 946 |
+ |
if(display_config->processes && display_config->maxx > x+25){ |
| 947 |
+ |
printw(" %4d %4d %4d %4d %4d", machine_data_list->processes_cpu, \ |
| 948 |
+ |
machine_data_list->processes_sleeping, \ |
| 949 |
+ |
machine_data_list->processes_zombie, \ |
| 950 |
+ |
machine_data_list->processes_stopped, \ |
| 951 |
+ |
machine_data_list->processes_total); |
| 952 |
+ |
x+=25; |
| 953 |
+ |
} |
| 954 |
+ |
|
| 955 |
|
machine_data_list=machine_data_list->next; |
| 956 |
|
} |
| 957 |
|
|
| 960 |
|
|
| 961 |
|
} |
| 962 |
|
|
| 963 |
+ |
void sig_winch_handler(int sig){ |
| 964 |
+ |
|
| 965 |
+ |
sig_winch=1; |
| 966 |
+ |
signal(SIGWINCH, sig_winch_handler); |
| 967 |
+ |
} |
| 968 |
+ |
|
| 969 |
+ |
void usage() { |
| 970 |
+ |
printf("Usage: idar [-o order] [-s server] [-p port] [-l list] [-h]\n\n"); |
| 971 |
+ |
printf(" -o Sets the initial sort order. Accepted arguments are one of:\n"); |
| 972 |
+ |
printf(" cpu load mem swap net disk\n"); |
| 973 |
+ |
printf(" -s Specifies the i-scream server to connect to.\n"); |
| 974 |
+ |
printf(" default: %s\n", DEF_SERVER_NAME); |
| 975 |
+ |
printf(" -p Specifies the i-scream server port.\n"); |
| 976 |
+ |
printf(" default: %d\n", DEF_SERVER_PORT); |
| 977 |
+ |
printf(" -l Sets the list of hosts to monitor in a semi-colon separated list.\n"); |
| 978 |
+ |
printf(" -h Displays this help information.\n"); |
| 979 |
+ |
printf("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
| 980 |
+ |
exit(1); |
| 981 |
+ |
} |
| 982 |
+ |
|
| 983 |
|
int main(int argc, char **argv){ |
| 984 |
|
WINDOW *window; |
| 985 |
|
fd_set infds; |
| 986 |
< |
int maxx, maxy; |
| 986 |
> |
struct winsize size; |
| 987 |
|
|
| 988 |
|
FILE *control; |
| 989 |
|
FILE *data; |
| 991 |
|
char *machine_list=NULL; |
| 992 |
|
char *response=NULL; |
| 993 |
|
|
| 994 |
< |
char *servername; |
| 994 |
> |
char *server_name; |
| 995 |
|
int server_control_port; |
| 996 |
|
int server_data_port; |
| 997 |
|
|
| 998 |
|
machine_data_list_t *machine_data_list=NULL; |
| 999 |
|
|
| 1000 |
|
int num_hosts; |
| 806 |
– |
int max_display=0; |
| 1001 |
|
int title=1; |
| 1002 |
|
|
| 1003 |
|
int cmdopt; |
| 1004 |
|
extern int optind; |
| 1005 |
|
extern char *optarg; |
| 1006 |
+ |
|
| 1007 |
+ |
extern int errno; |
| 1008 |
|
|
| 1009 |
|
display_config_t display_config; |
| 1010 |
|
char ch; |
| 1014 |
|
sortby_ptr=NULL; |
| 1015 |
|
|
| 1016 |
|
/* What to display defaults */ |
| 1017 |
+ |
display_config.units='b'; |
| 1018 |
+ |
|
| 1019 |
|
display_config.cpu_user=0; |
| 1020 |
|
display_config.cpu_idle=0; |
| 1021 |
|
display_config.cpu_iowait=0; |
| 1040 |
|
display_config.pages_in=1; |
| 1041 |
|
display_config.pages_out=1; |
| 1042 |
|
|
| 1043 |
< |
display_config.processes_total=0; |
| 846 |
< |
display_config.processes_sleeping=0; |
| 847 |
< |
display_config.processes_cpu=0; |
| 848 |
< |
display_config.processes_zombie=0; |
| 849 |
< |
display_config.processes_stopped=0; |
| 1043 |
> |
display_config.processes=1; |
| 1044 |
|
|
| 1045 |
|
display_config.network_io_total_tx=1; |
| 1046 |
|
display_config.network_io_total_rx=1; |
| 1051 |
|
display_config.disk_io_all_stats=0; |
| 1052 |
|
|
| 1053 |
|
display_config.disk_total_used=0; |
| 1054 |
< |
display_config.disk_all_stats=0; |
| 1054 |
> |
display_config.disk_all_stats=0; |
| 1055 |
|
|
| 1056 |
< |
while((cmdopt=getopt(argc, argv, "d:s:")) != -1){ |
| 1056 |
> |
signal(SIGWINCH, sig_winch_handler); |
| 1057 |
> |
|
| 1058 |
> |
server_name=DEF_SERVER_NAME; |
| 1059 |
> |
server_control_port=DEF_SERVER_PORT; |
| 1060 |
> |
|
| 1061 |
> |
while((cmdopt=getopt(argc, argv, "o:s:p:l:h")) != -1){ |
| 1062 |
|
switch(cmdopt){ |
| 1063 |
< |
case 'd': |
| 865 |
< |
max_display=atoi(optarg); |
| 866 |
< |
break; |
| 867 |
< |
case 's': |
| 1063 |
> |
case 'o': |
| 1064 |
|
if(!strcmp(optarg, "cpu")){ |
| 1065 |
|
sortby_ptr=cmp_cpu_used; |
| 1066 |
|
strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); |
| 1074 |
|
strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); |
| 1075 |
|
} |
| 1076 |
|
if(!strcmp(optarg, "swap")){ |
| 1077 |
< |
sortby_ptr=cmp_swap_used_pecent; |
| 1078 |
< |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
| 1079 |
< |
} |
| 1077 |
> |
sortby_ptr=cmp_swap_used_pecent; |
| 1078 |
> |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
| 1079 |
> |
} |
| 1080 |
> |
if(!strcmp(optarg, "net")){ |
| 1081 |
> |
sortby_ptr=cmp_network_io_total; |
| 1082 |
> |
strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME); |
| 1083 |
> |
} |
| 1084 |
> |
if(!strcmp(optarg, "disk")){ |
| 1085 |
> |
sortby_ptr=cmp_disk_io_total; |
| 1086 |
> |
strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME); |
| 1087 |
> |
} |
| 1088 |
|
if(sortby_ptr==NULL){ |
| 1089 |
< |
errf("Invalid sort type"); |
| 1090 |
< |
exit(1); |
| 1089 |
> |
errf("Invalid order given."); |
| 1090 |
> |
usage(); |
| 1091 |
|
} |
| 1092 |
< |
break; |
| 1092 |
> |
break; |
| 1093 |
> |
case 's': |
| 1094 |
> |
server_name=optarg; |
| 1095 |
> |
break; |
| 1096 |
> |
case 'p': |
| 1097 |
> |
server_control_port=atoi(optarg); |
| 1098 |
> |
break; |
| 1099 |
> |
case 'l': |
| 1100 |
> |
/* We've been passed a machine list */ |
| 1101 |
> |
/* list currently needs to be ; seperated */ |
| 1102 |
> |
machine_list=strdup(optarg); |
| 1103 |
> |
break; |
| 1104 |
> |
case 'h': |
| 1105 |
> |
default: |
| 1106 |
> |
usage(); |
| 1107 |
> |
break; |
| 1108 |
|
} |
| 1109 |
|
} |
| 1110 |
|
|
| 1111 |
+ |
/* Don't take any other arguments */ |
| 1112 |
+ |
if(argc>optind){ |
| 1113 |
+ |
usage(); |
| 1114 |
+ |
} |
| 1115 |
+ |
|
| 1116 |
|
if(sortby_ptr==NULL){ |
| 1117 |
|
sortby_ptr=cmp_cpu_used; |
| 1118 |
|
strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME); |
| 1119 |
|
} |
| 1120 |
|
|
| 1121 |
< |
if(argc<(optind+2)){ |
| 898 |
< |
printf("Usage is %s <-d lines> hostname port <machine list>\n", argv[0]); |
| 899 |
< |
exit(1); |
| 900 |
< |
} |
| 901 |
< |
|
| 902 |
< |
servername=argv[optind]; |
| 903 |
< |
server_control_port=atoi(argv[optind+1]); |
| 904 |
< |
|
| 905 |
< |
control=create_tcp_connection(servername, server_control_port); |
| 1121 |
> |
control=create_tcp_connection(server_name, server_control_port); |
| 1122 |
|
if(control==NULL){ |
| 1123 |
|
errf("Failed to connect (%m)"); |
| 1124 |
+ |
exit(1); |
| 1125 |
|
} |
| 1126 |
|
|
| 910 |
– |
if(argc==4){ |
| 911 |
– |
/* We've been passed a machine list */ |
| 912 |
– |
/* list currently needs to be ; seperated */ |
| 913 |
– |
machine_list=strdup(argv[3]); |
| 914 |
– |
} |
| 915 |
– |
|
| 1127 |
|
if((tcp_comm(control, NULL, &response, "PROTOCOL 1.1"))!=0){ |
| 1128 |
|
errf("Incorrect version number (%s)", response); |
| 1129 |
|
exit(1); |
| 1156 |
|
exit(1); |
| 1157 |
|
} |
| 1158 |
|
|
| 1159 |
< |
data=create_tcp_connection(servername, server_data_port); |
| 1159 |
> |
data=create_tcp_connection(server_name, server_data_port); |
| 1160 |
|
if(data==NULL){ |
| 1161 |
< |
errf("Failed to connect to host %s on port %d (%m)",servername, server_data_port); |
| 1161 |
> |
errf("Failed to connect to host %s on port %d (%m)",server_name, server_data_port); |
| 1162 |
> |
exit(1); |
| 1163 |
|
} |
| 1164 |
|
|
| 953 |
– |
/* |
| 954 |
– |
printf("\033[2J"); |
| 955 |
– |
printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); |
| 956 |
– |
printf("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
| 957 |
– |
*/ |
| 958 |
– |
|
| 1165 |
|
initscr(); |
| 1166 |
|
nonl(); |
| 1167 |
|
cbreak(); |
| 1168 |
< |
echo(); |
| 1168 |
> |
noecho(); |
| 1169 |
|
window=newwin(0, 0, 0, 0); |
| 1170 |
< |
getmaxyx(window, maxy, maxx); |
| 1170 |
> |
getmaxyx(window, display_config.maxy, display_config.maxx); |
| 1171 |
|
|
| 1172 |
|
stdin_fileno=fileno(stdin); |
| 1173 |
|
data_fileno=fileno(data); |
| 1177 |
|
FD_ZERO(&infds); |
| 1178 |
|
FD_SET(stdin_fileno, &infds); |
| 1179 |
|
FD_SET(data_fileno, &infds); |
| 1180 |
< |
select(biggest_fileno, &infds, NULL, NULL, NULL); |
| 1180 |
> |
if((select(biggest_fileno, &infds, NULL, NULL, NULL))==-1){ |
| 1181 |
> |
if(errno!=EINTR){ |
| 1182 |
> |
errf("select failed with (%m)"); |
| 1183 |
> |
exit(1); |
| 1184 |
> |
} |
| 1185 |
> |
} |
| 1186 |
> |
|
| 1187 |
> |
if(sig_winch){ |
| 1188 |
> |
if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { |
| 1189 |
> |
resizeterm(size.ws_row, size.ws_col); |
| 1190 |
> |
wrefresh(curscr); |
| 1191 |
> |
} |
| 1192 |
> |
getmaxyx(window, display_config.maxy, display_config.maxx); |
| 1193 |
> |
title=1; |
| 1194 |
> |
display(machine_data_list, &display_config, &title); |
| 1195 |
> |
refresh(); |
| 1196 |
> |
sig_winch=0; |
| 1197 |
> |
continue; |
| 1198 |
> |
} |
| 1199 |
|
|
| 1200 |
|
if(FD_ISSET(stdin_fileno, &infds)){ |
| 1201 |
|
|
| 1202 |
< |
ch=getc(stdin); |
| 1202 |
> |
ch=getch(); |
| 1203 |
|
switch(ch){ |
| 1204 |
+ |
case KEY_RESIZE: |
| 1205 |
+ |
sig_winch=1; |
| 1206 |
+ |
break; |
| 1207 |
|
|
| 1208 |
|
/* Quit */ |
| 1209 |
|
case 'Q': |
| 1211 |
|
endwin(); |
| 1212 |
|
exit(0); |
| 1213 |
|
break; |
| 1214 |
+ |
/* Units */ |
| 1215 |
+ |
case 'U': |
| 1216 |
+ |
case 'u': |
| 1217 |
+ |
if(display_config.units == 'b'){ |
| 1218 |
+ |
display_config.units = 'k'; |
| 1219 |
+ |
}else if(display_config.units == 'k'){ |
| 1220 |
+ |
display_config.units = 'm'; |
| 1221 |
+ |
}else{ |
| 1222 |
+ |
display_config.units = 'b'; |
| 1223 |
+ |
} |
| 1224 |
+ |
break; |
| 1225 |
|
|
| 1226 |
|
/* Sort by */ |
| 1227 |
|
case 'C': |
| 1327 |
|
display_config.cpu_used=1; |
| 1328 |
|
} |
| 1329 |
|
break; |
| 1330 |
+ |
case 'r': |
| 1331 |
+ |
if(display_config.processes){ |
| 1332 |
+ |
display_config.processes=0; |
| 1333 |
+ |
}else{ |
| 1334 |
+ |
display_config.processes=1; |
| 1335 |
+ |
} |
| 1336 |
+ |
break; |
| 1337 |
|
|
| 1338 |
|
default: |
| 1339 |
< |
/* Invalid key.. Ignore.. Set Title to -1, as the |
| 1095 |
< |
* title++ will then make that "0" (false) so a |
| 1096 |
< |
* screen redraw will not happen */ |
| 1097 |
< |
title=-1; |
| 1098 |
< |
break; |
| 1339 |
> |
continue; |
| 1340 |
|
} |
| 1341 |
|
|
| 1342 |
|
/* Increment title so it becomes true (and making the screen update */ |
| 1355 |
|
num_hosts=parse_xml(response, &machine_data_list); |
| 1356 |
|
if(num_hosts==-1) continue; |
| 1357 |
|
machine_data_list=sort_machine_stats(machine_data_list, num_hosts, sortby_ptr); |
| 1358 |
< |
if(max_display==0){ |
| 1118 |
< |
display(machine_data_list, &display_config, maxy, &title); |
| 1119 |
< |
}else{ |
| 1120 |
< |
display(machine_data_list, &display_config, max_display, &title); |
| 1121 |
< |
} |
| 1358 |
> |
display(machine_data_list, &display_config, &title); |
| 1359 |
|
|
| 1360 |
|
} |
| 1361 |
|
exit(0); |