Beispiel #1
0
 def find_inode_by_port(port, protocol):
     result = set()
     netstat_files = {
         "tcp": ["/proc/net/tcp", "/proc/net/tcp6"],
         "udp": ["/proc/net/udp", "/proc/net/udp6"]
     }
     listen_list = []
     for netstat_file in netstat_files[protocol]:
         listen_list += fileopt.read_file(netstat_file).split("\n")
     for line in listen_list:
         if not line or "local_address" in line:
             continue
         _parts = line.split()
         _local_addr = _parts[1]
         _socket_st = _parts[3]
         _inode_addr = _parts[9]
         _local_port = int(_local_addr.split(":")[1], 16)
         # st of '0A' is TCP_LISTEN, and '07' is for UDP (TCP_CLOSE)
         # see linux/include/net/tcp_states.h for difinitions of other states
         if _socket_st != '0A' and _socket_st != '07':
             continue
         if int(port) != _local_port:
             continue
         result.add(_inode_addr)
     return result
Beispiel #2
0
    def load_dump(self):
        def file_list(dir=None):
            f_list = []
            for file in fileopt.list_dir(dir):
                if os.path.isdir(file):
                    f_list += file_list(file)
                else:
                    f_list.append(file)
            return f_list

        for file in file_list(self.datadir):
            if file.endswith('.json'):
                raw = fileopt.read_file(file)
            elif file.endswith('.dat'):
                raw = zlib.decompress(fileopt.read_file(file, 'rb'))
            else:
                logging.debug("Skipped unrecorgnized file '%s'" % file)
                continue
            yield json.loads(raw)
Beispiel #3
0
    def __init__(self, args):
        super(TUIModuleTiDB, self).__init__(args, module='tidb')
        self.tidbinfo = {}

        for host in self.hosts:
            host = str(host)
            self.tidbinfo[host] = {}
            # list all tidbinfo information of this host
            for file in fileopt.list_files(self.datadir, filter='%s/tidbinfo/' % host):
                key = file.split('-tidb-')[-1][:-5]
                self.tidbinfo[host][key] = json.loads(fileopt.read_file(file))
Beispiel #4
0
    def __init__(self, args):
        super(TUIModulePD, self).__init__(args, 'pd')
        self.pdinfo = {}

        for host in self.hosts:
            host = str(host)
            self.pdinfo[host] = {}
            # list all pdctl information of this host
            for file in fileopt.list_files(self.datadir, filter='%s/pdctl/' % host):
                key = file.split('-')[-1][:-5]
                self.pdinfo[host][key] = json.loads(fileopt.read_file(file))
Beispiel #5
0
 def read_collector_data(self):
     data = {}
     for file in self.file_list:
         # paths are like some/path/<host_alias>/collector/<key>.json
         if 'collector/' not in file or not file.endswith('.json'):
             continue
         _path = file.split('/')
         alias = _path[-3]
         key = _path[-1][:-5]  # remove the '.json' suffix
         _data = json.loads(fileopt.read_file(file))
         try:
             data[alias][key] = _data
         except KeyError:
             data[alias] = {key: _data}
     return data