Beispiel #1
0
    def load(cls, filename="onionperf.analysis.json.xz", input_prefix=os.getcwd(), version=1.0):
        filepath = os.path.abspath(os.path.expanduser("{0}".format(filename)))
        if not os.path.exists(filepath):
            filepath = os.path.abspath(os.path.expanduser("{0}/{1}".format(input_prefix, filename)))
            if not os.path.exists(filepath):
                logging.warning("file does not exist at '{0}'".format(filepath))
                return None

        logging.info("loading analysis results from {0}".format(filepath))

        inf = util.DataSource(filepath)
        inf.open()
        db = json.load(inf.get_file_handle())
        inf.close()

        logging.info("done!")

        if 'type' not in db or 'version' not in db:
            logging.warning("'type' or 'version' not present in database")
            return None
        elif db['type'] != 'onionperf' or db['version'] != 1.0:
            logging.warning("type or version not supported (type={0}, version={1})".format(db['type'], db['version']))
            return None
        else:
            analysis_instance = cls()
            analysis_instance.json_db = db
            return analysis_instance
Beispiel #2
0
    def analyze(self, do_simple=True, date_filter=None):
        if self.did_analysis:
            return

        self.date_filter = date_filter
        tgen_parser = TGenParser(date_filter=self.date_filter)
        torctl_parser = TorCtlParser(date_filter=self.date_filter)

        for (filepaths, parser,
             json_db_key) in [(self.tgen_filepaths, tgen_parser, 'tgen'),
                              (self.torctl_filepaths, torctl_parser, 'tor')]:
            if len(filepaths) > 0:
                for filepath in filepaths:
                    logging.info("parsing log file at {0}".format(filepath))
                    parser.parse(util.DataSource(filepath),
                                 do_simple=do_simple)

                if self.nickname is None:
                    parsed_name = parser.get_name()
                    if parsed_name is not None:
                        self.nickname = parsed_name
                    elif self.hostname is not None:
                        self.nickname = self.hostname
                    else:
                        self.nickname = "unknown"

                if self.measurement_ip is None:
                    self.measurement_ip = "unknown"

                self.json_db['data'].setdefault(
                    self.nickname, {
                        'measurement_ip': self.measurement_ip
                    }).setdefault(json_db_key, parser.get_data())

        self.did_analysis = True
Beispiel #3
0
 def analyze(self, do_simple=True):
     for (filepaths, parser, json_db_key) in [(self.tgen_filepaths, TGenParser(), 'tgen'), (self.torctl_filepaths, TorCtlParser(), 'tor')]:
         if len(filepaths) > 0:
             for filepath in filepaths:
                 logging.info("parsing log file at {0}".format(filepath))
                 parser.parse(util.DataSource(filepath), do_simple=do_simple)
             parsed_name = parser.get_name()
             n = self.nickname
             if n is None:
                 n = parsed_name if parsed_name is not None else self.hostname
             self.json_db['data'].setdefault(n, {}).setdefault(json_db_key, parser.get_data())