def getConnectorStats(self): """Return dictionary of Connector Stats for Apache Tomcat Server. @return: Nested dictionary of Connector Stats. """ if self._statusxml is None: self.initStats() connnodes = self._statusxml.findall('connector') connstats = {} if connnodes: for connnode in connnodes: namestr = connnode.get('name') if namestr is not None: mobj = re.match('(\w+)-(\d+)', namestr) if mobj: proto = mobj.group(1) port = int(mobj.group(2)) connstats[port] = {'proto': proto} for tag in ('threadInfo', 'requestInfo'): stats = {} node = connnode.find(tag) if node is not None: for (key,val) in node.items(): if re.search('Time$', key): stats[key] = float(val) / 1000.0 else: stats[key] = util.parse_value(val) if stats: connstats[port][tag] = stats return connstats
def getConnectorStats(self): """Return dictionary of Connector Stats for Apache Tomcat Server. @return: Nested dictionary of Connector Stats. """ if self._statusxml is None: self.initStats() connnodes = self._statusxml.findall('connector') connstats = {} if connnodes: for connnode in connnodes: namestr = connnode.get('name') if namestr is not None: mobj = re.match('(\w+)-(\d+)', namestr) if mobj: proto = mobj.group(1) port = int(mobj.group(2)) connstats[port] = {'proto': proto} for tag in ('threadInfo', 'requestInfo'): stats = {} node = connnode.find(tag) if node is not None: for (key, val) in node.items(): if re.search('Time$', key): stats[key] = float(val) / 1000.0 else: stats[key] = util.parse_value(val) if stats: connstats[port][tag] = stats return connstats
def initStats(self): """Query and parse Nginx Web Server Status Page.""" url = "%s://%s:%d/%s" % (self._proto, self._host, self._port, self._statuspath) response = util.get_url(url, self._user, self._password) 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 initStats(self): """Query and parse Nginx Web Server Status Page.""" url = "%s://%s:%d/%s" % (self._proto, self._host, self._port, self._statuspath) response = util.get_url(url, self._user, self._password) 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 _simpleQuery(self, query): """Executes simple query which returns a single column. @param query: Query string. @return: Query result string. """ cur = self._conn.cursor() cur.execute(query) row = cur.fetchone() return util.parse_value(row[0])
def getParam(self, key): """Returns value of Run-time Database Parameter 'key'. @param key: Run-time parameter name. @return: Run-time parameter value. """ cur = self._conn.cursor() cur.execute("SHOW %s" % key) row = cur.fetchone() return util.parse_value(row[0])
def initStats(self): """Query and parse Apache Web Server Status Page.""" url = "%s://%s:%d/%s?auto" % (self._proto, self._host, self._port, self._statuspath) response = util.get_url(url, self._user, self._password) 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 Lighttpd Web Server Status Page.""" url = "%s://%s:%d/%s?auto" % (self._proto, self._host, self._port, self._statuspath) response = util.get_url(url, self._user, self._password) 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['MaxServers'] = len(self._statusDict['Scoreboard'])
def getStats(self): """Query and parse Web Server Status Page. """ url = "%s://%s:%d/%s" % (self._proto, self._host, self._port, self._monpath) response = util.get_url(url, self._user, self._password) 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 Web Server Status Page. """ url = "%s://%s:%d/%s" % (self._proto, self._host, self._port, self._monpath) response = util.get_url(url, self._user, self._password) 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 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 getMemoryStats(self): """Return JVM Memory Stats for Apache Tomcat Server. @return: Dictionary of memory utilization stats. """ if self._statusxml is None: self.initStats() node = self._statusxml.find('jvm/memory') memstats = {} if node is not None: for (key, val) in node.items(): memstats[key] = util.parse_value(val) return memstats
def getMemoryStats(self): """Return JVM Memory Stats for Apache Tomcat Server. @return: Dictionary of memory utilization stats. """ if self._statusxml is None: self.initStats() node = self._statusxml.find('jvm/memory') memstats = {} if node is not None: for (key,val) in node.items(): memstats[key] = util.parse_value(val) return memstats
def _parseStats(self, lines, parse_slabs = False): """Parse stats output from memcached and return dictionary of stats- @param lines: Array of lines of input text. @param parse_slabs: Parse slab stats if True. @return: Stats dictionary. """ info_dict = {} info_dict['slabs'] = {} for line in lines: mobj = re.match('^STAT\s(\w+)\s(\S+)$', line) if mobj: info_dict[mobj.group(1)] = util.parse_value(mobj.group(2), True) continue elif parse_slabs: mobj = re.match('STAT\s(\w+:)?(\d+):(\w+)\s(\S+)$', line) if mobj: (slab, key, val) = mobj.groups()[-3:] if not info_dict['slabs'].has_key(slab): info_dict['slabs'][slab] = {} info_dict['slabs'][slab][key] = util.parse_value(val, True) return info_dict
def getStats(self): """Returns global stats for database. @return: Dictionary of database statistics. """ cur = self._conn.cursor() cur.execute("SHOW GLOBAL STATUS") rows = cur.fetchall() info_dict = {} for row in rows: key = row[0] val = util.parse_value(row[1]) info_dict[key] = val return info_dict
def getParams(self): """Returns dictionary of all run-time parameters. @return: Dictionary of all Run-time parameters. """ cur = self._conn.cursor() cur.execute("SHOW GLOBAL VARIABLES") rows = cur.fetchall() info_dict = {} for row in rows: key = row[0] val = util.parse_value(row[1]) info_dict[key] = val return info_dict
def _parseStats(self, lines, parse_slabs=False): """Parse stats output from memcached and return dictionary of stats- @param lines: Array of lines of input text. @param parse_slabs: Parse slab stats if True. @return: Stats dictionary. """ info_dict = {} info_dict['slabs'] = {} for line in lines: mobj = re.match('^STAT\s(\w+)\s(\S+)$', line) if mobj: info_dict[mobj.group(1)] = util.parse_value( mobj.group(2), True) continue elif parse_slabs: mobj = re.match('STAT\s(\w+:)?(\d+):(\w+)\s(\S+)$', line) if mobj: (slab, key, val) = mobj.groups()[-3:] if not info_dict['slabs'].has_key(slab): info_dict['slabs'][slab] = {} info_dict['slabs'][slab][key] = util.parse_value(val, True) return info_dict
def getParams(self): """Returns dictionary of all run-time parameters. @return: Dictionary of all Run-time parameters. """ cur = self._conn.cursor() cur.execute("SHOW ALL") rows = cur.fetchall() info_dict = {} for row in rows: key = row[0] val = util.parse_value(row[1]) info_dict[key] = val return info_dict
def str_to_value_keep(strval, allow_nonnum=True): """ Convert BASIC string to BASIC value. """ if strval == ('$', ''): return vartypes.null['%'] strval = str(vartypes.pass_string_unpack(strval)) ins = StringIO(strval) outs = StringIO() # skip spaces and line feeds (but not NUL). util.skip(ins, (' ', '\n')) tokenise_number(ins, outs) outs.seek(0) value = util.parse_value(outs) if not allow_nonnum: if util.skip_white(ins) != '': # not everything has been parsed - error return None return value
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 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 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): """Runs varnishstats command to get stats from Varnish Cache. @return: Dictionary of stats. """ info_dict = {} args = [varnishstatCmd, "-1"] if self._instance is not None: args.extend(["-n", self._instance]) output = util.exec_command(args) if self._descDict is None: self._descDict = {} for line in output.splitlines(): mobj = re.match("(\S+)\s+(\d+)\s+(\d+\.\d+|\.)\s+(\S.*\S)\s*$", line) if mobj: fname = mobj.group(1).replace(".", "_") info_dict[fname] = util.parse_value(mobj.group(2)) self._descDict[fname] = mobj.group(4) return info_dict
def getStats(self): """Runs varnishstats command to get stats from Varnish Cache. @return: Dictionary of stats. """ info_dict = {} args = [varnishstatCmd, '-1'] if self._instance is not None: args.extend(['-n', self._instance]) output = util.exec_command(args) if self._descDict is None: self._descDict = {} for line in output.splitlines(): mobj = re.match('(\S+)\s+(\d+)\s+(\d+\.\d+|\.)\s+(\S.*\S)\s*$', line) if mobj: info_dict[mobj.group(1)] = util.parse_value(mobj.group(2)) self._descDict[mobj.group(1)] = mobj.group(4) return info_dict return info_dict
def initStats(self, extras=None): """Query and parse Web Server Status Page. @param extras: Include extra metrics, which can be computationally more expensive. """ if extras is not None: self._extras = extras if self._extras: detail = 1 else: detail = 0 url = "%s://%s:%d/%s?detail=%s" % (self._proto, self._host, self._port, self._monpath, detail) response = util.get_url(url, self._user, self._password) 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 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 parse_expr_unit(ins): """ Compute the value of the expression unit at the current code pointer. """ d = util.skip_white(ins) # string literal if d == '"': ins.read(1) output = bytearray() # while tokenised nmbers inside a string literal will be printed as tokenised numbers, they don't actually execute as such: # a \00 character, even if inside a tokenised number, will break a string literal (and make the parser expect a # line number afterwards, etc. We follow this. d = ins.read(1) while d not in util.end_line + ('"',): output += d d = ins.read(1) if d == '\0': ins.seek(-1, 1) return vartypes.pack_string(output) # variable name elif d >= 'A' and d <= 'Z': name, indices = get_var_or_array_name(ins) return var.get_var_or_array(name, indices) # number literals as ASCII are accepted in tokenised streams. only if they start with a figure (not & or .) # this happens e.g. after non-keywords like AS. They are not acceptable as line numbers. elif d >= '0' and d <= '9': outs = StringIO() representation.tokenise_number(ins, outs) outs.seek(0) return util.parse_value(outs) # number literals elif d in token.number: return util.parse_value(ins) # gw-basic allows adding line numbers to numbers elif d == token.T_UINT: return vartypes.pack_int(util.parse_jumpnum(ins)) # brackets elif d == '(': return parse_bracket(ins) # single-byte tokens else: ins.read(1) if d == '\x85': return value_input(ins) elif d == '\xC8': return value_screen(ins) elif d == '\xD0': return value_usr(ins) elif d == '\xD1': return value_fn(ins) elif d == '\xD3': return value_not(ins) elif d == '\xD4': return value_erl(ins) elif d == '\xD5': return value_err(ins) elif d == '\xD6': return value_string(ins) elif d == '\xD8': return value_instr(ins) elif d == '\xDA': return value_varptr(ins) elif d == '\xDB': return value_csrlin(ins) elif d == '\xDC': return value_point(ins) elif d == '\xDE': return value_inkey(ins) elif d == '\xE9': return parse_expr_unit(ins) elif d == '\xEA': return value_neg(ins) # two-byte tokens elif d == '\xFD': d = ins.read(1) if d == '\x81': return value_cvi(ins) elif d =='\x82': return value_cvs(ins) elif d =='\x83': return value_cvd(ins) elif d =='\x84': return value_mki(ins) elif d =='\x85': return value_mks(ins) elif d =='\x86': return value_mkd(ins) elif d == '\x8b': return value_exterr(ins) # two-byte tokens elif d == '\xFE': d = ins.read(1) if d == '\x8D': return value_date(ins) elif d == '\x8E': return value_time(ins) elif d == '\x93': return value_play(ins) elif d == '\x94': return value_timer(ins) elif d == '\x95': return value_erdev(ins) elif d == '\x96': return value_ioctl(ins) elif d == '\x9B': return value_environ(ins) elif d == '\x9E': return value_pmap(ins) # two-byte tokens elif d == '\xFF': d = ins.read(1) if d == '\x81': return value_left(ins) elif d == '\x82': return value_right(ins) elif d == '\x83': return value_mid(ins) elif d == '\x84': return value_sgn(ins) elif d == '\x85': return value_int(ins) elif d == '\x86': return value_abs(ins) elif d == '\x87': return value_sqrt(ins) elif d == '\x88': return value_rnd(ins) elif d == '\x89': return value_sin(ins) elif d == '\x8a': return value_log(ins) elif d == '\x8b': return value_exp(ins) elif d == '\x8c': return value_cos(ins) elif d == '\x8D': return value_tan(ins) elif d == '\x8E': return value_atn(ins) elif d == '\x8F': return value_fre(ins) elif d == '\x90': return value_inp(ins) elif d == '\x91': return value_pos(ins) elif d == '\x92': return value_len(ins) elif d == '\x93': return value_str(ins) elif d == '\x94': return value_val(ins) elif d == '\x95': return value_asc(ins) elif d == '\x96': return value_chr(ins) elif d == '\x97': return value_peek(ins) elif d == '\x98': return value_space(ins) elif d == '\x99': return value_oct(ins) elif d == '\x9A': return value_hex(ins) elif d == '\x9B': return value_lpos(ins) elif d == '\x9C': return value_cint(ins) elif d == '\x9D': return value_csng(ins) elif d == '\x9E': return value_cdbl(ins) elif d == '\x9F': return value_fix(ins) elif d == '\xA0': return value_pen(ins) elif d == '\xA1': return value_stick(ins) elif d == '\xA2': return value_strig(ins) elif d == '\xA3': return value_eof(ins) elif d == '\xA4': return value_loc(ins) elif d == '\xA5': return value_lof(ins) else: return None
def __init__(self, value, datatype, name=UNDEFINED_PARAM): self.name = name self.datatype = datatype self.value = parse_value(value)