Example #1
0
    def cleanup(self):
        self._cleanupCounter += 1
        if self._cleanupCounter < 5:
            return
        debug("before cleanup:")
        debug("   _state               %d" % len(self._state))
        debug("   _origin              %d" % len(self._origin))
        debug("   _magnitude           %d" % len(self._magnitude))
        debug("   _focalmechanism      %d" % len(self._focalmechanism))
        debug("   public object count  %d" % (PublicObject.ObjectCount()))
        # we first remove those origins and magnitudes, which are
        # older than one hour and are not preferred anywhere.
        limit = Time.GMT() + TimeSpan(-self._cleanup_interval)

        originIDs = self._origin.keys()
        for oid in originIDs:
            if self._origin[oid].creationInfo().creationTime() < limit:
                del self._origin[oid]

        magnitudeIDs = self._magnitude.keys()
        for oid in magnitudeIDs:
            if self._magnitude[oid] is None:
                # This should actually never happen!
                error("Magnitude %s is None!" % oid)
                del self._magnitude[oid]
                continue
            if self._magnitude[oid].creationInfo().creationTime() < limit:
                del self._magnitude[oid]

        focalmechanismIDs = self._focalmechanism.keys()
        for oid in focalmechanismIDs:
            if self._focalmechanism[oid].creationInfo().creationTime() < limit:
                del self._focalmechanism[oid]

        # finally remove all remaining objects older than two hours
        limit = Time.GMT() + TimeSpan(-2 * self._cleanup_interval)
        to_delete = []
        for evid in self._state:
            org = self._state[evid].origin
            if org and org.time().value() > limit:
                continue  # nothing to do with this event
            to_delete.append(evid)
        for evid in to_delete:
            del self._state[evid]

        debug("After cleanup:")
        debug("   _state               %d" % len(self._state))
        debug("   _origin              %d" % len(self._origin))
        debug("   _magnitude           %d" % len(self._magnitude))
        debug("   _focalmechanism      %d" % len(self._focalmechanism))
        debug("   public object count  %d" % (PublicObject.ObjectCount()))
        debug("-------------------------------")
        self._cleanupCounter = 0
Example #2
0
    def __init__(self):
        self.service = ""
        self.accessTime = Time.GMT()
        self.userName = None

        self.time = None
        self.channel = None
        self.geo = None

        self.noData = http.NO_CONTENT
        self.format = None

        self._args = {}
        self.streams = []  # 1 entry for GET, multipl
Example #3
0
    def __init__(self, req, ro, code, length, err):
        # user agent
        agent = req.getHeader("User-Agent")
        if agent is None:
            agent = ""
        else:
            agent = agent[:100].replace('|', ' ')

        if err is None:
            err = ""

        service, user, accessTime, procTime = "", "", "", 0
        net, sta, loc, cha = "", "", "", ""
        if ro is not None:
            # processing time in milliseconds
            procTime = int((Time.GMT() - ro.accessTime).length() * 1000.0)

            service = ro.service
            if ro.userName is not None:
                user = ro.userName
            accessTime = str(ro.accessTime)

            if ro.channel is not None:
                if ro.channel.net is not None:
                    net = ",".join(ro.channel.net)
                if ro.channel.sta is not None:
                    sta = ",".join(ro.channel.sta)
                if ro.channel.loc is not None:
                    loc = ",".join(ro.channel.loc)
                if ro.channel.cha is not None:
                    cha = ",".join(ro.channel.cha)

        # The host name of the client is resolved in the __str__ method by the
        # logging thread so that a long running DNS reverse lookup may not slow
        # down the request
        self.msgPrefix = "%s|%s|%s|" % (service, req.getRequestHostname(),
                                        accessTime)

        xff = req.requestHeaders.getRawHeaders("x-forwarded-for")
        if xff:
            self.userIP = xff[0].split(",")[0].strip()
        else:
            self.userIP = req.getClientIP()

        self.clientIP = req.getClientIP()
        self.msgSuffix = "|%s|%i|%i|%s|%s|%i|%s|%s|%s|%s|%s||" % (
            self.clientIP, length, procTime, err, agent, code, user, net, sta,
            loc, cha)
Example #4
0
    def __init__(self, args=None):
        self.service = ""
        self.accessTime = Time.GMT()
        self.userName = None

        self.time = None
        self.channel = None
        self.geo = None

        self.noData = http.NO_CONTENT
        self.format = None

        # transform keys to lower case
        self._args = {}
        if args is not None:
            for key in args.keys():
                self._args[key.lower()] = args[key]

        self.streams = []  # 1 entry for GET, multipl
Example #5
0
    def __init__(self, args=None):
        self.service = ""
        self.accessTime = Time.GMT()
        self.userName = None

        self.time = None
        self.channel = None
        self.geo = None

        self.noData = http.NO_CONTENT
        self.format = None

        # transform keys to lower case
        self._args = {}
        if args is not None:
            for k, v in iteritems(args):
                self._args[py3ustr(k.lower())] = py3ustrlist(v)

        self.streams = []  # 1 entry for GET, multipl