3 """This runs Apache Status on the remote host and returns the number of requests per second.
5 ./astat.py [-s server_hostname] [-u username] [-p password]
6 -s : hostname of the remote server to login to.
7 -u : username to user for login.
8 -p : Password to user for login.
11 This will print information about the given host:
12 ./astat.py -s www.example.com -u mylogin -p mypassword
27 def exit_with_usage():
29 print globals()['__doc__']
35 ######################################################################
36 # Parse the options, arguments, get ready, etc.
37 ######################################################################
39 optlist, args = getopt.getopt(
43 except Exception as e:
46 options = dict(optlist)
50 if [elem for elem in options if elem in [
51 '-h', '--h', '-?', '--?', '--help']]:
56 hostname = options['-s']
58 hostname = raw_input('hostname: ')
60 username = options['-u']
62 username = raw_input('username: ')
64 password = options['-p']
66 password = getpass.getpass('password: ')
72 p.login(hostname, username, password)
73 p.sendline('apachectl status')
74 p.expect('([0-9]+\.[0-9]+)\s*requests/sec')
75 requests_per_second = p.match.groups()[0]
77 print requests_per_second
79 if __name__ == "__main__":
82 except Exception as e: