Exemple #1
0
 def _setEaterConnectionItem(self, state, key, value):
     if key == 'feed-id':
         self.labels['eating-from'].set_text(str(value))
     # timestamps
     elif key == 'count-timestamp-discont':
         self.labels['timestamp-discont-count-current'].set_text(str(value))
         if value > 0:
             self._expander_discont_current.show()
     elif key == 'time-timestamp-discont':
         text = formatTimeStamp(time.localtime(value))
         self.labels['timestamp-discont-time-current'].set_text(text)
         if value is not None:
             self._vbox_timestamp_discont_current.show()
     elif key == 'last-timestamp-discont':
         text = formatTime(value, fractional=9)
         self.labels['timestamp-discont-last-current'].set_text(text)
         if value > 0.0:
             self._vbox_timestamp_discont_current.show()
     elif key == 'total-timestamp-discont':
         text = formatTime(value, fractional=9)
         self.labels['timestamp-discont-total-current'].set_text(text)
         if value > 0.0:
             self._vbox_timestamp_discont_current.show()
     elif key == 'timestamp-timestamp-discont':
         if value is None:
             return
         text = formatTime(value, fractional=9)
         self.labels['timestamp-discont-timestamp-current'].set_text(text)
     # offsets
     elif key == 'count-offset-discont':
         self.labels['offset-discont-count-current'].set_text(str(value))
         if value > 0:
             self._expander_discont_current.show()
     elif key == 'time-offset-discont':
         text = formatTimeStamp(time.localtime(value))
         self.labels['offset-discont-time-current'].set_text(text)
         if value is not None:
             self._vbox_offset_discont_current.show()
     elif key == 'last-offset-discont':
         text = _("%d units") % value
         self.labels['offset-discont-last-current'].set_text(text)
         if value > 0:
             self._vbox_offset_discont_current.show()
     elif key == 'total-offset-discont':
         text = _("%d units") % value
         self.labels['offset-discont-total-current'].set_text(text)
         if value > 0:
             self._vbox_offset_discont_current.show()
     elif key == 'offset-offset-discont':
         if value is None:
             return
         text = _("%d units") % value
         self.labels['offset-discont-offset-current'].set_text(text)
         if value > 0:
             self._vbox_offset_discont_current.show()
Exemple #2
0
 def _setEaterConnectionItem(self, state, key, value):
     if key == 'feed-id':
         self.labels['eating-from'].set_text(str(value))
     # timestamps
     elif key == 'count-timestamp-discont':
         self.labels['timestamp-discont-count-current'].set_text(str(value))
         if value > 0:
             self._expander_discont_current.show()
     elif key == 'time-timestamp-discont':
         text = formatting.formatTimeStamp(time.localtime(value))
         self.labels['timestamp-discont-time-current'].set_text(text)
         if value is not None:
             self._vbox_timestamp_discont_current.show()
     elif key == 'last-timestamp-discont':
         text = formatting.formatTime(value, fractional=9)
         self.labels['timestamp-discont-last-current'].set_text(text)
         if value > 0.0:
             self._vbox_timestamp_discont_current.show()
     elif key == 'total-timestamp-discont':
         text = formatting.formatTime(value, fractional=9)
         self.labels['timestamp-discont-total-current'].set_text(text)
         if value > 0.0:
             self._vbox_timestamp_discont_current.show()
     elif key == 'timestamp-timestamp-discont':
         if value is None:
             return
         text = formatting.formatTime(value, fractional=9)
         self.labels['timestamp-discont-timestamp-current'].set_text(text)
     # offsets
     elif key == 'count-offset-discont':
         self.labels['offset-discont-count-current'].set_text(str(value))
         if value > 0:
             self._expander_discont_current.show()
     elif key == 'time-offset-discont':
         text = formatting.formatTimeStamp(time.localtime(value))
         self.labels['offset-discont-time-current'].set_text(text)
         if value is not None:
             self._vbox_offset_discont_current.show()
     elif key == 'last-offset-discont':
         text = _("%d units") % value
         self.labels['offset-discont-last-current'].set_text(text)
         if value > 0:
             self._vbox_offset_discont_current.show()
     elif key == 'total-offset-discont':
         text = _("%d units") % value
         self.labels['offset-discont-total-current'].set_text(text)
         if value > 0:
             self._vbox_offset_discont_current.show()
     elif key == 'offset-offset-discont':
         if value is None:
             return
         text = _("%d units") % value
         self.labels['offset-discont-offset-current'].set_text(text)
         if value > 0:
             self._vbox_offset_discont_current.show()
