• Homepage
  • >
  • HowTos
  • >
  • Powershell command to monitor disk fragmentation level using Zabbix

Powershell command to monitor disk fragmentation level using Zabbix

  • by
  • 3 Years ago
  • 0

I love zabbix a lot because of its ease of use and the simplicity of the configuration when it comes to monitoring anything. I recently added a monitor to check the fragmentation level of volumes on a machine once a week and set it to trigger an alert when the fragmentation level reaches the set threshold.

I wrote a simple command line statement that would run the defrag check and output just the value. One thing to note is if the server has more than one partition, then you will need one script per partition as you will need to update the script with the drive letter.

Steps:

– Log into the server been monitored, open the zabbix script folder (in my case I have all my zabbix scripts in [highlight]c:\zabbix\scripts[/highlight]). Create a new file and name it as ‘[highlight]fragmentation-s.ps1[/highlight]’. Edit the file, copy and paste the following codes:

[code language=”js”](defrag s: /a) -match ‘%$’ -replace ‘.*= (\d)%$’,’$1′[/code]

Where [highlight]s:[/highlight] is the volume label to be monitored. To monitor a different volume like T: drive, simply replace [highlight]s:[/highlight] with [highlight]t:[/highlight]

– Log into zabbix, create a new item, fill in the details as shown in snapshot below. The Key value would be:

[code language=”js”]system.run(powershell -command "& ‘c:\zabbix\scripts\fragmentation-s.ps1’",)

Note: The above key curly brackets "()" should be changed to square brackets "[]" as the syntax highlighter I am using is unable to interpret the square bracket as part of the code[/code]

zabbix-defrag01

Note: If you plan to monitor fragmentation level in a production environment, I would recommend to change the frequency of check to once every month or adjust based on how the server frequently gets fragmented.

– Below is sample output of one of my checks which was initially on a daily basis

zabbix-defrag02

  • facebook
  • googleplus
  • twitter
  • linkedin
  • linkedin