Obtaining key attributes and Health of HDD and SSD using smartmontools














































Obtaining key attributes and Health of HDD and SSD using smartmontools



DESCRIPTION:
S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology; written as SMART) SMART is a system for monitoring and early detection of errors of storage media such as hard disks or SSDs.
 All current hard drives and SSDs have SMART functionality. However, the data provided by SMART, (SMART attributes), are different from manufacturer to manufacturer.

NOTE:Run IDE as administrator and SMARTMONTOOLS should be installed in the system

IMPLEMENTATION:
This python script displays the HDD and SSD health status and also its key attributes
import os #device record class DeviceRecord: def __init__(self): self.deviceHealth = None self.deviceAttributes = None class SMART: #to run a smartctl command def RunSmartCtl(self, strArgs): #get the command with strArgs as the argument cmdString = "smartctl " + strArgs #get command output and store each line in a list output = os.popen(cmdString).read() lines = str.splitlines(output) return lines #get device health def GetDeviceHealth(self, deviceId): deviceInfoLines = self.RunSmartCtl("-H " + deviceId) return deviceInfoLines[-2] #get device attributes def GetDeviceAttributes(self, deviceId): deviceInfoLines = self.RunSmartCtl("-A " + deviceId) for i in range(len(deviceInfoLines)): if deviceInfoLines[i].startswith('ID#'): index = i+1 break infoDict = dict() for i in range(index, len(deviceInfoLines)-1): x = deviceInfoLines[i].strip().split() infoDict[x[0]] = x[0:len(x)] return infoDict if __name__ == '__main__': smart_features = SMART() deviceid = input("Enter device id: ") #fetchig disk health devHealth = smart_features.GetDeviceHealth(deviceid) #printing device health information print("Disk Health Information") print(devHealth) #fetching attributes details devAttr=smart_features.GetDeviceAttributes(deviceid) #printing attributes information print("Disk attribute Informaion") print("ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH") for attributes in devAttr: print('\t'.join(devAttr[attributes][:6]))

OUTPUT:




Comments

  • Pierce
    30-Jun-2023 09:03:01 PM

    Smartmontools are invaluable in obtaining key attributes and monitoring the health of HDD and SSD. They provide essential insights for data integrity and storage device performance. Similarly, seeking counselling in australia offers vital support for mental and emotional well-being. With professional guidance, individuals can navigate challenges, develop coping strategies, and foster resilience. Just as smartmontools ensure the health of our storage, counselling in Australia nurtures our inner strength and promotes a balanced, fulfilling life.