[root@makeISO sjx]# cat per-html.sh #!/bin/bash perf () { # # Size Used Avail Use% # echo ‘<table border="0">‘ echo ‘<thead align="right">‘ echo -e "<tr>\n\t<th colspan=‘"5"‘>-----------------------$1-----------------------</th>\n</tr>" echo "Size:Used:Avail:Use(%)"| tr ‘-‘ ‘ ‘| awk -F ‘:‘ ‘{printf "<tr>\n\t<td></td>\n\t<td>%s</td>\n\t<td>%s</td>\n\t<td>%s</td>\n\t<td>%s</td>\n</tr>\n",$1,$2,$3,$4}‘ # #CPU - - - 0.63% # ssh $1 iostat |head -4 |tail -1| awk ‘{use=100-$6; printf "<tr>\n\t<td>CPU</td>\n\t<td>-</td>\n\t<td>-</td>\n\t<td>-</td>\n\t<td>%s%</td>\n</tr>\n",use}‘ # #MEM 10.00GB 2.00GB 8.00GB 20.00% # ssh $1 free -k |grep ‘+‘| awk ‘{size=($3+$4)/1024/1024;used=$3/1024/1024;avail=$4/1024/1024;use=$3*100/($3+$4); printf "<tr>\n\t<td>MEM</td>\n\t<td>%.2fGB</td>\n\t<td>%.2fGB</td>\n\t<td>%.2fGB</td>\n\t<td>%.2f%</td>\n</tr>\n",size,used,avail,use}‘ # #DISK 1000.00GB 200.00GB 800.00GB 20.00% # ssh $1 df |egrep ‘[v|s]d[a|b|c|d][[:digit:]]*‘ | awk ‘{size=($3+$4)/1024/1024;used=$3/1024/1024;avail=$4/1024/1024;use=$3*100/$2; printf "<tr>\n\t<td>%-s</td>\n\t<td>%.2fGB</td>\n\t<td>%.2fGB</td>\n\t<td>%.2fGB</td>\n\t<td>%.2f%</td>\n</tr>\n",substr($1,6),size,used,avail,use}‘ echo "</table>" } echo \<html\> echo \<body\> perf 10.12.29.1 perf 10.12.29.11 perf 10.12.29.12 perf 10.12.29.13 echo \</body\> echo \</html\> [root@makeISO sjx]# sh per-html.sh >perf.html [root@makeISO sjx]# cat perf.html <html> <body> <table border="0"> <thead align="right"> <tr> <th colspan=‘5‘>-----------------------10.12.29.1-----------------------</th> </tr> <tr> <td></td> <td>Size</td> <td>Used</td> <td>Avail</td> <td>Use(%)</td> </tr> <tr> <td>CPU</td> <td>-</td> <td>-</td> <td>-</td> <td>0.04%</td> </tr> <tr> <td>MEM</td> <td>15.58GB</td> <td>1.01GB</td> <td>14.57GB</td> <td>6.48%</td> </tr> <tr> <td>sda1</td> <td>186.74GB</td> <td>10.22GB</td> <td>176.52GB</td> <td>5.20%</td> </tr> </table> <table border="0"> <thead align="right"> <tr> <th colspan=‘5‘>-----------------------10.12.29.11-----------------------</th> </tr> <tr> <td></td> <td>Size</td> <td>Used</td> <td>Avail</td> <td>Use(%)</td> </tr> <tr> <td>CPU</td> <td>-</td> <td>-</td> <td>-</td> <td>0.07%</td> </tr> <tr> <td>MEM</td> <td>3.74GB</td> <td>1.31GB</td> <td>2.43GB</td> <td>35.06%</td> </tr> <tr> <td>sda1</td> <td>46.59GB</td> <td>5.07GB</td> <td>41.52GB</td> <td>10.32%</td> </tr> </table> <table border="0"> <thead align="right"> <tr> <th colspan=‘5‘>-----------------------10.12.29.12-----------------------</th> </tr> <tr> <td></td> <td>Size</td> <td>Used</td> <td>Avail</td> <td>Use(%)</td> </tr> <tr> <td>CPU</td> <td>-</td> <td>-</td> <td>-</td> <td>0.4%</td> </tr> <tr> <td>MEM</td> <td>3.74GB</td> <td>0.51GB</td> <td>3.23GB</td> <td>13.56%</td> </tr> <tr> <td>sda1</td> <td>46.59GB</td> <td>3.72GB</td> <td>42.87GB</td> <td>7.58%</td> </tr> </table> <table border="0"> <thead align="right"> <tr> <th colspan=‘5‘>-----------------------10.12.29.13-----------------------</th> </tr> <tr> <td></td> <td>Size</td> <td>Used</td> <td>Avail</td> <td>Use(%)</td> </tr> <tr> <td>CPU</td> <td>-</td> <td>-</td> <td>-</td> <td>0.28%</td> </tr> <tr> <td>MEM</td> <td>3.74GB</td> <td>1.26GB</td> <td>2.48GB</td> <td>33.73%</td> </tr> <tr> <td>sda1</td> <td>46.59GB</td> <td>3.77GB</td> <td>42.82GB</td> <td>7.68%</td> </tr> </table> </body> </html> [root@makeISO sjx]# cp perf.html /var/www/html/ [root@makeISO sjx]# elinks http://127.0.0.1/perf.html -----------------------10.12.29.1----------------------- Size Used Avail Use(%) CPU - - - 0.04% MEM 15.58GB 1.01GB 14.57GB 6.48% sda1 186.74GB 10.22GB 176.52GB 5.20% -----------------------10.12.29.11----------------------- Size Used Avail Use(%) CPU - - - 0.07% MEM 3.74GB 1.31GB 2.43GB 35.06% sda1 46.59GB 5.07GB 41.52GB 10.32% -----------------------10.12.29.12----------------------- Size Used Avail Use(%) CPU - - - 0.4% MEM 3.74GB 0.51GB 3.23GB 13.56% sda1 46.59GB 3.72GB 42.87GB 7.58% -----------------------10.12.29.13----------------------- Size Used Avail Use(%) CPU - - - 0.28% MEM 3.74GB 1.26GB 2.48GB 33.73% sda1 46.59GB 3.77GB 42.82GB 7.68% [root@makeISO sjx]# yum install -y mutt [root@makeISO sjx]# cat .muttrc set envelope_from=yes set from=admin@linux10.com set realname="admin" set use_from=yes [root@makeISO sjx]# source .muttrc [root@makeISO sjx]# cat /var/www/html/perf.html | mutt -s "服务器资源统计" -e "my_hdr content-type:text/html" www1707@vip.qq.com
本文出自 “三角花园” 博客,请务必保留此出处http://www1707.blog.51cto.com/1184226/1760738
原文地址:http://www1707.blog.51cto.com/1184226/1760738