コード例 #1
0
ファイル: mem.py プロジェクト: kadircet/i3pystatus-plugins
    def run(self):
        memory_usage = virtual_memory()
        used = memory_usage.used - memory_usage.cached - memory_usage.buffers

        if memory_usage.percent >= self.alert_percentage:
            color = self.alert_color

        elif memory_usage.percent >= self.warn_percentage:
            color = self.warn_color
        else:
            color = self.color

        cdict = {
            "used_mem": used / self.divisor,
            "avail_mem": memory_usage.available / self.divisor,
            "total_mem": memory_usage.total / self.divisor,
            "percent_used_mem": memory_usage.percent,
        }
        round_dict(cdict, self.round_size)

        self.data = cdict
        self.output = {
            "full_text": self.format.format(**cdict),
            "color": color
        }
コード例 #2
0
    def get_usage(self, interface):
        self.update_counters(interface)
        usage = dict(bytes_sent=0, bytes_recv=0, packets_sent=0, packets_recv=0)

        if not sysfs_interface_up(interface, self.unknown_up) or not self.pnic_before:
            return usage
        else:
            usage["bytes_sent"] = self.get_bytes_sent()
            usage["bytes_recv"] = self.get_bytes_received()
            usage["packets_sent"] = self.get_packets_sent()
            usage["packets_recv"] = self.get_packets_received()
            round_dict(usage, self.round_size)
        return usage
コード例 #3
0
    def run(self):
        if os.path.isdir(self.path) and not os.path.ismount(self.path):
            if len(os.listdir(self.path)) == 0:
                self.not_mounted()
                return

        try:
            stat = os.statvfs(self.path)
        except Exception:
            self.not_mounted()
            return

        available = (stat.f_bsize * stat.f_bavail) / self.divisor

        if available > self.display_limit:
            self.output = {}
            return

        critical = available < self.critical_limit

        cdict = {
            "total": (stat.f_bsize * stat.f_blocks) / self.divisor,
            "free": (stat.f_bsize * stat.f_bfree) / self.divisor,
            "avail":
            available,
            "used": (stat.f_bsize *
                     (stat.f_blocks - stat.f_bfree)) / self.divisor,
            "percentage_free":
            stat.f_bfree / stat.f_blocks * 100,
            "percentage_avail":
            stat.f_bavail / stat.f_blocks * 100,
            "percentage_used":
            (stat.f_blocks - stat.f_bfree) / stat.f_blocks * 100,
        }
        round_dict(cdict, self.round_size)

        self.data = cdict
        self.output = {
            "full_text": self.format.format(**cdict),
            "color": self.critical_color if critical else self.color,
            "urgent": critical
        }
コード例 #4
0
ファイル: network_traffic.py プロジェクト: hasB4K/configs
 def run(self):
     self.update_counters()
     cdict = {
         "bytes_sent": float(0),
         "bytes_recv": float(0),
         "packets_sent": float(0),
         "packets_recv": float(0),
     }
     for interface in self.interfaces:
         if self.sysfs_interface_up(interface):
             if not self.pnic_before or interface not in self.pnic_before:
                 continue
             cdict["bytes_sent"] = self.get_bytes_sent(interface)
             cdict["bytes_recv"] = self.get_bytes_received(interface)
             cdict["packets_sent"] = self.get_packets_sent(interface)
             cdict["packets_recv"] = self.get_packets_received(interface)
     round_dict(cdict, self.round_size)
     self.output = {
         "full_text": self.format.format(**cdict),
         "color": self.color
     }
コード例 #5
0
    def run(self):
        if os.path.isdir(self.path) and not os.path.ismount(self.path):
            if len(os.listdir(self.path)) == 0:
                self.not_mounted()
                return

        try:
            stat = os.statvfs(self.path)

            if self._fs_type != 'btrfs':
                available = (stat.f_bsize * stat.f_bavail) / self.divisor
                percentage_avail = stat.f_bavail / stat.f_blocks * 100

                cdict = {
                    "total": (stat.f_bsize * stat.f_blocks) / self.divisor,
                    "free": (stat.f_bsize * stat.f_bfree) / self.divisor,
                    "avail": available,
                    "used": (stat.f_bsize * (stat.f_blocks - stat.f_bfree)) / self.divisor,
                    "percentage_free": stat.f_bfree / stat.f_blocks * 100,
                    "percentage_avail": percentage_avail,
                    "percentage_used": (stat.f_blocks - stat.f_bfree) / stat.f_blocks * 100,
                }

            else:
                btrfs_usage = self._get_btrfs_usage(self.path)
                match = self.regex.findall(btrfs_usage)
                total_bytes = int(match[0][0])
                free_estimated = int(match[0][1])
                available = free_estimated / self.divisor
                percentage_avail = free_estimated / total_bytes * 100

                cdict = {
                    "total": total_bytes / self.divisor,
                    "free": available,
                    "avail": available,
                    "used": (total_bytes - free_estimated) / self.divisor,
                    "percentage_free": percentage_avail,
                    "percentage_avail": percentage_avail,
                    "percentage_used": 100 - percentage_avail,
                }

        except Exception as ex:
            self.not_mounted()
            return

        if available > self.display_limit:
            self.output = {}
            return

        if self.critical_limit:
            color = self.alert_color if available < self.critical_limit else self.color
        else:
            if percentage_avail < self.percentage_critical_limit:
                color = self.alert_color
            elif percentage_avail < self.percentage_alert_limit:
                color = self.warn_color
            else:
                color = self.color

        round_dict(cdict, self.round_size)

        self.data = cdict
        self.output = {
            "full_text": self.format.format(**cdict),
            "color": color
        }