如何在 Windows 中监视镜像磁盘的运行状况?

如何在 Windows 中监视镜像磁盘的运行状况?

我的 Windows 2003 Server 上有一个镜像动态磁盘。如何监控卷的运行状况?

当卷出现问题时,有没有办法让服务器发送电子邮件?有没有办法让服务器运行 SMART 测试?

编辑: 没有什么比登录客户端服务器、运行 DISKPART LIST VOLUME 并看到这个更能说明问题了。

Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
----------  ---  -----------  -----  ----------  -------  ---------  --------
Volume 0     X   xDrive       NTFS   Mirror       233 GB  Failed Rd
Volume 1     C                NTFS   Simple        57 GB  Healthy    System
Volume 2     D                       DVD-ROM         0 B  Healthy
Volume 3     F                RAW    Partition    466 GB  Healthy
Volume 4     E   New Volume   NTFS   Partition    932 GB  Healthy

答案1

我之前也有同样的问题。我首先想到的是使用 WMI,但出于某种奇怪的原因,WMI 不会通过任何常规 Win32_* 类公开 RAID 卷的运行状况。

我最终偶然发现本文中的脚本并做了一些修改以满足我的要求。它解析 diskpart.exe 的“LIST VOLUME”命令的输出。这可能看起来有点脏和丑陋,但目前这是我见过的最佳选择。

链接页面上显示的脚本已准备好用于纳吉奥斯/NS客户端++。如果您了解一些 VBScript,那么很容易就可以修改它来发送电子邮件而不是打印状态信息。

如果您不了解 VBScript,我很乐意为您提供一个修改后的版本,它可以满足您的任何要求。

答案2

for /f "tokens=4,9 delims= " %a IN ('echo list volume ^| diskpart ^| find "SSD"') do echo %a %b

将“SSD”替换为“镜像”(或条带……无论什么)或您的卷名。(我的卷名为 SSD1 + SSD2)

将@echo off 粘贴到批处理文件中,就完成了。:)

@echo off
for /f "tokens=4,9 delims= " %%a IN ('echo list volume ^| diskpart ^| find "SSD"') do echo %%a %%b

上面的行是批处理所必需的。=)

笔记

  • 您需要有一个卷名才能正常工作,否则请更改代币tokens=8

答案3

我使用这个丑陋的批处理文件来监控一百多台服务器以检查镜像状态,结果很不错。这是一个 nsclient++ 客户端插件,每四个小时进行一次被动检查,并将结果发送到 nagios 服务器。

check_mirror.bat

@echo off
echo list volume | diskpart | find "Mirror" > H
for /f %%i in ('type H ^| find /c "Mirror"') do set /a M=%%i 
for /f %%i in ('type H ^| find "Mirror" ^| find /c "Health" ') do set /a H=%%i 
for /f %%i in ('type H ^| find /c "Risk"') do set /a risk=%%i 
@del H /q
rem echo M=%M%, H = %H% Risk=%risk%
if %risk% GTR 0 goto err
IF %M%.==0. goto nomirror
IF %M% EQU %H% goto mirrorok

:err
echo CRITICAL: Something Wrong.
exit /B 1

:mirrorok
echo OK: Mirror Health.
exit /B 0

:nomirror
echo OK: No Mirror Found.
exit /B 1

答案4

这是一个 Powershell 脚本,用于监控 Windows 上 RAID 阵列的运行状况https://gist.github.com/schakkohttps://gist.github.com/schakko/4713248

我在 Windows 10 软件 raid 和 Server 2016 上的 Dell PERC H700 硬件 raid 上对其进行了测试。效果很好。我们使用 MegaRaid 进行通知。

我在这里重现它,以防要点消失,就像接受的答案中的目标一样https://serverfault.com/a/150089/2985

脚本中的“Fehlerfre”和“Fehlerhaf”是结果代码的德语翻译。

# A simple PowerShell script for retrieving the RAID status of volumes with help of diskpart.
# The nicer solution would be using WMI (which does not contain the RAID status in the Status field of Win32_DiskDrive, Win32_LogicalDisk or Win32_Volume for unknown reason)
# or using the new PowerShell API introduced with Windows 8 (wrong target system as our customer uses a Windows 7 architecture).
# 
# diskpart requires administrative privileges so this script must be executed under an administrative account if it is executed standalone.
# check_mk has this privileges and therefore this script must only be copied to your check_mk/plugins directory and you are done.
#
# Christopher Klein <ckl[at]neos-it[dot]de>
# This script is distributed under the GPL v2 license.

$dp = "list volume" | diskpart | ? { $_ -match "^  [^-]" }

