Skip to content

Commit

Permalink
Removed Docker Insights Beta feature. Causing to many headaches and s…
Browse files Browse the repository at this point in the history
…tability issues. Implemented fixes for Could not find device path for /mnt and Error in HA log regarding parity history parsing - invalid literal for int() with base 10
  • Loading branch information
MrD3y5eL committed Dec 30, 2024
1 parent 30df160 commit c3379fa
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 1,480 deletions.
8 changes: 0 additions & 8 deletions custom_components/unraid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from homeassistant.helpers.importlib import async_import_module # type: ignore

from .const import (
CONF_DOCKER_INSIGHTS,
CONF_HOSTNAME,
DOMAIN,
PLATFORMS,
Expand Down Expand Up @@ -182,13 +181,6 @@ async def async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None
except Exception as err:
_LOGGER.error("Error updating UPS status: %s", err)

# Handle Docker Insights updates
if CONF_DOCKER_INSIGHTS in entry.options:
try:
await coordinator.async_update_docker_insights(entry.options[CONF_DOCKER_INSIGHTS])
except Exception as err:
_LOGGER.error("Error updating Docker Insights: %s", err)

# Reload the config entry
await hass.config_entries.async_reload(entry.entry_id)

Expand Down
49 changes: 33 additions & 16 deletions custom_components/unraid/api/disk_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ def __init__(self, instance: Any):
self._spindown_delays: Dict[str, int] = {}
self._lock = asyncio.Lock()
self._device_types: Dict[str, str] = {} # Track device types (nvme, sata, etc)
self._device_paths_cache: Dict[str, str] = {} # Cache for device paths

async def _get_device_path(self, device: str) -> str | None:
"""Get actual device path from mount point."""
try:
# Check cache first
if device in self._device_paths_cache:
return self._device_paths_cache[device]

mount_cmd = f"findmnt -n -o SOURCE /mnt/{device}"
result = await self._instance.execute_command(mount_cmd)
if result.exit_status == 0 and (device_path := result.stdout.strip()):
self._device_paths_cache[device] = device_path
return device_path
return None
except Exception as err:
_LOGGER.error("Error getting device path for %s: %s", device, err)
return None

async def get_disk_state(self, device: str) -> DiskState:
"""Get disk state using multiple methods with SMART as primary."""
Expand All @@ -42,9 +60,13 @@ async def get_disk_state(self, device: str) -> DiskState:
if device.startswith('sd'):
device_path = f"/dev/{device}"
elif device == "cache":
device_path = "/dev/nvme0n1"
self._device_types[device] = 'nvme'
return DiskState.ACTIVE
# Get actual cache device path
if actual_path := await self._get_device_path("cache"):
device_path = actual_path
self._device_types[device] = 'nvme' if 'nvme' in actual_path.lower() else 'sata'
return DiskState.ACTIVE
_LOGGER.error("Could not find cache device path")
return DiskState.UNKNOWN
elif device.startswith("disk"):
try:
disk_num = int(''.join(filter(str.isdigit, device)))
Expand All @@ -53,18 +75,12 @@ async def get_disk_state(self, device: str) -> DiskState:
_LOGGER.error("Invalid disk number in %s", device)
return DiskState.UNKNOWN
else:
# For custom pools or other disks, try to get device from mount
try:
mount_cmd = f"findmnt -n -o SOURCE /mnt/{device}"
result = await self._instance.execute_command(mount_cmd)
if result.exit_status == 0:
device_path = result.stdout.strip()
_LOGGER.debug("Found device path for %s: %s", device, device_path)
else:
_LOGGER.error("Could not find device path for %s", device)
return DiskState.UNKNOWN
except Exception as err:
_LOGGER.error("Error getting device path for %s: %s", device, err)
# For custom pools or other disks
if actual_path := await self._get_device_path(device):
device_path = actual_path
_LOGGER.debug("Found device path for %s: %s", device, device_path)
else:
_LOGGER.error("Could not find device path for %s", device)
return DiskState.UNKNOWN

if device_path not in self._device_types:
Expand Down Expand Up @@ -126,7 +142,8 @@ async def get_disk_state(self, device: str) -> DiskState:
state = DiskState.STANDBY
else:
_LOGGER.warning(
"Both SMART and hdparm failed to determine state for %s (smart_exit=%d, hdparm_output='%s'), assuming ACTIVE",
"Both SMART and hdparm failed to determine state for %s "
"(smart_exit=%d, hdparm_output='%s'), assuming ACTIVE",
device_path,
result.exit_status,
output.strip()
Expand Down
15 changes: 1 addition & 14 deletions custom_components/unraid/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from homeassistant.core import callback # type: ignore

from .const import (
CONF_DOCKER_INSIGHTS,
DOMAIN,
DEFAULT_PORT,
CONF_GENERAL_INTERVAL,
Expand Down Expand Up @@ -41,15 +40,13 @@ class UnraidConfigFlowData:
general_interval: int = DEFAULT_GENERAL_INTERVAL
disk_interval: int = DEFAULT_DISK_INTERVAL
has_ups: bool = False
docker_insights: bool = False

@callback
def get_schema_base(
general_interval: int,
disk_interval: int,
include_auth: bool = False,
has_ups: bool = False,
docker_insights: bool = False
) -> vol.Schema:
"""Get base schema with sliders for both intervals."""
if include_auth:
Expand Down Expand Up @@ -110,7 +107,6 @@ def get_schema_base(
)
),
vol.Required(CONF_HAS_UPS, default=has_ups): bool,
vol.Required(CONF_DOCKER_INSIGHTS, default=docker_insights): bool,
}

return vol.Schema(schema)
Expand All @@ -125,14 +121,12 @@ def get_options_schema(
general_interval: int,
disk_interval: int,
has_ups: bool,
docker_insights: bool = False,
) -> vol.Schema:
"""Get schema for options flow."""
return get_schema_base(
general_interval,
disk_interval,
has_ups=has_ups,
docker_insights=docker_insights
has_ups=has_ups
)

async def validate_input(data: dict[str, Any]) -> dict[str, Any]:
Expand Down Expand Up @@ -278,10 +272,6 @@ def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
CONF_HAS_UPS,
config_entry.data.get(CONF_HAS_UPS, False)
)
self._docker_insights = config_entry.options.get(
CONF_DOCKER_INSIGHTS,
config_entry.data.get(CONF_DOCKER_INSIGHTS, False)
)