Exemple #3
0
    def get_pipeline_string(self, properties):
        directory = properties['directory']

        self.directory = directory

        self.fixRenamedProperties(properties, [('rotateType', 'rotate-type')])

        rotateType = properties.get('rotate-type', 'none')

        # now act on the properties
        if rotateType == 'size':
            self.setSizeRotate(properties['size'])
            self.uiState.set('rotate-type',
                             'every %sB' % \
                             formatting.formatStorage(properties['size']))
        elif rotateType == 'time':
            self.setTimeRotate(properties['time'])
            self.uiState.set('rotate-type',
                             'every %s' % \
                             formatting.formatTime(properties['time']))
        else:
            self.uiState.set('rotate-type', 'disabled')
        # FIXME: should add a way of saying "do first cycle at this time"

        return self.pipe_template
Exemple #4
0
    def updateState(self, set):
        c = self

        bytes_sent = c.getBytesSent()
        bytes_received = c.getBytesReceived()
        uptime = c.getUptime()

        set('stream-mime', c.get_mime())
        set('stream-url', c.getUrl())
        set('stream-uptime', formatTime(uptime))
        bitspeed = bytes_received * 8 / uptime
        currentbitrate = self.getCurrentBitrate()
        set('stream-bitrate', formatStorage(bitspeed) + 'bit/s')
        set('stream-current-bitrate',
            formatStorage(currentbitrate) + 'bit/s')
        set('stream-totalbytes', formatStorage(bytes_received) + 'Byte')
        set('stream-bitrate-raw', bitspeed)
        set('stream-totalbytes-raw', bytes_received)

        set('clients-current', str(c.getClients()))
        set('clients-max', str(c.getMaxClients()))
        set('clients-peak', str(c.getPeakClients()))
        set('clients-peak-time', c.getPeakEpoch())
        set('clients-average', str(int(c.getAverageClients())))

        bitspeed = bytes_sent * 8 / uptime
        set('consumption-bitrate', formatStorage(bitspeed) + 'bit/s')
        set('consumption-bitrate-current',
            formatStorage(currentbitrate * c.getClients()) + 'bit/s')
        set('consumption-totalbytes', formatStorage(bytes_sent) + 'Byte')
        set('consumption-bitrate-raw', bitspeed)
        set('consumption-totalbytes-raw', bytes_sent)
Exemple #5
0
 def _setEaterTotalTimestampDiscont(self, state, value):
     if value is None:
         return
     text = formatTime(value, fractional=9)
     self.labels['timestamp-discont-total'].set_text(text)
     if value > 0.0:
         self._vbox_timestamp_discont_total.show()
Exemple #6
0
    def _setCurrentTime(self, value):
        if self._startTime is not None:
            runtime = value - self._startTime

            self._label_uptime.set_text(formatting.formatTime(runtime))
        else:
            self._label_uptime.set_text(_("not available"))