echo `<`<`<local`>`>`>
foreach ($row in $dp) {
    # skip first line
    if (!$row.Contains("Volume ###")) {
        # best match RegExp from http://www.eventlogblog.com/blog/2012/02/how-to-make-the-windows-softwa.html
        if ($row -match "\s\s(Volume\s\d)\s+([A-Z])\s+(.*)\s\s(NTFS|FAT)\s+(Mirror|RAID-5|Stripe|Spiegel|Spiegelung|Übergreifend|Spanned)\s+(\d+)\s+(..)\s\s([A-Za-z]*\s?[A-Za-z]*)(\s\s)*.*")  {
            $disk = $matches[2] 
            # 0 = OK, 1 = WARNING, 2 = CRITICAL
            $statusCode = 1
            $status = "WARNING"
            $text = "Could not parse line: $row"
            $line = $row
            
            if ($line -match "Fehlerfre |OK|Healthy") {
                $statusText = "is healthy"
                $statusCode = 0
                $status = "OK"
            }
            elseif ($line -match "Rebuild") {
                $statusText = "is rebuilding"
                $statusCode = 1
            }
            elseif ($line -match "Failed|At Risk|Fehlerhaf") {
                $statusText = "failed"
                $statusCode = 2
                $status = "CRITICAL"
            }
        
            echo "$statusCode microsoft_software_raid - $status - Software RAID on disk ${disk}:\ $statusText"
        }
    }
}

此版本来自https://gist.github.com/LionRelaxe还通过电子邮件发送错误结果(https://gist.github.com/schakko/4713248#gistcomment-2256715

# A simple PowerShell script for retrieving the RAID status of volumes with help of diskpart.
# The nicer solution would be using WMI (which does not contain the RAID status in the Status field of Win32_DiskDrive, Win32_LogicalDisk or Win32_Volume for unknown reason)
# or using the new PowerShell API introduced with Windows 8 (wrong target system as our customer uses a Windows 7 architecture).
# 
# diskpart requires administrative privileges so this script must be executed under an administrative account if it is executed standalone.
# check_mk has this privileges and therefore this script must only be copied to your check_mk/plugins directory and you are done.
#
# Christopher Klein <ckl[at]neos-it[dot]de>
# This script is distributed under the GPL v2 license.

#Volumes:
$dpV = "list volume" | diskpart | ? { $_ -match "^  [^-]" }
foreach ($row in $dpV) {
    $OutString = $OutString+$row+"`r`n"
    # skip first line
    if (!$row.Contains("Volume ###")) {
        # best match RegExp from http://www.eventlogblog.com/blog/2012/02/how-to-make-the-windows-softwa.html
        if ($row -match "\s\s(Volume\s\d)\s+([A-Z])\s+(.*)\s\s(NTFS|FAT)\s+(Mirror|RAID-5|Stripe|Spiegel|Spiegelung|Übergreifend|Spanned)\s+(\d+)\s+(..)\s\s([A-Za-z]*\s?[A-Za-z]*)(\s\s)*.*")  {
            $disk = $matches[2] 
            # 0 = OK, 1 = WARNING, 2 = CRITICAL
            $statusCode = 1
            $status = "WARNING"
            $text = "Could not parse line: $row"
            $line = $row
            
            if ($line -match "Fehlerfre |OK|Healthy") {
                $statusText = "is healthy"
                $statusCode = 0
                $status = "OK"
            }
            elseif ($line -match "Rebuild") {
                $statusText = "is rebuilding"
                $statusCode = 1
                $VolumeErrorFound = 1
            }
            elseif ($line -match "Failed|At Risk|Fehlerhaf") {
                $statusText = "failed"
                $statusCode = 2
                $status = "CRITICAL"
                $VolumeErrorFound = 1
            }
        
            #echo "$statusCode microsoft_software_raid - $status - Software RAID on disk ${disk}:\ $statusText"
        }
    }
}
$OutString = $OutString+"`r`n"

#Disk:
$dpD = "list disk" | diskpart | ? { $_ -match "^  [^-]" }
foreach ($row in $dpD) {
    # skip first line
    if (!$row.Contains("Volume ###")) {
        $OutString = $OutString+$row+"`r`n"
        # best match RegExp from http://www.eventlogblog.com/blog/2012/02/how-to-make-the-windows-softwa.html
        if ($row -match "Errors") {
            #echo "$row"
            $DiskErrorFound = 1
        }
    }
}
if (($DiskErrorFound) -Or ($VolumeErrorFound)) {
    $SMTPServer = "your.smtp.server"
    $SMTPPort = 25
    $EmailTo = "[email protected]"
    $EmailFrom = "[email protected]"
    $EmailSubject = "Disk or Volume Error on $env:computername"
    $EmailBody = $OutString
    Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $EmailSubject -Body $EmailBody -SmtpServer $SMTPServer -Port $SMTPPort
}

相关内容