smart-ctl包装器(smartmontools)
py.SMART的Python项目详细描述
这是marc herndon的pysmart-0.3。它已经适应了python3.4(它没有与python3.4一起工作 Popen。通讯()正确地,并且已经完成了马克西姆-科罗布科(https://gitlab.beget.ru/LTD-Beget/pySMART)的工作。 也复制到其中。
Pysmart
版权所有(c)2015 Marc Herndon
pysmart是一个简单的python包装器,用于 smartmontools。它在linux和windows下工作,只要smartctl处于打开状态 系统路径。强烈建议使用管理权限运行, 因为smartctl无法准确检测所有设备类型或分析所有smart 没有这些权限的信息。
仅使用设备名(即/dev/sda,pd0),包将创建 Device对象,填充了与此相关的所有信息 装置。然后可以使用文档化的api来查询这个对象 信息、启动自检和执行其他功能。
使用量
使用pysmart的最常见方法是创建 要使用的物理存储设备,如图所示:
>>> from pySMART import Device >>> sda = Device('/dev/sda') >>> sda <SATA device on /dev/sda mod:WDC WD5000AAKS-60Z1A0 sn:WD-WCAWFxxxxxxx>
Device类成员可以直接访问,并且有许多helper方法 提供以批量检索信息。下面是一些示例:
>>> sda.assessment # Query the SMART self-assessment 'PASS' >>> sda.attributes[9] # Query a single SMART attribute <SMART Attribute 'Power_On_Hours' 068/000 raw:23644> >>> sda.all_attributes() # Print the entire SMART attribute table ID# ATTRIBUTE_NAME CUR WST THR TYPE UPDATED WHEN_FAIL RAW 1 Raw_Read_Error_Rate 200 200 051 Pre-fail Always - 0 3 Spin_Up_Time 141 140 021 Pre-fail Always - 3908 4 Start_Stop_Count 098 098 000 Old_age Always - 2690 5 Reallocated_Sector_Ct 200 200 140 Pre-fail Always - 0 ... # Edited for brevity 199 UDMA_CRC_Error_Count 200 200 000 Old_age Always - 0 200 Multi_Zone_Error_Rate 200 200 000 Old_age Offline - 0 >>> sda.tests[0] # Query the most recent self-test result <SMART Self-test [Short offline|Completed without error] hrs:23734 LBA:-> >>> sda.all_selftests() # Print the entire self-test log ID Test_Description Status Left Hours 1st_Error@LBA 1 Short offline Completed without error 00% 23734 - 2 Short offline Completed without error 00% 23734 - ... # Edited for brevity 7 Short offline Completed without error 00% 23726 - 8 Short offline Completed without error 00% 1 -
或者,包提供一个DeviceList类。当实例化时, 这将自动检测所有本地存储设备并创建一个包含 每个检测到的存储设备有一个Device对象:
>>> from pySMART import DeviceList >>> devlist = DeviceList() >>> devlist <DeviceList contents: <SAT device on /dev/sdb mod:WDC WD20EADS-00R6B0 sn:WD-WCAVYxxxxxxx> <SAT device on /dev/sdc mod:WDC WD20EADS-00S2B0 sn:WD-WCAVYxxxxxxx> <CSMI device on /dev/csmi0,0 mod:WDC WD5000AAKS-60Z1A0 sn:WD-WCAWFxxxxxxx> > >>> devlist.devices[0].attributes[5] # Access Device data as above <SMART Attribute 'Reallocated_Sector_Ct' 173/140 raw:214>
使用pysmart包装器,可以快速开发python应用程序 SmartMontools强大功能的优势。
安装
pySMART在pypi上可用,可通过pip:
安装python -m pip install pySMART
唯一的外部依赖项是smartmontools的smartctl组件 包裹。这应该预先安装在大多数linux发行版中,或者 可以通过您的包管理器获得。可能是以下情况之一:
apt-get install smartmontools or yum install smartmontools
在Windows PC上,必须下载并安装SmartMontools。最新的 版本可以从项目的主页http://www.smartmontools.org/获得。
注意,在windows上安装smartmontools之后,包含 smartctl.exe必须添加到系统路径(如果尚未添加)。
文件
pySMART的api文档是使用pdoc生成的,可以是 在包存档中的/docs文件夹中找到。
确认
我要感谢SmartMontools背后的整个团队, 维护这么好的产品。
我要特别感谢christian franke,他维护了windows端口 软件的。几年来,我编写的windows批处理文件 依靠smartctl.exe自动评估和测试 存储设备。如果没有他的工作,我的工作将会 更悲惨。:)
最近将我的脚本开发从批处理迁移到python for linux 移植性,我认为一个简单的smartctl包装器可以节省 未来自动化测试工具的开发。
关于许可的最后说明
如果你读到这篇文章并认为你会喜欢使用pysmart 它不受GPL许可的“限制”,请联系我。我非常 愿意在更宽松的条件下私下提供代码 许可证,包括一些公司或商业用途。我只想 你先跟我打个招呼,告诉我你的项目和皮斯马特 可以融入其中。我很可能乐意帮忙。
我以前也有过几次类似的请求,所以 我决定加上这张便条,以防有人不敢问。