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.
– 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:
(defrag s: /a) -match '%$' -replace '.*= (\d)%$','$1'
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:
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
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