Example #1
0
 def _flush_all(self):
     now = unix_time(datetime.utcnow())
     containers = self.containers.copy()
     for cid,c in list(containers.items()):
         c.flush()
         if now - c.last_read > self.maint_interval:
             c.delete()
             del self.containers[cid]
             log.debug('cleared stale container %s' % cid)
Example #2
0
    def _get_container(self, key):
        """
        Fetch all fields in a hash key from redis, mapping to types defined
        in self.keys. Return None if any keys are missing or last update
        was > 10s ago.
        """
        now = unix_time(datetime.utcnow())
        container = self.redis.hgetall(key)

        if False in [k in container for k in self.keys]:
            return None

        stat = { k:convert_type(container[k],t) for \
                    k,t in list(self.keys.items()) }

        if now - stat['last_read'] > 10:
            return None

        return stat
Example #3
0
    def append_stat(self, stat):
        self.last_read = unix_time(stat.timestamp)

        self.current["name"] = stat.name
        self.current["source"] = stat.source
        self.current["last_read"] = self.last_read

        if len(self.stats) > 0:
            last_stat = self.stats[-1]
            self.current["cpu"] = self._calculate_cpu(stat, last_stat)

        self.current["mem"] = float(stat.memory_stats.usage)
        self.current["net_tx_bytes_total"] = float(stat.network.tx_bytes)
        self.current["net_rx_bytes_total"] = float(stat.network.rx_bytes)

        read_io, write_io = self._get_rw_io(stat)
        self.current["io_read_bytes_total"] = read_io
        self.current["io_write_bytes_total"] = write_io

        self.redis.hincrby(self.key, "stats_read", amount=1)
        self.redis.hmset(self.key, self.current)

        self.stats.append(stat)