Exemplo n.º 1
0
    def checkOneRollover(self, cursor, previous, current):
        """Check for rollovers in one pair of consecutive time intervals,
           like yesterday/today or lastMonth/thisMonth. This is meant to
           be run inside a database interaction.
           """
        # Delete counters that are too old to bother keeping at all
        cursor.execute(
            "DELETE FROM stats_counters "
            "WHERE (name = %s OR name = %s) "
            "AND first_time < %s" %
            (Database.quote(previous,
                            'varchar'), Database.quote(current, 'varchar'),
             Database.quote(
                 long(TimeUtil.Interval(previous).getFirstTimestamp()),
                 'bigint')))

        # Roll over remaining counters that are too old for current
        # but still within the range of previous. Note that there is a
        # race condition in which this update will fail because a timer
        # has been incremented between it and the above DELETE. It could
        # be prevented by locking the table, but it's probably not worth
        # it. If the rollover fails this time, it will get another chance.
        cursor.execute(
            "UPDATE stats_counters SET name = %s "
            "WHERE name = %s "
            "AND first_time < %s" %
            (Database.quote(previous,
                            'varchar'), Database.quote(current, 'varchar'),
             Database.quote(
                 long(TimeUtil.Interval(current).getFirstTimestamp()),
                 'bigint')))
Exemplo n.º 2
0
Arquivo: Info.py Projeto: Kays/cia-vc
 def render_sysUptime(self, context):
     # This only works on linux systems for now
     try:
         seconds = float(open("/proc/uptime").read().split()[0])
     except:
         return "System uptime unknown"
     else:
         return ["This system has been up for ",
                 Template.value[ TimeUtil.formatDuration(seconds) ]]
Exemplo n.º 3
0
 def _render_averagePeriod(self, counter, result):
     if not counter:
         result.callback('')
         return
     events = counter.get('eventCount', 0)
     first = counter.get('firstEventTime')
     if events < 2 or not first:
         result.callback('')
         return
     result.callback([
         ', for an average of ',
         Template.value[ TimeUtil.formatDuration( (time.time() - first) / events ) ],
         ' between messages',
         ])
Exemplo n.º 4
0
 def _render_averagePeriod(self, counter, result):
     if not counter:
         result.callback('')
         return
     events = counter.get('eventCount', 0)
     first = counter.get('firstEventTime')
     if events < 2 or not first:
         result.callback('')
         return
     result.callback([
         ', for an average of ',
         Template.value[TimeUtil.formatDuration(
             (time.time() - first) / events)],
         ' between messages',
     ])
Exemplo n.º 5
0
    def remote_getStatusText(self):
        """Get a textual description of this bot's status"""
        indicators = []

        if self.remote_isFull():
            indicators.append('full')

        if self.remote_isEmpty():
            indicators.append('empty')

        timer = self.remote_getInactivity()
        if timer:
            indicators.append('GC in %s' %
                              TimeUtil.formatDuration(timer - time.time()))

        return ', '.join(indicators)
Exemplo n.º 6
0
Arquivo: Feed.py Projeto: Kays/cia-vc
    def render_item(self, context, id, content):
        url = Link.MessageLink(self.target, id).getURL(context)
        m = Message.Message(content)
        tags = [
            tag('link')[ url ],
            tag('dc:date')[ TimeUtil.formatDateISO8601(XML.digValue(m.xml, int, "message", "timestamp")) ],
            tag('description')[ quote(self.formatMessage(m)) ],
            ]

        # Generate a title if we can, but if we can't don't worry too much
        try:
            tags.append(tag('title')[ Formatters.getFactory().findMedium('title', m).formatMessage(m) ])
        except Message.NoFormatterError:
            pass

        return tag('item', **{'rdf:about': url})[tags]
Exemplo n.º 7
0
Arquivo: Feed.py Projeto: Kays/cia-vc
    def messageToItemContent(self, context, m, id):
        """Render an XML message as the content of an RSS <item>"""
        url = Link.MessageLink(self.target, id).getURL(context)
        tags = [
            tag('pubDate')[ TimeUtil.formatDateRFC822(XML.digValue(m.xml, int, "message", "timestamp")) ],
            tag('guid')[url],
            tag('link')[url],
            tag('description')[ quote(self.formatMessage(m)) ],
            ]

        # Generate a title if we can, but if we can't don't worry too much
        try:
            tags.append(tag('title')[ Formatters.getFactory().findMedium('title', m).formatMessage(m) ])
        except Message.NoFormatterError:
            pass

        return tags
Exemplo n.º 8
0
 def render_data(self, context, message):
     value = self.getValue(message)
     if value:
         return TimeUtil.formatRelativeDate(value)
     else:
         return Template.error["Invalid Date"]
Exemplo n.º 9
0
 def filter_relativeDate(self, value):
     return TimeUtil.formatDuration(time.time() - value)
Exemplo n.º 10
0
 def filter_relativeDate(self, value):
     return TimeUtil.formatDuration(time.time() - value)
Exemplo n.º 11
0
 def filter_date(self, value):
     return TimeUtil.formatDate(value)
Exemplo n.º 12
0
 def render_time(self, context):
     return TimeUtil.formatDateRFC822(time.time())
Exemplo n.º 13
0
Arquivo: Info.py Projeto: Kays/cia-vc
 def render_mtbr(self, context):
     site = context['request'].site
     if site.requestCount > 0:
         return TimeUtil.formatDuration((time.time() - site.serverStartTime) / site.requestCount)
     else:
         return Template.error["unknown"]
Exemplo n.º 14
0
Arquivo: Info.py Projeto: Kays/cia-vc
 def render_uptime(self, context):
     return TimeUtil.formatDuration(time.time() - context['request'].site.serverStartTime)
Exemplo n.º 15
0
 def filter_date(self, value):
     return TimeUtil.formatDate(value)
Exemplo n.º 16
0
 def render_data(self, context, message):
     value = self.getValue(message)
     if value:
         return TimeUtil.formatRelativeDate(value)
     else:
         return Template.error[ "Invalid Date" ]
Exemplo n.º 17
0
 def render_time(self, context):
     return TimeUtil.formatDateRFC822(time.time())
Exemplo n.º 18
0
 def render_data(self, context, target):
     value = self.getValue(target)
     if value is None:
         return ''
     else:
         return "%s ago" % TimeUtil.formatDuration(self.getValue(target))
Exemplo n.º 19
0
 def format_timestamp(self, stamp):
     return ["Received ", Template.value[TimeUtil.formatRelativeDate(int(XML.shallowText(stamp)))]]
Exemplo n.º 20
0
 def render_data(self, context, target):
     value = self.getValue(target)
     if value is None:
         return ''
     else:
         return "%s ago" % TimeUtil.formatDuration(self.getValue(target))
Exemplo n.º 21
0
 def format_timestamp(self, stamp):
     return ["Received ", Template.value[TimeUtil.formatRelativeDate(int(XML.shallowText(stamp)))]]
Exemplo n.º 22
0
Arquivo: Info.py Projeto: Kays/cia-vc
 def render_rows(self, context):
     return [TimeUtil.formatDate(time.time())]