[modules] Add support for disk utilization
Add a new module "disk" that takes an optional parameter (the path) and displays free & total disk space, along with the usage percentage. Also, added Tunnel/VPN support to the themeing of the "net" module.
This commit is contained in:
parent
b235ae88a4
commit
bb6ca556c7
5 changed files with 59 additions and 14 deletions
25
bumblebee/modules/disk.py
Normal file
25
bumblebee/modules/disk.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
import os
|
||||
import bumblebee.util
|
||||
import bumblebee.module
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, args):
|
||||
super(Module, self).__init__(args)
|
||||
self._path = args[0] if args else "/"
|
||||
|
||||
def data(self):
|
||||
st = os.statvfs(self._path)
|
||||
|
||||
self._size = st.f_frsize*st.f_blocks
|
||||
self._free = st.f_frsize*st.f_bavail
|
||||
self._perc = 100.0*self._free/self._size
|
||||
|
||||
return "{} {}/{} ({:05.02f}%)".format(self._path, bumblebee.util.bytefmt(self._free), bumblebee.util.bytefmt(self._size), self._perc)
|
||||
|
||||
def warning(self):
|
||||
return self._perc < 20
|
||||
|
||||
def critical(self):
|
||||
return self._perc < 10
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
|
@ -1,12 +1,6 @@
|
|||
import bumblebee.module
|
||||
import psutil
|
||||
|
||||
def fmt(num, suffix='B'):
|
||||
for unit in [ "", "Ki", "Mi", "Gi" ]:
|
||||
if num < 1024.0:
|
||||
return "{:.2f}{}{}".format(num, unit, suffix)
|
||||
num /= 1024.0
|
||||
return "{:05.2f%}{}{}".format(num, "Gi", suffix)
|
||||
import bumblebee.module
|
||||
import bumblebee.util
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, args):
|
||||
|
@ -19,7 +13,7 @@ class Module(bumblebee.module.Module):
|
|||
free = self._mem.available
|
||||
total = self._mem.total
|
||||
|
||||
return "{}/{} ({:05.02f}%)".format(fmt(self._mem.available), fmt(self._mem.total), 100.0 - self._mem.percent)
|
||||
return "{}/{} ({:05.02f}%)".format(bumblebee.util.bytefmt(self._mem.available), bumblebee.util.bytefmt(self._mem.total), 100.0 - self._mem.percent)
|
||||
|
||||
def warning(self):
|
||||
return self._mem.percent < 20
|
||||
|
|
|
@ -19,11 +19,15 @@ class Module(bumblebee.module.Module):
|
|||
self._state = "down"
|
||||
addr = []
|
||||
|
||||
try:
|
||||
if netifaces.AF_INET in netifaces.ifaddresses(self._intf):
|
||||
for ip in netifaces.ifaddresses(self._intf)[netifaces.AF_INET]:
|
||||
if "addr" in ip and ip["addr"] != "":
|
||||
addr.append(ip["addr"])
|
||||
self._state = "up"
|
||||
except Exception as e:
|
||||
self._state = "down"
|
||||
addr = []
|
||||
|
||||
return "{} {} {}".format(self._intf, self._state, ", ".join(addr))
|
||||
|
||||
|
@ -48,9 +52,14 @@ class Module(bumblebee.module.Module):
|
|||
self._cache["wlan{}".format(intf)] = False
|
||||
return self._cache["wlan{}".format(intf)]
|
||||
|
||||
def _istunnel(self, intf):
|
||||
return intf.startswith("tun")
|
||||
|
||||
def state(self):
|
||||
t = "wireless" if self._iswlan(self._intf) else "wired"
|
||||
|
||||
t = "tunnel" if self._istunnel(self._intf) else t
|
||||
|
||||
return "{}-{}".format(t, self._state)
|
||||
|
||||
def warning(self):
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
"cpu": {
|
||||
"prefix": " "
|
||||
},
|
||||
"disk": {
|
||||
"prefix": " "
|
||||
},
|
||||
"nic": {
|
||||
"states": {
|
||||
"wireless-up": {
|
||||
|
@ -45,6 +48,12 @@
|
|||
},
|
||||
"wired-down": {
|
||||
"prefix": " "
|
||||
},
|
||||
"tunnel-up": {
|
||||
"prefix": " "
|
||||
},
|
||||
"tunnel-down": {
|
||||
"prefix": " "
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
8
bumblebee/util.py
Normal file
8
bumblebee/util.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
def bytefmt(num):
|
||||
for unit in [ "", "Ki", "Mi", "Gi" ]:
|
||||
if num < 1024.0:
|
||||
return "{:.2f}{}B".format(num, unit)
|
||||
num /= 1024.0
|
||||
return "{:05.2f%}{}GiB".format(num)
|
||||
|
Loading…
Reference in a new issue