コード例 #1
0
    def stats(self):
        cpu_total = 0.0
        cpu_system = 0.0
        cpu_percent = 0.0
        for x in self.d.stats(self.container_id, decode=True, stream=True):
            blk_read, blk_write = calculate_blkio_bytes(x)
            net_r, net_w = calculate_network_bytes(x)
            mem_current = x["memory_stats"]["usage"]
            mem_total = x["memory_stats"]["limit"]

            try:
                cpu_percent, cpu_system, cpu_total = calculate_cpu_percent2(
                    x, cpu_total, cpu_system)
            except KeyError as e:
                logger.error(
                    "error while getting new CPU stats: %r, falling back")
                cpu_percent = calculate_cpu_percent(x)

            r = {
                "cpu_percent": cpu_percent,
                "mem_current": mem_current,
                "mem_total": x["memory_stats"]["limit"],
                "mem_percent": (mem_current / mem_total) * 100.0,
                "blk_read": blk_read,
                "blk_write": blk_write,
                "net_rx": net_r,
                "net_tx": net_w,
            }
            yield r
コード例 #2
0
ファイル: docker_backend.py プロジェクト: TomasTomecek/sen
 def stats(self):
     for x in self.d.stats(self.container_id, decode=True, stream=True):
         blk_read, blk_write = calculate_blkio_bytes(x)
         net_r, net_w = calculate_network_bytes(x)
         mem_current = x["memory_stats"]["usage"]
         mem_total = x["memory_stats"]["limit"]
         r = {
             "cpu_percent": calculate_cpu_percent(x),
             "mem_current": mem_current,
             "mem_total": x["memory_stats"]["limit"],
             "mem_percent": (mem_current / mem_total) * 100.0,
             "blk_read": blk_read,
             "blk_write": blk_write,
             "net_rx": net_r,
             "net_tx": net_w,
         }
         yield r
コード例 #3
0
 def stats(self):
     for x in self.d.stats(self.container_id, decode=True, stream=True):
         blk_read, blk_write = calculate_blkio_bytes(x)
         net_r, net_w = calculate_network_bytes(x)
         mem_current = x["memory_stats"]["usage"]
         mem_total = x["memory_stats"]["limit"]
         r = {
             "cpu_percent": calculate_cpu_percent(x),
             "mem_current": mem_current,
             "mem_total": x["memory_stats"]["limit"],
             "mem_percent": (mem_current / mem_total) * 100.0,
             "blk_read": blk_read,
             "blk_write": blk_write,
             "net_rx": net_r,
             "net_tx": net_w,
         }
         yield r