| 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; |
| 45 |
|
int line; |
| 586 |
|
int x=1; |
| 587 |
|
|
| 588 |
|
if(*title){ |
| 589 |
< |
printf("\033[2J"); |
| 589 |
> |
// printf("\033[2J"); |
| 590 |
|
// printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); |
| 591 |
< |
// printf("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
| 592 |
< |
printf("\033[1;1H%-11s", "Hostname"); |
| 591 |
> |
// printw("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
| 592 |
> |
move(1,1); |
| 593 |
> |
printw("%-11s", "Hostname"); |
| 594 |
|
x=x+11+1; |
| 595 |
|
if(display_config->cpu_used){ |
| 596 |
< |
printf("\033[1;%dH%5s", x, "CPU"); |
| 597 |
< |
printf("\033[2;%dH%5s", x, "used%"); |
| 596 |
> |
move(1,x); |
| 597 |
> |
printw("%5s", "CPU"); |
| 598 |
> |
move(2,x); |
| 599 |
> |
printw("%5s", "used%"); |
| 600 |
|
x+=6; |
| 601 |
|
} |
| 602 |
|
if(display_config->load_1){ |
| 603 |
< |
printf("\033[1;%dH%5s", x, "Load"); |
| 604 |
< |
printf("\033[2;%dH%5s", x, "(1m)"); |
| 603 |
> |
move(1,x); |
| 604 |
> |
printw("%5s", "Load"); |
| 605 |
> |
move(2,x); |
| 606 |
> |
printw("%5s", "(1m)"); |
| 607 |
|
x+=6; |
| 608 |
|
} |
| 609 |
|
if(display_config->pages_in){ |
| 610 |
< |
printf("\033[1;%dH%5s", x, "Page"); |
| 611 |
< |
printf("\033[2;%dH%5s", x, "ins"); |
| 610 |
> |
move(1,x); |
| 611 |
> |
printw("%5s", "Page"); |
| 612 |
> |
move(2,x); |
| 613 |
> |
printw("%5s", "ins"); |
| 614 |
|
x+=6; |
| 615 |
|
} |
| 616 |
|
if(display_config->pages_out){ |
| 617 |
< |
printf("\033[1;%dH%5s", x, "Page"); |
| 618 |
< |
printf("\033[2;%dH%5s", x, "outs"); |
| 617 |
> |
move(1,x); |
| 618 |
> |
printw("%5s", "Page"); |
| 619 |
> |
move(2,x); |
| 620 |
> |
printw("%5s", "outs"); |
| 621 |
|
x+=6; |
| 622 |
|
} |
| 623 |
|
if(display_config->memory_used_pecent){ |
| 624 |
< |
printf("\033[1;%dH%5s", x, "Mem"); |
| 625 |
< |
printf("\033[2;%dH%5s", x, "used"); |
| 624 |
> |
move(1,x); |
| 625 |
> |
printw("%5s", "Mem"); |
| 626 |
> |
move(2,x); |
| 627 |
> |
printw("%5s", "used"); |
| 628 |
|
x+=6; |
| 629 |
|
} |
| 630 |
|
if(display_config->swap_used_pecent){ |
| 631 |
< |
printf("\033[1;%dH%5s", x, "Swap"); |
| 632 |
< |
printf("\033[2;%dH%5s", x, "used"); |
| 631 |
> |
move(1,x); |
| 632 |
> |
printw("%5s", "Swap"); |
| 633 |
> |
move(2,x); |
| 634 |
> |
printw("%5s", "used"); |
| 635 |
|
x+=6; |
| 636 |
|
} |
| 637 |
|
if(display_config->network_io_total_rx){ |
| 638 |
< |
printf("\033[1;%dH%8s", x, "Net"); |
| 639 |
< |
printf("\033[2;%dH%8s", x, "rx"); |
| 638 |
> |
move(1,x); |
| 639 |
> |
printw("%8s", "Net"); |
| 640 |
> |
move(2,x); |
| 641 |
> |
printw("%8s", "rx"); |
| 642 |
|
x+=9; |
| 643 |
|
} |
| 644 |
|
if(display_config->network_io_total_tx){ |
| 645 |
< |
printf("\033[1;%dH%8s", x, "Net"); |
| 646 |
< |
printf("\033[2;%dH%8s", x, "tx"); |
| 645 |
> |
move(1,x); |
| 646 |
> |
printw("%8s", "Net"); |
| 647 |
> |
move(2,x); |
| 648 |
> |
printw("%8s", "tx"); |
| 649 |
|
x+=9; |
| 650 |
|
} |
| 651 |
|
if(display_config->disk_io_total_read){ |
| 652 |
< |
printf("\033[1;%dH%9s", x, "Disk"); |
| 653 |
< |
printf("\033[2;%dH%9s", x, "read"); |
| 652 |
> |
move(1,x); |
| 653 |
> |
printw("%9s", "Disk"); |
| 654 |
> |
move(2,x); |
| 655 |
> |
printw("%9s", "read"); |
| 656 |
|
x+=10; |
| 657 |
|
} |
| 658 |
|
if(display_config->disk_io_total_read){ |
| 659 |
< |
printf("\033[1;%dH%9s", x, "Disk"); |
| 660 |
< |
printf("\033[2;%dH%9s", x, "write"); |
| 659 |
> |
move(1,x); |
| 660 |
> |
printw("%9s", "Disk"); |
| 661 |
> |
move(2,x); |
| 662 |
> |
printw("%9s", "write"); |
| 663 |
|
x+=10; |
| 664 |
|
} |
| 665 |
|
|
| 668 |
|
|
| 669 |
|
for(;num_lines;num_lines--){ |
| 670 |
|
if(machine_data_list==NULL) break; |
| 671 |
+ |
move(line_num++, 1); |
| 672 |
+ |
printw("%-11s", machine_data_list->sysname); |
| 673 |
|
|
| 674 |
< |
printf("\033[%d;%dH%-11s", line_num++, 1, machine_data_list->sysname); |
| 674 |
> |
if(display_config->cpu_used) printw(" %5.1f", machine_data_list->cpu_used); |
| 675 |
> |
if(display_config->load_1) printw(" %5.1f", machine_data_list->load_1); |
| 676 |
> |
if(display_config->pages_in) printw(" %5d", machine_data_list->pages_in); |
| 677 |
> |
if(display_config->pages_out) printw(" %5d", machine_data_list->pages_out); |
| 678 |
> |
if(display_config->memory_used_pecent) printw(" %5.1f", machine_data_list->memory_used_pecent); |
| 679 |
> |
if(display_config->swap_used_pecent) printw(" %5.1f", machine_data_list->swap_used_pecent); |
| 680 |
> |
if(display_config->network_io_total_rx) printw(" %8lld", machine_data_list->network_io_total_rx); |
| 681 |
> |
if(display_config->network_io_total_tx) printw(" %8lld", machine_data_list->network_io_total_tx); |
| 682 |
> |
if(display_config->disk_io_total_read) printw(" %9lld", machine_data_list->disk_io_total_read); |
| 683 |
> |
if(display_config->disk_io_total_write) printw(" %9lld", machine_data_list->disk_io_total_write); |
| 684 |
|
|
| 647 |
– |
if(display_config->cpu_used) printf(" %5.1f", machine_data_list->cpu_used); |
| 648 |
– |
if(display_config->load_1) printf(" %5.1f", machine_data_list->load_1); |
| 649 |
– |
if(display_config->pages_in) printf(" %5d", machine_data_list->pages_in); |
| 650 |
– |
if(display_config->pages_out) printf(" %5d", machine_data_list->pages_out); |
| 651 |
– |
if(display_config->memory_used_pecent) printf(" %5.1f", machine_data_list->memory_used_pecent); |
| 652 |
– |
if(display_config->swap_used_pecent) printf(" %5.1f", machine_data_list->swap_used_pecent); |
| 653 |
– |
if(display_config->network_io_total_rx) printf(" %8lld", machine_data_list->network_io_total_rx); |
| 654 |
– |
if(display_config->network_io_total_tx) printf(" %8lld", machine_data_list->network_io_total_tx); |
| 655 |
– |
if(display_config->disk_io_total_read) printf(" %9lld", machine_data_list->disk_io_total_read); |
| 656 |
– |
if(display_config->disk_io_total_write) printf(" %9lld", machine_data_list->disk_io_total_write); |
| 657 |
– |
|
| 685 |
|
machine_data_list=machine_data_list->next; |
| 686 |
|
} |
| 687 |
|
|
| 688 |
|
|
| 689 |
< |
fflush(stdout); |
| 689 |
> |
refresh(); |
| 690 |
|
|
| 691 |
|
} |
| 692 |
|
|
| 693 |
|
int main(int argc, char **argv){ |
| 694 |
+ |
WINDOW *window; |
| 695 |
+ |
fd_set infds; |
| 696 |
+ |
|
| 697 |
|
FILE *control; |
| 698 |
|
FILE *data; |
| 699 |
|
|
| 713 |
|
int cmdopt; |
| 714 |
|
extern int optind; |
| 715 |
|
extern char *optarg; |
| 686 |
– |
sortby_ptr=NULL; |
| 716 |
|
|
| 717 |
|
display_config_t display_config; |
| 718 |
+ |
char ch; |
| 719 |
|
|
| 720 |
+ |
int data_fileno, stdin_fileno, biggest_fileno; |
| 721 |
+ |
|
| 722 |
+ |
sortby_ptr=NULL; |
| 723 |
+ |
|
| 724 |
|
/* What to display defaults */ |
| 725 |
|
display_config.cpu_user=0; |
| 726 |
|
display_config.cpu_idle=0; |
| 756 |
|
display_config.network_io_total_rx=1; |
| 757 |
|
display_config.network_all_stats=1; |
| 758 |
|
|
| 759 |
< |
display_config.disk_io_total_write=1; |
| 760 |
< |
display_config.disk_io_total_read=1; |
| 759 |
> |
display_config.disk_io_total_write=0; |
| 760 |
> |
display_config.disk_io_total_read=0; |
| 761 |
|
display_config.disk_io_all_stats=0; |
| 762 |
|
|
| 763 |
|
display_config.disk_total_used=0; |
| 764 |
|
display_config.disk_all_stats=0; |
| 765 |
|
|
| 732 |
– |
|
| 766 |
|
while((cmdopt=getopt(argc, argv, "d:s:")) != -1){ |
| 767 |
|
switch(cmdopt){ |
| 768 |
|
case 'd': |
| 849 |
|
printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); |
| 850 |
|
printf("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
| 851 |
|
*/ |
| 852 |
< |
fflush(stdout); |
| 852 |
> |
|
| 853 |
> |
initscr(); |
| 854 |
> |
nonl(); |
| 855 |
> |
cbreak(); |
| 856 |
> |
echo(); |
| 857 |
> |
window=newwin(0, 0, 0, 0); |
| 858 |
> |
|
| 859 |
> |
stdin_fileno=fileno(stdin); |
| 860 |
> |
data_fileno=fileno(data); |
| 861 |
> |
biggest_fileno=(data_fileno>stdin_fileno) ? (data_fileno+1) : (stdin_fileno+1); |
| 862 |
> |
|
| 863 |
|
for(;;){ |
| 864 |
< |
response=fpgetline(data); |
| 865 |
< |
if (response==NULL){ |
| 866 |
< |
errf("Failed to read data (%m)"); |
| 867 |
< |
exit(1); |
| 864 |
> |
FD_ZERO(&infds); |
| 865 |
> |
FD_SET(stdin_fileno, &infds); |
| 866 |
> |
FD_SET(data_fileno, &infds); |
| 867 |
> |
select(biggest_fileno, &infds, NULL, NULL, NULL); |
| 868 |
> |
|
| 869 |
> |
if(FD_ISSET(stdin_fileno, &infds)){ |
| 870 |
> |
|
| 871 |
> |
ch=getc(stdin); |
| 872 |
> |
|
| 873 |
> |
if(ch=='q'){ |
| 874 |
> |
endwin(); |
| 875 |
> |
exit(0); |
| 876 |
> |
} |
| 877 |
|
} |
| 878 |
+ |
if(FD_ISSET(data_fileno, &infds)){ |
| 879 |
+ |
response=fpgetline(data); |
| 880 |
+ |
if (response==NULL){ |
| 881 |
+ |
errf("Failed to read data (%m)"); |
| 882 |
+ |
exit(1); |
| 883 |
+ |
} |
| 884 |
+ |
} |
| 885 |
+ |
|
| 886 |
|
|
| 887 |
|
num_hosts=parse_xml(response, &machine_data_list); |
| 888 |
|
if(num_hosts==-1) continue; |