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