1:提醒客户注意内存、swap使用(使用率大于90%前台也会有告警).
2:如有必要,可考虑布置下监控,定时参看每个进程swap空间的情况.
a)将swap_monitor.sh复制到/sf/data/local下,然后执行下面脚本
b)nohup watch -n 10 bash /sf/data/local/swap_monitor.sh &
swap_monitor.sh脚本内容:
#!/bin/bash
# 定义输出文件路径
output_file="/sf/data/local/swap_monitor.txt"
# 记录当前日期
date >> "$output_file"
# 获取每个进程的交换空间使用信息,并按交换空间使用量降序排序,取前几行
for file in /proc/*/status; do
awk '/^Name:/ { name = $2 } /^Pid:/ { pid = $2 } /^VmSwap:/ { vmswap = $2 " " $3; found=1 } END { if (found) print "Name:" name, "Pid:" pid, "VmSwap:" vmswap }' "$file"
done | sort -k 5,5n -r | head >> "$output_file"
# 输出分隔线
echo "--------------------------------------" >> "$output_file"
# 检查文件大小是否超过 100M
file_size=$(du -m "$output_file" | cut -f 1)
if [ "$file_size" -gt 100 ]; then
# 获取当前日期作为压缩包文件名的一部分
current_date=$(date +%Y%m%d%H%M%S)
tar_file="/sf/data/local/swap_monitor_${current_date}.tar.gz"
# 压缩文件
tar -czf "$tar_file" "$output_file"
# 清空原文件
> "$output_file"
fi