Changeset 27775
- Timestamp:
- Apr 26, 2010, 2:25:29 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/tools/czartool.pl (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/czartool.pl
r27767 r27775 11 11 use File::Temp qw(tempfile); 12 12 13 my $dbname = 'gpc1';14 my $dbserver = 'ippdb01';15 my $dbuser = 'ippuser';16 my $dbpass = 'ippuser';17 my $db = DBI->connect(18 "DBI:mysql:database=${dbname};host=${dbserver};mysql_socket=" .19 DB_SOCKET(),${dbuser},${dbpass},20 {21 RaiseError => 1, AutoCommit => 1}22 ) or die "Unable to connect to database $DBI::errstr\n";23 24 # get current labels from pantasks25 my @cmdOut = `echo "show.labels;quit" | pantasks_client -c ~ipp/stdscience/ptolemy.rc`;26 my $line;27 my @labels;28 my $passedHeader=0;29 foreach $line (@cmdOut) {30 31 chomp($line);32 if ($line =~ m/pantasks: dummy/) {$passedHeader=1; next;}33 34 if ($passedHeader){push(@labels, $line);}35 }36 37 # define set of states38 13 my @states = ("full", "new", "drop", "wait", "fault"); 14 my $db = connectToDb(); 15 16 if (!$db) {die;} 17 18 my @stdscienceLabels = loadLabels("stdscience"); 19 my @distributionLabels = loadLabels("distribution"); 20 showLabelDifferences(); 39 21 40 22 checkAllLabels("new"); 41 23 printInstructions(); 42 24 43 my $key; 44 system "stty cbreak < /dev/tty > /dev/tty 2>&1"; 45 while (($key=getc) ) { 46 last if $key eq "q"; 47 48 if ($key eq "f") {checkAllLabels("full");} 49 elsif ($key eq "n") {checkAllLabels("new");} 50 elsif ($key eq "d") {checkAllLabels("drop");} 51 elsif ($key eq "w") {checkAllLabels("wait");} 52 elsif ($key eq "l") {labelDetails();} 53 elsif ($key =~ m/[0-9]/) {my $key2=getc; checkOneLabel($labels[$key.$key2]);} 54 printInstructions(); 55 56 }; 57 system "stty -cbreak < /dev/tty > /dev/tty 2>&1"; 25 poll(); 58 26 $db->disconnect(); 59 27 60 ############## 61 # 62 # 63 ############### 28 ########################################################################### 29 # 30 # Prints simple instructions 31 # 32 ########################################################################### 64 33 sub printInstructions { 65 34 66 print "\n*** Enter: (f)ull (n)ew (d)rop (w)ait (q)uit (l)abel, or label number from table above: "; 67 } 68 69 ############## 70 # 71 # 72 ############### 35 print "\n### Enter: (s)ervers (f)ull (n)ew (d)rop (w)ait (q)uit (l)abel, or label number from table above: "; 36 } 37 38 ########################################################################### 39 # 40 # Polls waiting for input from user 41 # 42 ########################################################################### 43 sub poll { 44 45 my $key; 46 system "stty cbreak < /dev/tty > /dev/tty 2>&1"; 47 while (($key=getc) ) { 48 last if $key eq "q"; 49 50 if ($key eq "s") {checkServers();} 51 elsif ($key eq "f") {checkAllLabels("full");} 52 elsif ($key eq "n") {checkAllLabels("new");} 53 elsif ($key eq "d") {checkAllLabels("drop");} 54 elsif ($key eq "w") {checkAllLabels("wait");} 55 elsif ($key eq "l") {labelDetails();} 56 elsif ($key =~ m/[0-9]/) {my $key2=getc; checkOneLabel($stdscienceLabels[$key.$key2]);} 57 printInstructions(); 58 59 }; 60 system "stty -cbreak < /dev/tty > /dev/tty 2>&1"; 61 } 62 63 ########################################################################### 64 # 65 # Connects to the database 66 # 67 ########################################################################### 68 sub connectToDb { 69 70 my $dbname = 'gpc1'; 71 my $dbserver = 'ippdb01'; 72 my $dbuser = 'ippuser'; 73 my $dbpass = 'ippuser'; 74 my $db = DBI->connect( 75 "DBI:mysql:database=${dbname};host=${dbserver};mysql_socket=" . 76 DB_SOCKET(),${dbuser},${dbpass}, 77 { 78 RaiseError => 1, AutoCommit => 1} 79 ) or die "Unable to connect to database $DBI::errstr\n"; 80 81 return $db; 82 } 83 84 ########################################################################### 85 # 86 # Display label differences between stdscience and distribution 87 # 88 ########################################################################### 89 sub showLabelDifferences { 90 91 my @diffLabels = @{getArrayDifferences(\@stdscienceLabels, \@distributionLabels)}; 92 93 printf("+-------------------------------------------------------+\n"); 94 printf("| Label differences between stdscience and distribution |\n"); 95 printf("+-------------------------------------------------------+\n"); 96 97 my $item; 98 foreach $item (@diffLabels) { 99 100 printf( "| %53s |\n", $item); 101 } 102 printf("+-------------------------------------------------------+\n"); 103 } 104 105 ########################################################################### 106 # 107 # Compares two arrays and stores the differences 108 # 109 ########################################################################### 110 sub getArrayDifferences { 111 112 my @array1 = @{$_[0]}; 113 my @array2 = @{$_[1]}; 114 115 my @isect; 116 my @diff; 117 my %count; 118 119 my $item; 120 foreach $item (@array1, @array2) { $count{$item}++;} 121 122 foreach $item (keys %count) { 123 if ($count{$item} == 2) { 124 push @isect, $item; 125 } else { 126 push @diff, $item; 127 } 128 } 129 130 return \@diff; 131 } 132 133 ########################################################################### 134 # 135 # Loads labels from a particular pantasks server 136 # 137 ########################################################################### 138 sub loadLabels { 139 my ($server) = @_; 140 141 my @cmdOut = `echo "show.labels;quit" | pantasks_client -c ~ipp/$server/ptolemy.rc 2>&1`; 142 my $line; 143 my @labels; 144 my $passedHeader=0; 145 foreach $line (@cmdOut) { 146 147 chomp($line); 148 if ($line =~ m/pantasks:/) {$passedHeader=1; next;} 149 150 if ($passedHeader){push(@labels, $line);} 151 } 152 153 return @labels; 154 } 155 156 ########################################################################### 157 # 158 # Checks all servers to see if they are alive and running 159 # 160 ########################################################################### 161 sub checkServers { 162 163 my @servers = ("addstar", "cleanup", "detrend", "distribution", "pstamp", "publishing", "registration", "replication", "stdscience", "summitcopy"); 164 printf("\n+-----------------------------------------------+\n"); 165 printf("| Servers |\n"); 166 printf("+--------------+---------+----------------------+\n"); 167 printf("| server | alive? | Scheduler running? |\n"); 168 printf("+--------------+---------+----------------------+\n"); 169 my $server; 170 foreach $server (@servers) { 171 172 printf("| %12s ", $server); 173 174 my @cmdOut = `echo "status ;quit" | pantasks_client -c ~ipp/$server/ptolemy.rc 2>&1`; 175 176 my $line; 177 my $foundStatus = 0; 178 my $isRunning = 0; 179 foreach $line (@cmdOut) { 180 181 chomp($line); 182 if ($line =~ m/Scheduler is stopped/) {$isRunning = 0; $foundStatus=1;last;} 183 if ($line =~ m/Scheduler is running/) {$isRunning = 1; $foundStatus=1;last;} 184 if ($line =~ m/Task Staus/) {last;} 185 186 } 187 188 if (!$foundStatus){print "| NO ";} else {print "| yes ";} 189 if (!$isRunning){print "| NO ";} else {print "| yes ";} 190 printf("|\n"); 191 } 192 193 printf("+--------------+---------+----------------------+\n"); 194 } 195 196 ########################################################################### 197 # 198 # Takes label name or number 199 # 200 ########################################################################### 73 201 sub labelDetails { 74 202 … … 77 205 chomp($input); 78 206 if ($input =~ m/^([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$/) { 79 return checkOneLabel($ labels[$input]);207 return checkOneLabel($stdscienceLabels[$input]); 80 208 } 81 209 … … 83 211 } 84 212 85 ############## 86 # 87 # 88 ############### 213 ########################################################################### 214 # 215 # Checks one label and prints results in a table 216 # 217 ########################################################################### 89 218 sub checkOneLabel { 90 219 my ($label) = @_; … … 121 250 close(LOGFILE); 122 251 } 123 ############## 124 # 125 # 126 ############### 252 253 ########################################################################### 254 # 255 # Checks all labels for a particular state and prints results in a table 256 # 257 ########################################################################### 127 258 sub checkAllLabels { 128 259 my ($state) = @_; … … 136 267 my $label; 137 268 my $i=0; 138 foreach $label (@ labels) {269 foreach $label (@stdscienceLabels) { 139 270 140 271 chomp($label); … … 159 290 } 160 291 161 ############## 162 # 163 # 164 ############### 292 ########################################################################### 293 # 294 # Returns state and fault-count (if new) as a string 295 # 296 ########################################################################### 165 297 sub getStateAndFaults { 166 298 my ($label, $table, $state, $stage) = @_; … … 177 309 } 178 310 179 ############## 180 # 181 # 182 ############### 311 ########################################################################### 312 # 313 # Returns count of exposures with this state for this label 314 # 315 ########################################################################### 183 316 sub checkLabel { 184 317 my ($label, $table, $state, $stage) = @_; … … 198 331 } 199 332 200 201 # #############202 # 203 # 204 ############### 333 ########################################################################### 334 # 335 # Returns count of faults for this stage and label 336 # 337 ########################################################################### 205 338 sub countFaults { 206 339 my ($label, $table, $stage) = @_; … … 236 369 } 237 370 238 ############## 239 # 240 # 241 ############### 371 ########################################################################### 372 # 373 # Counts total distribution faults 374 # 375 ########################################################################### 242 376 sub countDistFaults { 243 377 my ($label) = @_;
Note:
See TracChangeset
for help on using the changeset viewer.