Exemple #7
0
    def updateState(self, set):
        c = self

        bytes_sent = c.getBytesSent()
        bytes_received = c.getBytesReceived()
        uptime = c.getUptime()

        set("stream-mime", c.get_mime())
        set("stream-url", c.getUrl())
        set("stream-uptime", formatting.formatTime(uptime))
        bitspeed = bytes_received * 8 / uptime
        currentbitrate = self.getCurrentBitrate()
        set("stream-bitrate", formatting.formatStorage(bitspeed) + "bit/s")
        set("stream-current-bitrate", formatting.formatStorage(currentbitrate) + "bit/s")
        set("stream-totalbytes", formatting.formatStorage(bytes_received) + "Byte")
        set("stream-bitrate-raw", bitspeed)
        set("stream-totalbytes-raw", bytes_received)

        set("clients-current", str(c.getClients()))
        set("clients-max", str(c.getMaxClients()))
        set("clients-peak", str(c.getPeakClients()))
        set("clients-peak-time", c.getPeakEpoch())
        set("clients-average", str(int(c.getAverageClients())))

        bitspeed = bytes_sent * 8 / uptime
        set("consumption-bitrate", formatting.formatStorage(bitspeed) + "bit/s")
        set("consumption-bitrate-current", formatting.formatStorage(currentbitrate * c.getClients()) + "bit/s")
        set("consumption-totalbytes", formatting.formatStorage(bytes_sent) + "Byte")
        set("consumption-bitrate-raw", bitspeed)
        set("consumption-totalbytes-raw", bytes_sent)
    def _setCurrentTime(self, value):
        if self._startTime is not None:
            runtime = value - self._startTime

            self._label_uptime.set_text(formatting.formatTime(runtime))
        else:
            self._label_uptime.set_text(_("not available"))
Exemple #9
0
 def _setEaterTotalTimestampDiscont(self, state, value):
     if value is None:
         return
     text = formatting.formatTime(value, fractional=9)
     self.labels['timestamp-discont-total'].set_text(text)
     if value > 0.0:
         self._vbox_timestamp_discont_total.show()
Exemple #10
0
    def get_pipeline_string(self, properties):
        directory = properties['directory']

        self.directory = directory

        self.fixRenamedProperties(properties, [('rotateType', 'rotate-type')])

        rotateType = properties.get('rotate-type', 'none')

        # now act on the properties
        if rotateType == 'size':
            self.setSizeRotate(properties['size'])
            self.uiState.set('rotate-type',
                             'every %sB' % \
                             formatting.formatStorage(properties['size']))
        elif rotateType == 'time':
            self.setTimeRotate(properties['time'])
            self.uiState.set('rotate-type',
                             'every %s' % \
                             formatting.formatTime(properties['time']))
        else:
            self.uiState.set('rotate-type', 'disabled')
        # FIXME: should add a way of saying "do first cycle at this time"

        return self.pipe_template
Exemple #11
0
    def testReallyLong(self):
        minute = 60
        hour = minute * 60
        day = hour * 24
        week = day * 7

        value = week * 291 + day * 5 + hour * 13 + minute * 5
        assert formatTime(value) == "291 weeks 5 days 13:05"
    def testReallyLong(self):
        minute = 60
        hour = minute * 60
        day = hour * 24
        week = day * 7

        value = week * 291 + day * 5 + hour * 13 + minute * 5
        self.assertEquals(formatting.formatTime(value),
            "291 weeks 5 days 13:05")
Exemple #13
0
    def testReallyLong(self):
        minute = 60
        hour = minute * 60
        day = hour * 24
        week = day * 7

        value = week * 291 + day * 5 + hour * 13 + minute * 5
        self.assertEquals(formatting.formatTime(value),
                          "291 weeks 5 days 13:05")