async def async_step_init(
self, user_input: dict[str, Any] | None = None
Expand All @@ -295,7 +285,6 @@ async def async_step_init(
CONF_GENERAL_INTERVAL: user_input[CONF_GENERAL_INTERVAL],
CONF_DISK_INTERVAL: user_input[CONF_DISK_INTERVAL],
CONF_HAS_UPS: user_input[CONF_HAS_UPS],
CONF_DOCKER_INSIGHTS: user_input[CONF_DOCKER_INSIGHTS],
},
)

Expand All @@ -322,7 +311,6 @@ async def async_step_init(
)
),
vol.Required(CONF_HAS_UPS, default=self._has_ups): bool,
vol.Required(CONF_DOCKER_INSIGHTS, default=self._docker_insights): bool,
})

return self.async_show_form(
Expand All @@ -335,7 +323,6 @@ async def async_step_init(
"disk_interval_description": (
"How often to update disk information (1-24 hours)"
),
"docker_insights_description": "Enable detailed Docker container monitoring"
},
)

Expand Down
20 changes: 0 additions & 20 deletions custom_components/unraid/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,6 @@ class DiskHealth(str, Enum):
FAILED = "FAILED"
UNKNOWN = "Unknown"

# Docker Configuration
CONF_DOCKER_INSIGHTS = "docker_insights"
DEFAULT_DOCKER_INSIGHTS = False

# Docker Stats Keys
DOCKER_STATS_CPU_PERCENTAGE = "containers_cpu_percentage"
DOCKER_STATS_1CPU_PERCENTAGE = "containers_1cpu_percentage"
DOCKER_STATS_MEMORY = "containers_memory"
DOCKER_STATS_MEMORY_PERCENTAGE = "containers_memory_percentage"

# Container Stats Keys
CONTAINER_STATS_CPU_PERCENTAGE = "cpu_percentage"
CONTAINER_STATS_1CPU_PERCENTAGE = "1cpu_percentage"
CONTAINER_STATS_MEMORY = "memory"
CONTAINER_STATS_MEMORY_PERCENTAGE = "memory_percentage"
CONTAINER_STATS_NETWORK_SPEED_UP = "network_speed_up"
CONTAINER_STATS_NETWORK_SPEED_DOWN = "network_speed_down"
CONTAINER_STATS_NETWORK_TOTAL_UP = "network_total_up"
CONTAINER_STATS_NETWORK_TOTAL_DOWN = "network_total_down"

# Device identifier patterns
DEVICE_ID_SERVER = "{}_server_{}" # DOMAIN, entry_id
DEVICE_ID_DOCKER = "{}_docker_{}_{}" # DOMAIN, container_name, entry_id
Expand Down
Loading

0 comments on commit c3379fa

Please sign in to comment.