Ejemplo n.º 1
0
    def collect_user_sessions(self, from_date=None, to_date=None, inclusive_to=False, whitelist=None):
        t_start = timeutils.date_str_to_epoch(from_date) or float('-inf')
        t_end = timeutils.date_str_to_epoch(to_date or timeutils.latest_log_date_str(self.logs_dir))
        # TODO inclusive_to
        user_sessions = {}  # uuid -> [sessions]

        def crop_and_add(uuid, t_from, t_to, name):
            if whitelist and uuid not in whitelist:
                return
            # crop to interval
            t_from = max(t_from, t_start)
            t_to = min(t_to, t_end)
            if t_from >= t_to:
                return
            # add data to collection
            if uuid not in user_sessions:
                user_sessions[uuid] = []
            user_sessions[uuid].append([uuid, t_from, t_to, name])

        times, online = self.collect_data(from_date, to_date, inclusive_to)
        for uuid, t_from, t_to, name in times:
            crop_and_add(uuid, t_from, t_to, name)
        for name, sess_begin in online.items():
            uuid, t_from = sess_begin[:2]
            crop_and_add(uuid, t_from, t_end, name)
        return user_sessions
Ejemplo n.º 2
0
 def collect_uptimes(self, from_date=None, to_date=None, inclusive_to=False):
     from_day, to_day, inclusive_to = self.date_to_log_day(from_date, to_date, inclusive_to)
     first_event = None
     for log_file in self.read_interval_iter(from_day, to_day, inclusive_to):
         if log_file.started and log_file.prev_log and not log_file.prev_log.stopped:
             log_file.prev_log.read_log()
             if not log_file.prev_log.stopped:
                 yield (first_event or timeutils.date_str_to_epoch(from_date),
                 log_file.prev_log.last_event)
                 first_event = None
         if not first_event:
             first_event = log_file.first_event if log_file.started \
                 else timeutils.date_str_to_epoch(from_date)
         if log_file.stopped:
             yield (first_event, log_file.last_event)
             first_event = None
     if first_event:
         yield (first_event, timeutils.date_str_to_epoch(
             to_date or timeutils.latest_log_date_str(self.logs_dir)))
Ejemplo n.º 3
0
    def __init__(self, logs_dir, log_name, prev_log=None):
        self.log_name = log_name
        self.prev_log = prev_log
        self.log_path = os.path.join(logs_dir, log_name + '.log')
        if self.log_name == 'latest':
            # for timestamps in log lines
            self.day_str = timeutils.ensure_day_only(timeutils.latest_log_date_str(logs_dir))
        else:
            self.day_str = self.log_name.rsplit('-', 1)[0]
        self.uuids = {}  # name -> last associated UUID
        self.been_read = False

        self.yaml_attributes = 'started', 'stopped', 'first_event', 'last_event', 'online', 'times'
        self.started = None
        self.stopped = None
        self.first_event = None
        self.last_event = None
        self.online = {}
        self.times = []