Exemple #14
0
    def do(self, args):
        if not args:
            return util.unknown('Please specify a log file to check.')
        if len(args) > 1:
            return util.unknown('Please specify only one log file to check.')

        command = "grep '%s' %s | tail -n 1" % (self.options.string,
                                                " ".join(args))
        self.debug('executing %s' % command)
        output = commands.getoutput(command)
        self.debug('output: %s' % output)

        if not output:
            return util.unknown('Could not find string %s in log file' %
                                self.options.string)

        level = output[:5].strip()
        if level not in ['ERROR', 'WARN', 'INFO', 'DEBUG', 'LOG']:
            return util.unknown("Last line is not a log line: '%s'" % output)

        # matches flumotion.extern.log.log
        # level   pid     object   cat      time
        # 5 + 1 + 7 + 1 + 32 + 1 + 17 + 1 + 15 == 80
        position = 5 + 1 + 7 + 1 + 32 + 1 + 17 + 1

        # log timestrings are currently in local time, which might be a mistake
        timestring = output[position:position + 15]
        timetuple = time.strptime(timestring, "%b %d %H:%M:%S")
        now = time.time()
        nowtuple = time.localtime(now)

        # since the year does not get logged, assume the log line is from this
        # year, or last year if the delta becomes negative
        timelist = list(timetuple)
        timelist[0] = nowtuple[0]
        if time.mktime(tuple(timelist)) > time.mktime(nowtuple):
            self.debug('timestamp is past now, so assume it is from last year')
            timelist[0] = nowtuple[0] - 1

        # mktime also works in local time, which hopefully matches the log's
        # local time
        timestamp = time.mktime(tuple(timelist))
        delta = now - int(timestamp)

        msg = 'Last log line%s is %s old.' % (
            self.options.string and " with '%s'" % self.options.string
            or '', formatting.formatTime(delta, fractional=2))
        if delta > int(self.options.critical):
            return util.critical(msg)
        elif delta > int(self.options.warning):
            return util.warning(msg)
        else:
            return util.ok(msg)
Exemple #15
0
    def _onStateSet(self, state):
        # Update the URI
        uri = state.get('stream-url')
        if uri is not None:
            if not self._link:
                self._link = self._createLinkWidget(uri)
            else:
                self._link.set_uri(uri)

        # Update Server Uptime
        uptime = state.get('server-uptime')
        self._uptime.set_text(formatting.formatTime(uptime))
Exemple #16
0
    def do(self, args):
        if not args:
            return util.unknown('Please specify a log file to check.')
        if len(args) > 1:
            return util.unknown('Please specify only one log file to check.')

        command = "grep '%s' %s | tail -n 1" % (
            self.options.string, " ".join(args))
        self.debug('executing %s' % command)
        output = commands.getoutput(command)
        self.debug('output: %s' % output)

        if not output:
            return util.unknown('Could not find string %s in log file' %
                self.options.string)

        level = output[:5].strip()
        if level not in ['ERROR', 'WARN', 'INFO', 'DEBUG', 'LOG']:
            return util.unknown("Last line is not a log line: '%s'" % output)

        # matches flumotion.extern.log.log
        # level   pid     object   cat      time
        # 5 + 1 + 7 + 1 + 32 + 1 + 17 + 1 + 15 == 80
        position = 5 + 1 + 7 + 1 + 32 + 1 + 17 + 1

        # log timestrings are currently in local time, which might be a mistake
        timestring = output[position:position + 15]
        timetuple = time.strptime(timestring, "%b %d %H:%M:%S")
        now = time.time()
        nowtuple = time.localtime(now)

        # since the year does not get logged, assume the log line is from this
        # year, or last year if the delta becomes negative
        timelist = list(timetuple)
        timelist[0] = nowtuple[0]
        if time.mktime(tuple(timelist)) > time.mktime(nowtuple):
            self.debug('timestamp is past now, so assume it is from last year')
            timelist[0] = nowtuple[0] - 1

        # mktime also works in local time, which hopefully matches the log's
        # local time
        timestamp = time.mktime(tuple(timelist))
        delta = now - int(timestamp)

        msg = 'Last log line%s is %s old.' % (
            self.options.string and " with '%s'" % self.options.string or '',
            formatting.formatTime(delta, fractional=2))
        if delta > int(self.options.critical):
            return util.critical(msg)
        elif delta > int(self.options.warning):
            return util.warning(msg)
        else:
            return util.ok(msg)
Exemple #17
0
    def _onStateSet(self, state):
        # Update the URI
        uri = state.get('stream-url')
        if uri is not None:
            if not self._link and uri:
                self._link = self._createLinkWidget(uri)
            elif self._link:
                self._link.set_uri(uri)
                self._link.set_label(uri)

        # Update Server Uptime
        uptime = state.get('server-uptime')
        self._uptime.set_text(formatting.formatTime(uptime))
