RAID monitoring in FreeBSD with mfiutil
If you are running FreeBSD on your dedicated server, you can monitor the RAID array using the built-in tool called mfiutil.
mfiutil is a built-in tool in FreeBSD for monitoring and querying MegaRAID controller cards. Using this tool, you can view the RAID controller status on your dedicated server and be alerted if a disk is failing and needs replacement.
Querying the RAID card
The following commands must be executed as root.
To view information about the RAID card, use mfiutil show adapter, such as:
mfiutil show adapter
/dev/mfi0 Adapter:
Product Name: AVAGO 3108 MegaRAID
Serial Number: FW-AFV36IVAARBWA
Firmware: 24.21.0-0151
RAID Levels: JBOD, RAID0, RAID1, RAID5, RAID6, RAID10, RAID50
Battery Backup: not present
NVRAM: 32K
Onboard Memory: 2048M
Minimum Stripe: 64K
Maximum Stripe: 1MTo view information about the volumes and their status, use mfiutil show volumes, such as:
mfiutil show volumes
/dev/mfi0 Volumes:
Id Size Level Stripe State Cache Name
mfid0 ( 447G) RAID-1 256K OPTIMAL Disabled <Drive1>To view information about the physical drives, use mfiutil show drives, such as:
Automating and monitoring
The script below will send you an email if the status is not "OPTIMAL".
For the script to work, you'll need a fully working MTA (Mail Transport Agent) installed, such as FreeBSD's new default mail transport agent, DMA (DragonFly Mail Agent), or Postfix.
See the guide Sending email from your FreeBSD server using DMA for sending email using FreeBSD's new default mail agent (recommended and easiest). Or, if you would rather use Postfix, see the guide Sending email from your server using Postfix on how to set up your own Postfix server (written for Debian Linux).
Next, create a file called raidcheck.sh in a directory of your choice and edit the file with vim or nano. Paste the following code:
Note that this script requires bash; it does not work with sh. Install Bash using pkg install bash as root.
You need to change the FROM_EMAIL and TO_EMAIL variables at the beginning of the script to match your email address and the sender's email address.
You also need to make raidcheck.sh executable:
Next, you'll need to add the script to root's crontab (since mfiutil requires root permissions to access the controller). You can open root's crontab either by using sudo crontab -e (if sudo is installed and configured), or by first switching to root with su, and then running crontab -e.
Once root's crontab is open, paste the following line. Change the path to where your script is located. This crontab will run the script 10 minutes past every hour. For more information about crontab, see Automate tasks in Linux using cron.
Notes
We recommend that you test the script to ensure that it truly works before putting it into live operation. There's no guarantee it will suit your specific server and setup.
Last updated
Was this helpful?