我会在我的Windows 7客户端上监控智能硬盘。
我会得到硬盘智能属性,而不是使用任何vbs文件或现成的工具,只是寻找WMI或PowerShell。
我将使用ZABBIX监控服务器(使用zabbix-sender.exe
)聚合这些数据。
我找到了一种或多或少适用于Linux的解决方案,但我会监控windows7机器的硬盘。
有谁有主意吗?
发布于 2014-03-31 18:19:36
使用WMI API访问智能数据,如下所示:
gwmi -namespace root\wmi -class MSStorageDriver_FailurePredictStatus
There更多的是网络中的examples。
发布于 2020-01-10 13:04:40
-序:
我相信PowerShell解决方案会满足您的需求。不幸的是,似乎没有一种方法可以仅通过PowerShell从各种存储设备获取所有的S.M.A.R.T.信息,因为PowerShell是该功能的一个相当通用的实现,而且S.M.A.R.T.的实现因存储设备供应商而异。
话虽如此,下面描述的方法应该满足用户执行的典型S.M.A.R.T.检查的关键要求,包括预测寿命、重新分配和不可校正的扇区等,尽管使用了相当通用的PowerShell术语(例如,寿命=“磨损”)。
-信息:
通过结合使用两个PowerShell cmdlet,我们可以轻松查看存储设备提供的一些S.M.A.R.T.数据:
Get-StorageReliabilityCounter
“cmdlet获取指定磁盘或物理磁盘的存储可靠性计数器。这些计数器包括有关设备温度、错误、损耗和设备使用时间长度等信息。”
这是实际上将返回我们寻找的S.M.A.R.T数据的cmdlet。但是,与您可能熟悉的许多其他cmdlet不同,此cmdlet需要通过PowerShell对象指向目标磁盘。(如果您是PowerShell的新手,这并不像听起来那么复杂,所以不要害怕。)
“Get- Disk cmdlet获取操作系统可见的一个或多个磁盘对象,或可选的筛选列表。”
这是我们将用来提供所需的PowerShell对象的cmdlet,以便Get-StorageReliabilityCounter知道要查询哪个磁盘。
-代码:
就像任何事情一样,有多种方法可以实际执行代码,所以在我看来,我只需要提供代码,以尽可能简单的方式获得所需的信息。
有关所有本地磁盘的简单S.M.A.R.T.信息的(以管理员身份运行):
Get-Disk | Get-StorageReliabilityCounter
示例输出:
PS C:\WINDOWS\system32> Get-Disk | Get-StorageReliabilityCounter
DeviceId Temperature ReadErrorsUncorrected Wear PowerOnHours
-------- ----------- --------------------- ---- ------------
1 0 0 5505
2 0 0 572
0 0 2799
所有本地磁盘上的扩展S.M.A.R.T.信息的(以管理员身份运行):
Get-Disk | Get-StorageReliabilityCounter | Select-Object -Property "*"
截断样本输出:
PS C:\WINDOWS\system32> Get-Disk | Get-StorageReliabilityCounter | Select-Object -Property "*"
DeviceId : 1
FlushLatencyMax : 46
LoadUnloadCycleCount :
LoadUnloadCycleCountMax :
ManufactureDate :
PowerOnHours : 5505
ReadErrorsCorrected : 0
ReadErrorsTotal : 0
ReadErrorsUncorrected : 0
ReadLatencyMax : 231
StartStopCycleCount :
StartStopCycleCountMax :
Temperature : 27
TemperatureMax : 0
Wear : 0
WriteErrorsCorrected :
WriteErrorsTotal :
WriteErrorsUncorrected :
WriteLatencyMax : 69
PSComputerName :
正如您所看到的,列出了一些可取的指标,这些指标可能会也可能不会让您规避灾难。
- tl;dr:
跑
Get-Disk | Get-StorageReliabilityCounter
或
Get-Disk | Get-StorageReliabilityCounter | Select-Object -Property "*"
以管理员身份使用获取最重要的S.M.A.R.T.信息。
发布于 2015-02-18 04:39:56
下面是一个powershell脚本,它从smartctl (smartmontools)输出中提取所有属性数据。如果smartctl不在%path%中,请调整它的路径。
它可以像这样使用:
.\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
}
https://stackoverflow.com/questions/22758629
复制相似问题