Exemple #18
0
    def get_pipeline_string(self, properties):
        directory = properties['directory']

        self.directory = directory

        self.fixRenamedProperties(properties, [('rotateType', 'rotate-type')])

        rotateType = properties.get('rotate-type', 'none')

        # validate rotate-type and size/time properties first
        if not rotateType in ['none', 'size', 'time']:
            m = messages.Error(T_(N_(
                "The configuration property 'rotate-type' should be set to "
                "'size', time', or 'none', not '%s'. "
                "Please fix the configuration."),
                    rotateType), mid='rotate-type')
            self.addMessage(m)
            raise errors.ComponentSetupHandledError()

        # size and time types need the property specified
        if rotateType in ['size', 'time']:
            if rotateType not in properties.keys():
                m = messages.Error(T_(N_(
                    "The configuration property '%s' should be set. "
                    "Please fix the configuration."),
                        rotateType), mid='rotate-type')
                self.addMessage(m)
                raise errors.ComponentSetupHandledError()

        # now act on the properties
        if rotateType == 'size':
            self.setSizeRotate(properties['size'])
            self.uiState.set('rotate-type',
                             'every %sB' % \
                             format.formatStorage(properties['size']))
        elif rotateType == 'time':
            self.setTimeRotate(properties['time'])
            self.uiState.set('rotate-type',
                             'every %s' % \
                             format.formatTime(properties['time']))
        else:
            self.uiState.set('rotate-type', 'disabled')
        # FIXME: should add a way of saying "do first cycle at this time"

        return self.pipe_template
Exemple #19
0
    def updateState(self, set):
        c = self

        bytes_sent = c.getBytesSent()
        bytes_received = c.getBytesReceived()
        uptime = c.getUptime()

        set('stream-mime', c.get_mime())
        set('stream-url', c.getUrl())
        set('stream-uptime', formatting.formatTime(uptime))
        bitspeed = bytes_received * 8 / uptime
        currentbitrate = self.getCurrentBitrate()
        set('stream-bitrate', formatting.formatStorage(bitspeed) + 'bit/s')
        set('stream-current-bitrate',
            formatting.formatStorage(currentbitrate) + 'bit/s')
        set('stream-totalbytes',
            formatting.formatStorage(bytes_received) + 'Byte')
        set('stream-bitrate-raw', bitspeed)
        set('stream-totalbytes-raw', bytes_received)

        set('clients-current', str(c.getClients()))
        set('clients-max', str(c.getMaxClients()))
        set('clients-peak', str(c.getPeakClients()))
        set('clients-peak-time', c.getPeakEpoch())
        set('clients-average', str(int(c.getAverageClients())))

        bitspeed = bytes_sent * 8 / uptime
        set('consumption-bitrate',
            formatting.formatStorage(bitspeed) + 'bit/s')
        set(
            'consumption-bitrate-current',
            formatting.formatStorage(currentbitrate * c.getClients()) +
            'bit/s')
        set('consumption-totalbytes',
            formatting.formatStorage(bytes_sent) + 'Byte')
        set('consumption-bitrate-raw', bitspeed)
        set('consumption-totalbytes-raw', bytes_sent)
 def testYear(self):
     value = 60 * 60 * 24 * 365
     self.assertEquals(formatting.formatTime(value), "52 weeks 1 day 00:00")
 def testWeek(self):
     value = 60 * 60 * 24 * 7
     self.assertEquals(formatting.formatTime(value), "1 week 00:00")
 def testDay(self):
     value = 60 * 60 * 24
     self.assertEquals(formatting.formatTime(value), "1 day 00:00")
 def testMinuteSecond(self):
     value = 60 + 1
     self.assertEquals(formatting.formatTime(value), "00:01")
 def testFractionalSecond(self):
     value = 1.1
     self.assertEquals(formatting.formatTime(value, fractional=2),
         "00:00:01.10")
Exemple #25
0
 def testWeeks(self):
     value = 60 * 60 * 24 * 7 * 2
     self.assertEquals(formatting.formatTime(value), "2 weeks 00:00")
