| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright 2010 Google Inc. All Rights Reserved. | 3 # Copyright 2010 Google Inc. All Rights Reserved. |
| 4 # | 4 # |
| 5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
| 7 # You may abtain a copy of the license at | 7 # You may abtain a copy of the license at |
| 8 # | 8 # |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 # | 10 # |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 """ | 149 """ |
| 150 Args: | 150 Args: |
| 151 hostname: string, hostname of AutoTest host. | 151 hostname: string, hostname of AutoTest host. |
| 152 """ | 152 """ |
| 153 self.h = hostname | 153 self.h = hostname |
| 154 self.client = paramiko.SSHClient() | 154 self.client = paramiko.SSHClient() |
| 155 self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | 155 self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
| 156 | 156 |
| 157 | 157 |
| 158 def run(self): | 158 def run(self): |
| 159 TB.hosts[self.h]['time'] = strftime( | |
| 160 '%d%b%Y %H:%M:%S', localtime()) | |
| 161 try: | 159 try: |
| 162 self.client.connect(self.h, username='root', | 160 self.client.connect(self.h, username='root', |
| 163 key_filename=TB.privkey, timeout=TIMEOUT) | 161 key_filename=TB.privkey, timeout=TIMEOUT) |
| 164 TB.hosts[self.h]['status'] = True | 162 TB.hosts[self.h]['status'] = True |
| 165 except Exception, e: | 163 except Exception, e: |
| 166 TB.logger.error('Host %s: %s', self.h, e) | 164 TB.logger.error('Host %s: %s', self.h, e) |
| 167 TB.hosts[self.h]['status'] = False | 165 TB.hosts[self.h]['status'] = False |
| 168 finally: | 166 finally: |
| 169 if TB.hosts[self.h]['status']: | 167 if TB.hosts[self.h]['status']: |
| 170 self.ReadRelease() | 168 self.ReadRelease() # Must be done before UpdateRelease(). |
| 171 self.ReadFirmware() | 169 self.ReadFirmware() |
| 172 self.UpdateRelease() # Must be done before ReadResources(). | 170 self.UpdateRelease() # Must be done before ReadResources(). |
| 173 if TB.hosts[self.h]['status']: | 171 if TB.hosts[self.h]['status']: |
| 174 self.ReadResources() | 172 self.ReadResources() |
| 175 TB.logger.debug('Closing client for %s', self.h) | 173 TB.logger.debug('Closing client for %s', self.h) |
| 176 self.client.close() | 174 self.client.close() |
| 175 TB.hosts[self.h]['time'] = strftime( |
| 176 '%d%b%Y %H:%M:%S', localtime()) |
| 177 | 177 |
| 178 | 178 |
| 179 def ReadRelease(self): | 179 def ReadRelease(self): |
| 180 """Get the Chrome OS Release version.""" | 180 """Get the Chrome OS Release version.""" |
| 181 # The PTR key will mark the current version. | 181 # The PTR key will mark the current version. |
| 182 | 182 |
| 183 cmd = 'cat /etc/lsb-release' | 183 cmd = 'cat /etc/lsb-release' |
| 184 try: | 184 try: |
| 185 stdin, stdout, stderr = self.client.exec_command(cmd) | 185 stdin, stdout, stderr = self.client.exec_command(cmd) |
| 186 for line in stdout: | 186 for line in stdout: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 # This means the release file has the wrong format, so | 259 # This means the release file has the wrong format, so |
| 260 # we'll just write a new one with current values. | 260 # we'll just write a new one with current values. |
| 261 update_file = True | 261 update_file = True |
| 262 lines.pop(lines.index(line)) | 262 lines.pop(lines.index(line)) |
| 263 else: | 263 else: |
| 264 # If we get here than it's probably a blank line. | 264 # If we get here than it's probably a blank line. |
| 265 update_file = True | 265 update_file = True |
| 266 lines.pop(lines.index(line)) | 266 lines.pop(lines.index(line)) |
| 267 | 267 |
| 268 if update_file: | 268 if update_file: |
| 269 TB.logger.info('Updating %s', relfile) | 269 TB.logger.debug('Updating %s', relfile) |
| 270 shutil.move(relfile, tmpfile) | 270 shutil.move(relfile, tmpfile) |
| 271 # Put the most recent update in the new file, and make the | 271 # Put the most recent update in the new file, and make the |
| 272 # PTR key to point to it. | 272 # PTR key to point to it. |
| 273 lines.append('%s=%s\n' % (TB.time, | 273 lines.append('%s=%s\n' % (TB.time, |
| 274 TB.hosts[self.h][item]['PTR'])) | 274 TB.hosts[self.h][item]['PTR'])) |
| 275 lines.append('PTR=%s' % TB.hosts[self.h][item]['PTR']) | 275 lines.append('PTR=%s' % TB.hosts[self.h][item]['PTR']) |
| 276 try: | 276 try: |
| 277 rf = open(relfile, 'w') | 277 rf = open(relfile, 'w') |
| 278 for line in lines: | 278 for line in lines: |
| 279 rf.write(line) | 279 rf.write(line) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 t.start() | 413 t.start() |
| 414 | 414 |
| 415 # Fill the requests queue with AutoTest host objects. | 415 # Fill the requests queue with AutoTest host objects. |
| 416 for host in self.afe_hosts: | 416 for host in self.afe_hosts: |
| 417 TB.logger.debug('Placing %s in host queue.', host.hostname) | 417 TB.logger.debug('Placing %s in host queue.', host.hostname) |
| 418 TB.q.put(host) | 418 TB.q.put(host) |
| 419 | 419 |
| 420 | 420 |
| 421 if TB.graph: | 421 if TB.graph: |
| 422 # Graphing takes much longer, so increase the max runtime. | 422 # Graphing takes much longer, so increase the max runtime. |
| 423 maxtime = RUNTIME * 5 | 423 maxtime = RUNTIME * 6 |
| 424 else: | 424 else: |
| 425 maxtime = RUNTIME | 425 maxtime = RUNTIME |
| 426 # Queue.join() will wait for all jobs in the queue to finish, or | 426 # Queue.join() will wait for all jobs in the queue to finish, or |
| 427 # until the timeout value is reached. Timeout is needed because | 427 # until the timeout value is reached. Timeout is needed because |
| 428 # sometimes the paramiko client will hang. | 428 # sometimes the paramiko client will hang. |
| 429 TB.logger.debug('Joining run queue.') | 429 TB.logger.debug('Joining run queue.') |
| 430 TB.q.join(timeout=maxtime) | 430 TB.q.join(timeout=maxtime) |
| 431 TB.logger.info('%s hosts left in host queue', TB.q.qsize()) | 431 TB.logger.info('%s hosts left in host queue', TB.q.qsize()) |
| 432 | 432 |
| 433 LogLevel = TB.logger.getEffectiveLevel() | 433 LogLevel = TB.logger.getEffectiveLevel() |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 f.write('<td>%s<br><a href=%s.html>' % (r, r)) | 744 f.write('<td>%s<br><a href=%s.html>' % (r, r)) |
| 745 f.write('<img src=%s%s.png width=475 height=250></a></td>' % ( | 745 f.write('<img src=%s%s.png width=475 height=250></a></td>' % ( |
| 746 r,k)) | 746 r,k)) |
| 747 if newrow: | 747 if newrow: |
| 748 newrow = False | 748 newrow = False |
| 749 else: | 749 else: |
| 750 f.write('</tr>\n') | 750 f.write('</tr>\n') |
| 751 newrow = True | 751 newrow = True |
| 752 f.write('</table><p>\n') | 752 f.write('</table><p>\n') |
| 753 f.write('</center>\n') | 753 f.write('</center>\n') |
| 754 f.write('<H5>Last Update: %s</H5>' % TB.hosts[hostname]['time']) |
| 754 f.write('</BODY></HTML>') | 755 f.write('</BODY></HTML>') |
| 755 f.close() | 756 f.close() |
| 756 os.chmod(pathname[k], 0644) | 757 os.chmod(pathname[k], 0644) |
| 757 if not os.path.isfile(index_file): | 758 if not os.path.isfile(index_file): |
| 758 os.symlink(pathname[TB.rrdtimes[0]], index_file) | 759 os.symlink(pathname[TB.rrdtimes[0]], index_file) |
| 759 | 760 |
| 760 # Create HTML files for each resource for all time periods. | 761 # Create HTML files for each resource for all time periods. |
| 761 for r in resource_list: | 762 for r in resource_list: |
| 762 rrdfile = os.path.join(rrd_dir, r + '.html') | 763 rrdfile = os.path.join(rrd_dir, r + '.html') |
| 763 f = open(rrdfile, 'w') | 764 f = open(rrdfile, 'w') |
| 764 f.write('<HTML><HEAD>') | 765 f.write('<HTML><HEAD>') |
| 765 f.write('<center><TITLE>%s %s Resources</TITLE></HEAD>' % ( | 766 f.write('<center><TITLE>%s %s Resources</TITLE></HEAD>' % ( |
| 766 hostname, r)) | 767 hostname, r)) |
| 767 f.write('<BODY><H1>%s %s Resources</H1>' % (hostname, r)) | 768 f.write('<BODY><H1>%s %s Resources</H1>' % (hostname, r)) |
| 768 for i in TB.releases: | 769 for i in TB.releases: |
| 769 f.write('<H4>%s: %s</H4>' % (i, TB.hosts[hostname][i]['PTR'])) | 770 f.write('<H4>%s: %s</H4>' % (i, TB.hosts[hostname][i]['PTR'])) |
| 770 f.write('<table border=5 bgcolor=#B5B5B5>') | 771 f.write('<table border=5 bgcolor=#B5B5B5>') |
| 771 f.write('<tr>') | 772 f.write('<tr>') |
| 772 for h in TB.rrdtimes: | 773 for h in TB.rrdtimes: |
| 773 f.write('<td><a href="#%s"><b>%s</b></a>' % (h, h)) | 774 f.write('<td><a href="#%s"><b>%s</b></a>' % (h, h)) |
| 774 f.write('</table>') | 775 f.write('</table>') |
| 775 f.write('<HR>') | 776 f.write('<HR>') |
| 776 f.write('<table border=1 bgcolor=#EEEEEE>') | 777 f.write('<table border=1 bgcolor=#EEEEEE>') |
| 777 for h in TB.rrdtimes: | 778 for h in TB.rrdtimes: |
| 778 f.write('<tr><td><a name="%s"><img src=%s%s.png>' % (h, r, h)) | 779 f.write('<tr><td><a name="%s"><img src=%s%s.png>' % (h, r, h)) |
| 779 f.write('</a></td></tr>\n') | 780 f.write('</a></td></tr>\n') |
| 780 f.write('</table><p>\n') | 781 f.write('</table><p>\n') |
| 781 f.write('</center>\n') | 782 f.write('</center>\n') |
| 783 f.write('<H5>Last Update: %s</H5>' % TB.hosts[hostname]['time']) |
| 782 f.write('</BODY></HTML>') | 784 f.write('</BODY></HTML>') |
| 783 f.close() | 785 f.close() |
| 784 os.chmod(rrdfile, 0644) | 786 os.chmod(rrdfile, 0644) |
| 785 | 787 |
| 786 | 788 |
| 787 def ParseBattery(self, h, k): | 789 def ParseBattery(self, h, k): |
| 788 """Convert /proc/acpi/battery/BAT0/state to a list of strings. | 790 """Convert /proc/acpi/battery/BAT0/state to a list of strings. |
| 789 | 791 |
| 790 Args: | 792 Args: |
| 791 h: string, hostname of host in AutoTest. | 793 h: string, hostname of host in AutoTest. |
| (...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 parser.add_option('--logfile', | 1720 parser.add_option('--logfile', |
| 1719 help='name of logfile [default: %default]', | 1721 help='name of logfile [default: %default]', |
| 1720 default='monitor.log', | 1722 default='monitor.log', |
| 1721 dest='logfile') | 1723 dest='logfile') |
| 1722 parser.add_option('--log_to_stdout', | 1724 parser.add_option('--log_to_stdout', |
| 1723 help='Send output to StdOut [default: %default]', | 1725 help='Send output to StdOut [default: %default]', |
| 1724 default=False, | 1726 default=False, |
| 1725 dest='log_to_stdout') | 1727 dest='log_to_stdout') |
| 1726 parser.add_option('--threads', | 1728 parser.add_option('--threads', |
| 1727 help='Number of threads to create [default: %default]', | 1729 help='Number of threads to create [default: %default]', |
| 1728 default=25, | 1730 default=50, |
| 1729 dest='threads') | 1731 dest='threads') |
| 1730 parser.add_option('--update', | 1732 parser.add_option('--update', |
| 1731 help='Collect data from hosts [default: %default]', | 1733 help='Collect data from hosts [default: %default]', |
| 1732 default=True, | 1734 default=True, |
| 1733 dest='update') | 1735 dest='update') |
| 1734 parser.add_option('--url', | 1736 parser.add_option('--url', |
| 1735 help='URL for landing page [default: %default]', | 1737 help='URL for landing page [default: %default]', |
| 1736 default='http://www/~chromeos-test/systemhealth/', | 1738 default='http://www/~chromeos-test/systemhealth/', |
| 1737 dest='url') | 1739 dest='url') |
| 1738 | 1740 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1751 sysmon.BuildLandingPage() | 1753 sysmon.BuildLandingPage() |
| 1752 runtime = time() - start | 1754 runtime = time() - start |
| 1753 endtime = strftime('%H:%M:%S', localtime()) | 1755 endtime = strftime('%H:%M:%S', localtime()) |
| 1754 TB.logger.info('End Time: %s', endtime) | 1756 TB.logger.info('End Time: %s', endtime) |
| 1755 TB.logger.info('Time of run: %s seconds', runtime) | 1757 TB.logger.info('Time of run: %s seconds', runtime) |
| 1756 TB.logger.info('Ran with %d threads', TB.thread_num) | 1758 TB.logger.info('Ran with %d threads', TB.thread_num) |
| 1757 | 1759 |
| 1758 | 1760 |
| 1759 if __name__ == '__main__': | 1761 if __name__ == '__main__': |
| 1760 main(sys.argv) | 1762 main(sys.argv) |
| OLD | NEW |