Created
October 11, 2010 12:27
-
-
Save fornwall/620441 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import BaseHTTPServer, os | |
class TopHandler(BaseHTTPServer.BaseHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
self.send_header('Content-type', 'text/plain') | |
self.end_headers() | |
# the load may be comma-separated depending on locale, so replace comma with dot | |
self.wfile.write(os.popen("uptime | cut -d ' ' -f 12").read().strip().replace(',', '.') + "," + os.popen("sysctl -n hw.ncpu").read()) | |
def main(): | |
try: | |
port = 18373 | |
server = BaseHTTPServer.HTTPServer(('', port), TopHandler) | |
print 'Started httpserver on port', port | |
server.serve_forever() | |
except KeyboardInterrupt: | |
print '^C received, shutting down server' | |
server.socket.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment