def handle(self): data = socket_read(self.request) request = result = error = None try: request, method, args, kwargs = \ self.server.protocol.unmarshall_request(data) result = self.server.dispatcher.dispatch(method, *args, **kwargs) except Error as e: error = e response = self.server.protocol.marshall_response(request, result, error) if response: self.request.send(response)
def _retrieve(self): """Query Apache Tomcat Server Status Page in XML format and return the result as an ElementTree object. @return: ElementTree object of Status Page XML. """ if self._user is not None and self._password is not None: url = "%s://%s:%s@%s:%d/manager/status?XML=true" % ( self._proto, urllib.quote(self._user), urllib.quote(self._password), self._host, self._port) else: url = "%s://%s:%d/manager/status?XML=true" % ( self._proto, self._host, self._port) fp = urllib.urlopen(url) response = util.socket_read(fp) fp.close() tree = ElementTree.XML(response) return tree
def _retrieve(self): """Query Apache Tomcat Server Status Page in XML format and return the result as an ElementTree object. @return: ElementTree object of Status Page XML. """ if self._user is not None and self._password is not None: url = "%s://%s:%s@%s:%d/manager/status?XML=true" % (self._proto, urllib.quote(self._user), urllib.quote(self._password), self._host, self._port) else: url = "%s://%s:%d/manager/status?XML=true" % (self._proto, self._host, self._port) fp = urllib.urlopen(url) response = util.socket_read(fp) fp.close() tree = ElementTree.XML(response) return tree
def initStats(self): """Query and parse Apache Web Server Status Page.""" if self._user is not None and self._password is not None: url = "%s://%s:%s@%s:%d/%s?auto" % (self._proto, urllib.quote(self._user), urllib.quote(self._password), self._host, self._port, self._statuspath) else: url = "%s://%s:%d/%s?auto" % (self._proto, self._host, self._port, self._statuspath) fp = urllib.urlopen(url) response = util.socket_read(fp) fp.close() self._statusDict = {} for line in response.splitlines(): mobj = re.match('(\S.*\S)\s*:\s*(\S+)\s*$', line) if mobj: self._statusDict[mobj.group(1)] = util.parse_value(mobj.group(2)) if self._statusDict.has_key('Scoreboard'): self._statusDict['MaxWorkers'] = len(self._statusDict['Scoreboard'])
def initStats(self): """Query and parse Web Server Status Page. """ if self._user is not None and self._password is not None: url = "%s://%s:%s@%s:%d/%s" % (self._proto, urllib.quote(self._user), urllib.quote(self._password), self._host, self._port, self._monpath) else: url = "%s://%s:%d/%s" % (self._proto, self._host, self._port, self._monpath) fp = urllib.urlopen(url) response = util.socket_read(fp) fp.close() self._statusDict = {} for line in response.splitlines(): cols = line.split(':') if not self._statusDict.has_key(cols[0]): self._statusDict[cols[0]] = {} self._statusDict[cols[0]][cols[1]] = util.parse_value(cols[2])
def initStats(self): """Query and parse Web Server Status Page. """ if self._user is not None and self._password is not None: url = "%s://%s:%s@%s:%d/%s" % (self._proto, urllib.quote( self._user), urllib.quote( self._password), self._host, self._port, self._monpath) else: url = "%s://%s:%d/%s" % (self._proto, self._host, self._port, self._monpath) fp = urllib.urlopen(url) response = util.socket_read(fp) fp.close() self._statusDict = {} for line in response.splitlines(): cols = line.split(':') if not self._statusDict.has_key(cols[0]): self._statusDict[cols[0]] = {} self._statusDict[cols[0]][cols[1]] = util.parse_value(cols[2])
def getStats(self): """Query and parse Web Server Status Page. """ if self._user is not None and self._password is not None: url = "%s://%s:%s@%s:%d/%s" % (self._proto, urllib.quote(self._user), urllib.quote(self._password), self._host, self._port, self._monpath) else: url = "%s://%s:%d/%s" % (self._proto, self._host, self._port, self._monpath) fp = urllib.urlopen(url) response = util.socket_read(fp) fp.close() stats = {} for line in response.splitlines(): mobj = re.match('([\w\s]+):\s+(\w+)$', line) if mobj: stats[mobj.group(1)] = util.parse_value(mobj.group(2)) return stats
def getStats(self): """Query and parse Web Server Status Page. """ if self._user is not None and self._password is not None: url = "%s://%s:%s@%s:%d/%s" % (self._proto, urllib.quote( self._user), urllib.quote( self._password), self._host, self._port, self._monpath) else: url = "%s://%s:%d/%s" % (self._proto, self._host, self._port, self._monpath) fp = urllib.urlopen(url) response = util.socket_read(fp) fp.close() stats = {} for line in response.splitlines(): mobj = re.match('([\w\s]+):\s+(\w+)$', line) if mobj: stats[mobj.group(1)] = util.parse_value(mobj.group(2)) return stats
def initStats(self): """Query and parse Apache Web Server Status Page.""" if self._user is not None and self._password is not None: url = "%s://%s:%s@%s:%d/%s?auto" % ( self._proto, urllib.quote(self._user), urllib.quote( self._password), self._host, self._port, self._statuspath) else: url = "%s://%s:%d/%s?auto" % (self._proto, self._host, self._port, self._statuspath) fp = urllib.urlopen(url) response = util.socket_read(fp) fp.close() self._statusDict = {} for line in response.splitlines(): mobj = re.match('(\S.*\S)\s*:\s*(\S+)\s*$', line) if mobj: self._statusDict[mobj.group(1)] = util.parse_value( mobj.group(2)) if self._statusDict.has_key('Scoreboard'): self._statusDict['MaxWorkers'] = len( self._statusDict['Scoreboard'])
def initStats(self): """Query and parse Nginx Web Server Status Page.""" if self._user is not None and self._password is not None: url = "%s://%s:%s@%s:%d/%s" % (self._proto, urllib.quote(self._user), urllib.quote(self._password), self._host, self._port, self._statuspath) else: url = "%s://%s:%d/%s" % (self._proto, self._host, self._port, self._statuspath) fp = urllib.urlopen(url) response = util.socket_read(fp) fp.close() self._statusDict = {} for line in response.splitlines(): mobj = re.match('\s*(\d+)\s+(\d+)\s+(\d+)\s*$', line) if mobj: idx = 0 for key in ('accepts','handled','requests'): idx += 1 self._statusDict[key] = util.parse_value(mobj.group(idx)) else: for (key,val) in re.findall('(\w+):\s*(\d+)', line): self._statusDict[key.lower()] = util.parse_value(val)
def send_request(self, data): with open_socket(self.address) as sock: sock.send(data) return socket_read(sock)