Exemple #26
0
 def testWeek(self):
     value = 60 * 60 * 24 * 7
     assert formatTime(value) == "1 week 00:00"
    def _setStartTime(self, value):
        self._label_start_time.set_text(
            time.strftime("%c", time.localtime(value)))
        self._label_uptime.set_text(formatting.formatTime(0))

        self._startTime = value
Exemple #28
0
    def _setStartTime(self, value):
        self._label_start_time.set_text(
            time.strftime("%c", time.localtime(value)))
        self._label_uptime.set_text(formatting.formatTime(0))

        self._startTime = value
Exemple #29
0
 def testWeeks(self):
     value = 60 * 60 * 24 * 7 * 2
     assert formatTime(value) == "2 weeks 00:00"
Exemple #30
0
 def testYear(self):
     value = 60 * 60 * 24 * 365
     assert formatTime(value) == "52 weeks 1 day 00:00"
Exemple #31
0
 def _updateDisconnectionTime(self):
     if self._lastDisconnect:
         text = formatTime(time.time() - self._lastDisconnect)
         self.labels['disconnection-time'].set_text(text)
Exemple #32
0
 def updateConnectionTime(self):
     if self._lastConnect:
         text = formatTime(time.time() - self._lastConnect)
         self.labels["connection-time"].set_text(text)
Exemple #33
0
 def updateDisconnectionTime(self):
     if self._lastDisconnect:
         text = formatting.formatTime(time.time() - self._lastDisconnect)
         self.labels['disconnection-time'].set_text(text)
Exemple #34
0
 def testDays(self):
     value = 60 * 60 * 24 * 2
     assert formatTime(value) == "2 days 00:00"
Exemple #35
0
 def testWeek(self):
     value = 60 * 60 * 24 * 7
     self.assertEquals(formatting.formatTime(value), "1 week 00:00")
Exemple #36
0
 def testNegative(self):
     self.assertEquals(formatting.formatTime(-1.0, fractional=1),
                       "- 00:00:01.0")
Exemple #37
0
 def testYear(self):
     value = 60 * 60 * 24 * 365
     self.assertEquals(formatting.formatTime(value), "52 weeks 1 day 00:00")
Exemple #38
0
 def testFractionalSecond(self):
     value = 1.1
     self.assertEquals(formatting.formatTime(value, fractional=2),
                       "00:00:01.10")
 def testNegative(self):
     self.assertEquals(formatting.formatTime(-1.0, fractional=1),
         "- 00:00:01.0")
Exemple #40
0
 def testSecond(self):
     value = 1
     self.assertEquals(formatting.formatTime(value), "00:00")
 def testSecond(self):
     value = 1
     self.assertEquals(formatting.formatTime(value), "00:00")
Exemple #42
0
 def _updateConnectionTime(self):
     if self._lastConnect:
         text = formatting.formatTime(time.time() - self._lastConnect)
         self.labels['connection-time'].set_text(text)
 def testHourMinuteSecond(self):
     value = 60 * 60 + 60 + 2
     self.assertEquals(formatting.formatTime(value), "01:01")
Exemple #44
0
 def testHourMinuteSecond(self):
     value = 60 * 60 + 60 + 2
     self.assertEquals(formatting.formatTime(value), "01:01")
 def testDays(self):
     value = 60 * 60 * 24 * 2
     self.assertEquals(formatting.formatTime(value), "2 days 00:00")
Exemple #46
0
 def testDay(self):
     value = 60 * 60 * 24
     self.assertEquals(formatting.formatTime(value), "1 day 00:00")
 def testWeeks(self):
     value = 60 * 60 * 24 * 7 * 2
     self.assertEquals(formatting.formatTime(value), "2 weeks 00:00")
Exemple #48
0
 def testDays(self):
     value = 60 * 60 * 24 * 2
     self.assertEquals(formatting.formatTime(value), "2 days 00:00")
Exemple #49
0
 def testMinuteSecond(self):
     value = 60 + 1
     self.assertEquals(formatting.formatTime(value), "00:01")
 def updateDisconnectionTime(self):
     if self._lastDisconnect:
         text = formatting.formatTime(time.time() - self._lastDisconnect)
         self.labels["disconnection-time"].set_text(text)