Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ config:
# Choose a theme made for your screen size (see DISPLAY_SIZE inside theme.yaml)
THEME: 3.5inchTheme2

# Filesystem path used for disk usage statistics
DISK_PATH: "/"

# Hardware sensors reading
# Choose the appropriate method for reading your hardware sensors:
# - PYTHON use Python libraries (psutils, GPUtil...) to read hardware sensors (supports all OS but not all HW)
Expand Down
6 changes: 3 additions & 3 deletions library/sensors/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ def virtual_free() -> int: # In bytes
class Disk(ABC):
@staticmethod
@abstractmethod
def disk_usage_percent() -> float:
def disk_usage_percent(path: str = "/") -> float:
pass

@staticmethod
@abstractmethod
def disk_used() -> int: # In bytes
def disk_used(path: str = "/") -> int: # In bytes
pass

@staticmethod
@abstractmethod
def disk_free() -> int: # In bytes
def disk_free(path: str = "/") -> int: # In bytes
pass


Expand Down
12 changes: 6 additions & 6 deletions library/sensors/sensors_librehardwaremonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,16 @@ def virtual_free() -> int: # In bytes
# This is because LHM is a hardware-oriented library, whereas used/free/total space is for partitions, not disks
class Disk(sensors.Disk):
@staticmethod
def disk_usage_percent() -> float:
return psutil.disk_usage("/").percent
def disk_usage_percent(path: str = "/") -> float:
return psutil.disk_usage(path).percent

@staticmethod
def disk_used() -> int: # In bytes
return psutil.disk_usage("/").used
def disk_used(path: str = "/") -> int: # In bytes
return psutil.disk_usage(path).used

@staticmethod
def disk_free() -> int: # In bytes
return psutil.disk_usage("/").free
def disk_free(path: str = "/") -> int: # In bytes
return psutil.disk_usage(path).free


class Net(sensors.Net):
Expand Down
12 changes: 6 additions & 6 deletions library/sensors/sensors_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,23 +453,23 @@ def virtual_free() -> int: # In bytes

class Disk(sensors.Disk):
@staticmethod
def disk_usage_percent() -> float:
def disk_usage_percent(path: str = "/") -> float:
try:
return psutil.disk_usage("/").percent
return psutil.disk_usage(path).percent
except:
return math.nan

@staticmethod
def disk_used() -> int: # In bytes
def disk_used(path: str = "/") -> int: # In bytes
try:
return psutil.disk_usage("/").used
return psutil.disk_usage(path).used
except:
return -1

@staticmethod
def disk_free() -> int: # In bytes
def disk_free(path: str = "/") -> int: # In bytes
try:
return psutil.disk_usage("/").free
return psutil.disk_usage(path).free
except:
return -1

Expand Down
6 changes: 3 additions & 3 deletions library/sensors/sensors_stub_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def virtual_free() -> int: # In bytes

class Disk(sensors.Disk):
@staticmethod
def disk_usage_percent() -> float:
def disk_usage_percent(path: str = "/") -> float:
return random.uniform(0, 100)

@staticmethod
def disk_used() -> int: # In bytes
def disk_used(path: str = "/") -> int: # In bytes
return random.randint(1000000000, 2000000000000)

@staticmethod
def disk_free() -> int: # In bytes
def disk_free(path: str = "/") -> int: # In bytes
return random.randint(1000000000, 2000000000000)


Expand Down
6 changes: 3 additions & 3 deletions library/sensors/sensors_stub_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ def virtual_free() -> int: # In bytes

class Disk(sensors.Disk):
@staticmethod
def disk_usage_percent() -> float:
def disk_usage_percent(path: str = "/") -> float:
return PERCENTAGE_SENSOR_VALUE

@staticmethod
def disk_used() -> int: # In bytes
def disk_used(path: str = "/") -> int: # In bytes
return int(DISK_TOTAL_SIZE_GB / 100 * PERCENTAGE_SENSOR_VALUE) * 1000000000

@staticmethod
def disk_free() -> int: # In bytes
def disk_free(path: str = "/") -> int: # In bytes
return int(DISK_TOTAL_SIZE_GB / 100 * (100 - PERCENTAGE_SENSOR_VALUE)) * 1000000000


Expand Down
9 changes: 5 additions & 4 deletions library/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,13 @@ class Disk:

@classmethod
def stats(cls):
used = sensors.Disk.disk_used()
free = sensors.Disk.disk_free()

disk_theme_data = config.THEME_DATA['STATS']['DISK']
path = config.CONFIG_DATA['config'].get('DISK_PATH') or "/"

used = sensors.Disk.disk_used(path)
free = sensors.Disk.disk_free(path)

disk_usage_percent = sensors.Disk.disk_usage_percent()
disk_usage_percent = sensors.Disk.disk_usage_percent(path)
save_last_value(disk_usage_percent, cls.last_values_disk_usage,
disk_theme_data['USED']['LINE_GRAPH'].get("HISTORY_SIZE", DEFAULT_HISTORY_SIZE))
display_themed_progress_bar(disk_theme_data['USED']['GRAPH'], disk_usage_percent)
Expand Down