# -*- coding: utf-8 -*-
-from __future__ import absolute_import
import json
import logging
from mgr_util import get_most_recent_rate, get_time_series_rates
from .. import mgr
-from ..exceptions import DashboardException
try:
from typing import Any, Dict, Optional, Union
# type: (dict) -> Dict[str, dict]
# Check whether the device is associated with daemons.
if 'daemons' in device and device['daemons']:
- dev_smart_data = None
-
- # The daemons associated with the device. Note, the list may
- # contain daemons that are 'down' or 'destroyed'.
- daemons = device.get('daemons')
+ dev_smart_data: Dict[str, Any] = {}
# Get a list of all OSD daemons on all hosts that are 'up'
# because SMART data can not be retrieved from daemons that
if node.get('status') == 'up'
]
- # Finally get the daemons on the host of the given device
- # that are 'up'. All daemons on the same host can deliver
- # SMART data, thus it is not relevant for us which daemon
- # we are using.
- daemons = list(set(daemons) & set(osd_daemons_up)) # type: ignore
-
- for daemon in daemons:
+ # All daemons on the same host can deliver SMART data,
+ # thus it is not relevant for us which daemon we are using.
+ # NOTE: the list may contain daemons that are 'down' or 'destroyed'.
+ for daemon in device['daemons']:
svc_type, svc_id = daemon.split('.')
if 'osd' in svc_type:
+ if daemon not in osd_daemons_up:
+ continue
try:
dev_smart_data = CephService.send_command(
svc_type, 'smart', svc_id, devid=device['devid'])
- except SendCommandError:
+ except SendCommandError as error:
+ logger.warning(str(error))
# Try to retrieve SMART data from another daemon.
continue
elif 'mon' in svc_type:
try:
dev_smart_data = CephService.send_command(
svc_type, 'device query-daemon-health-metrics', who=daemon)
- except SendCommandError:
+ except SendCommandError as error:
+ logger.warning(str(error))
# Try to retrieve SMART data from another daemon.
continue
else:
'[SMART] Error retrieving smartctl data for device ID "%s": %s',
dev_id, dev_data)
break
- if dev_smart_data is None:
- raise DashboardException(
- 'Failed to retrieve SMART data for device ID "{}"'.format(
- device['devid']))
+
return dev_smart_data
logger.warning('[SMART] No daemons associated with device ID "%s"',
device['devid'])