Recently, I encountered a sad reminder: One of the fastdfs storage servers is broken (the storage partition is changed to readonly), but zabbix does not monitor this, resulting in client upload failure. It was finally found that it became read-only two days ago. Although data storage is redundant, it has little impact, but it is still quite uncomfortable, not to detect problems in time. In this case, a small script is written to enable an alarm when the storage update latency is higher than the specified value (for example, 2 minutes. &
Recently, I encountered a sad reminder: a disk in the fastdfs storage server is broken (the storage partition is changed to read only), but zabbix does not monitor this, resulting in client upload failure. It was finally found that it became read-only two days ago. Although data storage is redundant, it has little impact, but it is still quite uncomfortable, not to detect problems in time. In this case, a small script is written to enable an alarm when the storage update latency is higher than the specified value (for example, 2 minutes.
You can use fdfs_monitor to view the storage status and Update Time Delay of all fastdfs instances. The execution result is the uptime value of last_synced_timestamp. Monitors Active status and latency. The script is as follows:
#! /Bin/bash
# Storage synchronous delay alarm scripts
# Richard shen 2012/07/11
# BLOG: http://lxsym.blog.51cto.com
Basedir = 'dirname $0'
Now_time = 'date + % s'
Active = $ Basedir/active.txt
IP = $ Basedir/ip.txt
Syn_time = $ Basedir/syn_time.txt
COMMAND = "/usr/local/webserver/fdfs/bin/fdfs_monitor/usr/local/webserver/fdfs/etc/client. conf"
$ COMMAND | grep "(" | awk '/ip_addr/{print $5}'> $ Active
$ COMMAND | grep "(" | awk '/ip_addr/{print $3}'> $ IP
$ COMMAND | grep last_synced_timestamp | awk '{print $3, $4}'> $ Syn_time
Paste $ Syn_time $ IP $ Active> main. log
Cat main. log | while read day time ip active
Do
Sys_time = 'date-d "$ day $ time" + % s'
Num = 'expr $ Now_time-$ sys_time'
# Stuts alarm
If [$ active! = "ACTIVE"]; then
# Email alarm API,
# Echo "$ ip State is $ active, please check ."
Fi
# Set alarm time (eg 2 m (120 s ))
If [$ num-gt 120]; then
# Mail alarm API, such as wget-q-O-"http://api.abc.com/sendMail.php? Type = abcdG & to = Email Address & subject = [Storage synchronization latency alarm: $ ip latency $ num seconds, please check ~] & Body = RT, please check. Thank you ">/dev/null
# Echo "$ ip Update time delay $ num (s )"
Fi
Done
Rm-rf $ Active $ IP $ Syn_time main. log