Changeset 514 for trunk/web/addons
- Timestamp:
- 03/08/08 21:16:32 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/job_monarch/libtoga.php
r496 r514 126 126 } 127 127 128 128 129 class TarchDbase { 129 130 … … 566 567 $this->nodes = array(); 567 568 $heartbeat = array(); 569 $down_nodes = array(); 570 $offline_nodes = array(); 568 571 $this->clustername = $clustername; 569 572 $this->fqdn = 1; … … 573 576 574 577 return $this->fqdn; 578 579 575 580 } 576 581 … … 600 605 } 601 606 607 function makeHostname( $thostname, $tdomain=null ) 608 { 609 // Should hostname be FQDN or short w/o domain 610 // 611 $nodes = &$this->nodes; 612 613 $fqdn = 1; 614 615 //$tdomain = explode( '.', $thostname ); 616 // TODO: domain van hostname afhalen: parameter weghalen 617 618 if( $tdomain ) 619 { 620 $domain_len = 0 - strlen( $tdomain ); 621 622 // Let's see if Ganglia use's FQDN or short hostnames 623 // 624 foreach( $nodes as $hostname => $nimage ) 625 { 626 627 if( substr( $hostname, $domain_len ) != $tdomain ) 628 { 629 $fqdn = 0; 630 } 631 } 632 } 633 else 634 { 635 $fqdn = 0; 636 } 637 638 if( $tdomain && $fqdn ) 639 { 640 if( substr( $thostname, $domain_len ) != $tdomain ) 641 { 642 $thostname = $thostname . '.'.$tdomain; 643 } 644 else 645 { 646 $thostname = $thostname; 647 } 648 } 649 650 return $thostname; 651 } 652 602 653 function startElement( $parser, $name, $attrs ) { 603 654 … … 640 691 } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) { 641 692 642 if( strstr( $attrs[NAME], 'MONARCH-HEARTBEAT' ) ) {643 693 if( strstr( $attrs[NAME], 'MONARCH-HEARTBEAT' ) ) 694 { 644 695 $this->heartbeat['time'] = $attrs[VAL]; 645 //printf( "heartbeat %s\n", $heartbeat['time'] ); 696 } 697 else if( strstr( $attrs[NAME], 'MONARCH-DOWN' ) ) 698 { 699 $fields = explode( ' ', $attrs[VAL] ); 700 701 $nodes_down = array(); 702 $down_domain = null; 703 704 foreach( $fields as $f ) 705 { 706 $togavalues = explode( '=', $f ); 707 708 $toganame = $togavalues[0]; 709 $togavalue = $togavalues[1]; 710 711 if( $toganame == 'nodes' ) 712 { 713 $mynodes = explode( ';', $togavalue ); 714 715 foreach( $mynodes as $node ) 716 { 717 $nodes_down[] = $node; 718 } 719 } 720 else if( $toganame == 'domain' ) 721 { 722 $down_domain = $togavalue; 723 } 724 else if( $toganame == 'reported' ) 725 { 726 if( !isset( $this->down_nodes['heartbeat'] ) ) 727 { 728 $this->down_nodes[$togavalue] = array( $nodes_down, $down_domain ); 729 } 730 } 731 } 732 733 } else if( strstr( $attrs[NAME], 'MONARCH-OFFLINE' ) ) { 734 735 $fields = explode( ' ', $attrs[VAL] ); 736 737 $nodes_offline = array(); 738 $offline_domain = null; 739 740 foreach( $fields as $f ) 741 { 742 $togavalues = explode( '=', $f ); 743 744 $toganame = $togavalues[0]; 745 $togavalue = $togavalues[1]; 746 747 if( $toganame == 'nodes' ) 748 { 749 $mynodes = explode( ';', $togavalue ); 750 751 foreach( $mynodes as $node ) 752 { 753 $nodes_offline[] = $node; 754 } 755 } 756 else if( $toganame == 'domain' ) 757 { 758 $offline_domain = $togavalue; 759 } 760 else if( $toganame == 'reported' ) 761 { 762 if( !isset( $this->offline_nodes['heartbeat'] ) ) 763 { 764 $this->offline_nodes[$togavalue] = array( $nodes_offline, $offline_domain ); 765 } 766 } 767 } 646 768 647 769 } else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) ) { … … 762 884 763 885 function stopElement( $parser, $name ) { 886 887 $nodes = $this->nodes; 888 889 if( $name == "GANGLIA_XML" ) 890 { 891 foreach( $this->down_nodes as $reported => $dnodes ) 892 { 893 894 if( $reported == $this->heartbeat['time'] ) 895 { 896 $domain = $dnodes[1]; 897 898 foreach( $dnodes[0] as $downhost ) 899 { 900 $downhost = $this->makeHostname( $downhost, $domain ); 901 902 if( isset( $nodes[$downhost] ) ) 903 { 904 // OMG PHP4 is fking stupid! 905 // $nodes[$downhost]->setDown( 1 ) won't work here.. 906 // 907 $mynode = $nodes[$downhost]; 908 $mynode->setDown( 1 ); 909 $nodes[$downhost] = $mynode; 910 } 911 } 912 } 913 } 914 915 foreach( $this->offline_nodes as $reported => $onodes ) 916 { 917 if( $reported == $this->heartbeat['time'] ) 918 { 919 $domain = $onodes[1]; 920 921 foreach( $onodes[0] as $offlinehost ) 922 { 923 $offlinehost = $this->makeHostname( $offlinehost, $domain ); 924 925 if( isset( $nodes[$offlinehost] ) ) 926 { 927 // OMG PHP4 is fking stupid! 928 // $nodes[$offlinehost]->setDown( 1 ) won't work here.. 929 // 930 $mynode = $nodes[$offlinehost]; 931 $mynode->setOffline( 1 ); 932 $nodes[$offlinehost] = $mynode; 933 } 934 } 935 } 936 } 937 } 938 939 $this->nodes = $nodes; 764 940 } 765 941 … … 851 1027 $this->showinfo = 1; 852 1028 $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH; 1029 $this->down = 0; 1030 $this->offline = 0; 853 1031 } 854 1032 … … 878 1056 879 1057 $this->tasks = $this->tasks + $cpus; 1058 } 1059 1060 function setDown( $down ) { 1061 1062 $this->down = $down; 1063 } 1064 1065 function isDown() { 1066 1067 return $this->down; 1068 } 1069 function setOffline( $offline ) { 1070 1071 $this->offline = $offline; 1072 } 1073 1074 function isOffline() { 1075 1076 return $this->offline; 880 1077 } 881 1078 … … 898 1095 899 1096 $area_href = "./?c=" . $this->clustername . "&h=" . $this->hostname; 900 $area_tooltip = $this->hostname . ": " . implode( " ", $this->jobs ); 1097 1098 $area_tooltip = $this->hostname; 1099 1100 if( $this->down) 1101 { 1102 $area_tooltip = $area_tooltip . ": DOWN"; 1103 } 1104 else if( $this->offline ) 1105 { 1106 $area_tooltip = $area_tooltip . ": OFFLINE"; 1107 } 1108 1109 $area_tooltip = $area_tooltip . ": " . implode( " ", $this->jobs ); 901 1110 902 1111 $tag_href = "HREF=\"" . $area_href . "\""; … … 955 1164 function draw() { 956 1165 957 global $JOB_NODE_MARKING ;1166 global $JOB_NODE_MARKING, $NODE_DOWN_MARKING, $NODE_OFFLINE_MARKING; 958 1167 959 1168 $black_color = imageColorAllocate( $this->image, 0, 0, 0 ); … … 978 1187 $usecolor = $this->colorHex( load_color($load) ); 979 1188 imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); 980 if( count( $this->jobs ) > 0 ) 1189 if( $this->down ) 1190 { 1191 imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $NODE_DOWN_MARKING, $black_color ); 1192 } 1193 else if( $this->offline ) 1194 { 1195 imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $NODE_OFFLINE_MARKING, $black_color ); 1196 } 1197 else if( count( $this->jobs ) > 0 ) 1198 { 981 1199 imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $JOB_NODE_MARKING, $black_color ); 1200 } 982 1201 983 1202 } else {
Note: See TracChangeset
for help on using the changeset viewer.