如何阅读HDD S.M.A.R.T.属性?

问题描述 投票:3回答:3

我会在我的Windows 7客户端上监控智能硬盘。

我想获得HDD智能属性,而不使用任何vbs文件或现成的工具只是期待WMI或PowerShell。

我会用ZABBIX监控服务器聚合该数据(使用zabbix-sender.exe)。

我发现了一个或多或少的Linux解决方案,但我会监视Windows 7机器硬盘。

有人有想法吗?

powershell windows-7 wmi monitoring zabbix
3个回答
5
投票

使用WMI API访问SMART数据,

gwmi -namespace root\wmi -class MSStorageDriver_FailurePredictStatus

There在网中更多examples


2
投票

这是一个powershell脚本,它从smartctl(smartmontools)输出中提取所有属性数据。如果它不在%path%中,请调整smartctl的路径。

它可以像这样使用:

.\get-smart.ps1 -Drive hda -AttributeId 5,241 -Property Name,Raw -FriendlyOutput

要不就

.\get-smart.ps1 hda 5,241 Name,Raw -f

如果指定-FriendlyOutput,它会将数据格式化为表格,否则它会为您提供一个对象。如果您只对特定值感兴趣,请使用

.\get-smart.ps1 hda 241 Raw

请注意,如果未以管理员身份运行smartctl,则不会显示某些属性(如阈值)。

没有异常处理了!你被警告了!

param(
    [Parameter(Mandatory=$True)]
    [string]    $Drive,
    [int[]]     $AttributeId,
    [string[]]  $Property,
    [switch]    $FriendlyOutput)
# parses attribute table in smartctl output and builds an object
$smart = [string[]](smartctl -A $Drive)
$attributes=@()
foreach ($s in $smart) {
    if ($s -match '^\s*(\d+)\s+(\w+)\s+(\w+)\s+(\d+)\s+(\d+)\s+([\d-]+)\s+([\w-]+)\s+(\w+)\s+([\w-]+)\s+(\d+)') {
        $o = new-object -Typename PSObject
        add-member -in $o -m NoteProperty -name 'ID' -value ([int]$matches[1])
        add-member -in $o -m NoteProperty -name 'Name' -value $matches[2]
        add-member -in $o -m NoteProperty -name 'Flag' -value $matches[3]
        add-member -in $o -m NoteProperty -name 'Value' -value ([int]$matches[4])
        add-member -in $o -m NoteProperty -name 'Worst' -value ([int]$matches[5])
        add-member -in $o -m NoteProperty -name 'Threshold' -value ([int]$matches[6])
        add-member -in $o -m NoteProperty -name 'Type' -value $matches[7]
        add-member -in $o -m NoteProperty -name 'Updated' -value $matches[8]
        add-member -in $o -m NoteProperty -name 'WhenFailed' -value $matches[9]
        add-member -in $o -m NoteProperty -name 'Raw' -value ([int64]$matches[10])
        $attributes += $o
    }
}
if ($AttributeId){
    $attributes = $attributes | ? {$_.id -in $attributeid}
}
if ($Property){
    if ($property.count -gt 1 -and $attributes.count -gt -0 -and $Property -notcontains 'id'){
        # if more than one result and more than one attribute, add the ID to the output
        $property = ,'id'+$Property
    }
    $attributes = $attributes | select $Property
}
if (@($attributes).count -eq 1 -and @($attributes.psobject.properties).count -eq 1){
    # return single values directly instead of an object
    $attributes.psobject.properties.value
} elseif ($FriendlyOutput){
    $attributes | ft * -a
} else {
    $attributes
}

0
投票

使用Smartmontools的JSON输出模式,这可以很容易地完成:

以下简短的Powershell脚本读取第一个磁盘的SMART属性(在smartmontools中名为/dev/sda),并选择ID为241的属性(即我的SSD上的Total_LBAs_Written)。

最后一行将LBA值转换为TBW值(TeraByte(s)Written)。

$json = (smartctl -A -j /dev/sda | ConvertFrom-JSON)
$lbaRaw = ($json.ata_smart_attributes.table | Where id -eq 241 | Select-Object raw)
$tbw = $lbaRaw.raw.value * 512 / 1024 / 1024 / 1024 / 1024
$tbw.toString("##.## TB")
© www.soinside.com 2019 - 2024. All rights reserved.