Compare commits
2 Commits
1d06e1c180
...
b57db23a35
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b57db23a35 | ||
|
|
ebcc08cc8f |
@ -14,7 +14,7 @@ rec {
|
|||||||
packages.x86_64-linux = with nixpkgs.legacyPackages.x86_64-linux; rec {
|
packages.x86_64-linux = with nixpkgs.legacyPackages.x86_64-linux; rec {
|
||||||
pvemon = python3Packages.buildPythonApplication {
|
pvemon = python3Packages.buildPythonApplication {
|
||||||
pname = "pvemon";
|
pname = "pvemon";
|
||||||
version = "1.3.1";
|
version = "1.3.2";
|
||||||
src = ./src;
|
src = ./src;
|
||||||
propagatedBuildInputs = with python3Packages; [
|
propagatedBuildInputs = with python3Packages; [
|
||||||
pexpect
|
pexpect
|
||||||
|
|||||||
@ -87,15 +87,53 @@ def parse_storage_cfg(file_path='/etc/pve/storage.cfg'):
|
|||||||
|
|
||||||
def get_storage_size(storage):
|
def get_storage_size(storage):
|
||||||
try:
|
try:
|
||||||
if storage["type"] in ["dir", "nfs", "cephfs", "zfspool"]:
|
|
||||||
if storage["type"] == "zfspool":
|
if storage["type"] == "zfspool":
|
||||||
path = storage["mountpoint"]
|
if "pool" not in storage:
|
||||||
else:
|
logging.debug(f"ZFS pool {storage['name']} has no pool name configured")
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Extract the pool name (could be in format like rpool/data)
|
||||||
|
pool_name = storage["pool"].split("/")[0]
|
||||||
|
|
||||||
|
# Use zpool command to get accurate size information
|
||||||
|
import subprocess
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
["zpool", "list", pool_name, "-p"],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Parse the output
|
||||||
|
lines = result.stdout.strip().split("\n")
|
||||||
|
if len(lines) < 2:
|
||||||
|
logging.warn(f"Unexpected zpool list output format for {pool_name}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Extract values from the second line (the data line)
|
||||||
|
values = lines[1].split()
|
||||||
|
if len(values) < 4:
|
||||||
|
logging.warn(f"Insufficient data in zpool list output for {pool_name}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Values are: NAME SIZE ALLOC FREE ...
|
||||||
|
# We need the SIZE and FREE values (index 1 and 3)
|
||||||
|
total_size = int(values[1])
|
||||||
|
free_space = int(values[3])
|
||||||
|
|
||||||
|
return {
|
||||||
|
"total": total_size,
|
||||||
|
"free": free_space
|
||||||
|
}
|
||||||
|
except (subprocess.SubprocessError, ValueError, IndexError) as e:
|
||||||
|
logging.warn(f"Error running zpool list for {pool_name}: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
elif storage["type"] in ["dir", "nfs", "cephfs"]:
|
||||||
|
# For non-ZFS storage, use statvfs
|
||||||
path = storage["path"]
|
path = storage["path"]
|
||||||
# Get filesystem statistics
|
|
||||||
stats = os.statvfs(path)
|
stats = os.statvfs(path)
|
||||||
# Calculate total size and free space in bytes
|
|
||||||
# TODO: find an alternative way to calculate total_size for ZFS
|
|
||||||
total_size = stats.f_frsize * stats.f_blocks
|
total_size = stats.f_frsize * stats.f_blocks
|
||||||
free_space = stats.f_frsize * stats.f_bavail
|
free_space = stats.f_frsize * stats.f_bavail
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pvemon',
|
name='pvemon',
|
||||||
version = "1.3.1",
|
version = "1.3.2",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user