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 |
+ |
|
691 |
|
FILE *control; |
692 |
|
FILE *data; |
693 |
|
|
707 |
|
int cmdopt; |
708 |
|
extern int optind; |
709 |
|
extern char *optarg; |
686 |
– |
sortby_ptr=NULL; |
710 |
|
|
711 |
|
display_config_t display_config; |
712 |
+ |
char ch; |
713 |
|
|
714 |
+ |
sortby_ptr=NULL; |
715 |
+ |
|
716 |
|
/* What to display defaults */ |
717 |
|
display_config.cpu_user=0; |
718 |
|
display_config.cpu_idle=0; |
748 |
|
display_config.network_io_total_rx=1; |
749 |
|
display_config.network_all_stats=1; |
750 |
|
|
751 |
< |
display_config.disk_io_total_write=1; |
752 |
< |
display_config.disk_io_total_read=1; |
751 |
> |
display_config.disk_io_total_write=0; |
752 |
> |
display_config.disk_io_total_read=0; |
753 |
|
display_config.disk_io_all_stats=0; |
754 |
|
|
755 |
|
display_config.disk_total_used=0; |
756 |
|
display_config.disk_all_stats=0; |
757 |
|
|
732 |
– |
|
758 |
|
while((cmdopt=getopt(argc, argv, "d:s:")) != -1){ |
759 |
|
switch(cmdopt){ |
760 |
|
case 'd': |
841 |
|
printf("\033[1;1HHostname CPU Load Page Page Mem Swap Net Net Disk Disk"); |
842 |
|
printf("\033[2;1H used%% (1m) ins outs used used rx tx read write"); |
843 |
|
*/ |
844 |
< |
fflush(stdout); |
844 |
> |
|
845 |
> |
initscr(); |
846 |
> |
nonl(); |
847 |
> |
cbreak(); |
848 |
> |
echo(); |
849 |
> |
window=newwin(0, 0, 0, 0); |
850 |
> |
|
851 |
|
for(;;){ |
852 |
|
response=fpgetline(data); |
853 |
|
if (response==NULL){ |
855 |
|
exit(1); |
856 |
|
} |
857 |
|
|
858 |
+ |
/* ch=getc(stdin); |
859 |
+ |
|
860 |
+ |
if(ch=='q'){ |
861 |
+ |
endwin(); |
862 |
+ |
exit(0); |
863 |
+ |
} |
864 |
+ |
*/ |
865 |
|
num_hosts=parse_xml(response, &machine_data_list); |
866 |
|
if(num_hosts==-1) continue; |
867 |
|
machine_data_list=sort_machine_stats(machine_data_list, num_hosts, sortby_ptr); |