[文章作者:张宴 本文版本:v1.0 最后修改:2007.08.03 转载请注明出处:http://blog.zyan.cc]

  我管理服务器太多了,不可能每时每刻都登录到上面查看服务器状况,于是写了一个“服务器监控系统 ServMon V1.0”。其原理是用shell脚本定时抓取被监控服务器上信息,再用curl POST到监控机的PHP接口程序上,由PHP接口程序对信息进行分析,如果存在异常,则发送报警邮件给管理员。

  下午,ServMon V1.0 已经在sina播客服务器上部署,以下为ServMon的删节版内容,只监控磁盘分区使用率和Swap交换空间两项:

  点击在新窗口中浏览此图片

  1、被监控端服务器的shell脚本(Linux)
  (1)、发送磁盘分区使用率给监控端接口http://192.168.0.28/servmon/interface.php的脚本
引用
/usr/local/servmon/bin/diskstat_send
#!/bin/sh
LANG=zh_cn
disk=$(/bin/df -kP | grep / | awk -F ' ' ' {print $6":"$5}' | awk -F '%' ' {print $1}' | tr -s '\n' ';')
today=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")
ip=$(/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{print $2;}' | awk -F':' '{print $2;}' | tr -s '\n' ';')
/usr/bin/curl -d menu=diskstat -d password=$2 -d date=$today -d ip=$ip -d data=$disk $1

  磁盘分区使用率监控报警邮件示例图:
  点击在新窗口中浏览此图片


  (2)、发送Swap交换空间使用率给监控端接口http://192.168.0.28/servmon/interface.php的脚本
  /usr/local/servmon/bin/swapstat_send
引用
#!/bin/sh
LANG=zh_cn
data=$(/usr/bin/free -m | grep Swap | awk '{print $2":"$3":"$4}')
today=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")
ip=$(/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{print $2;}' | awk -F':' '{print $2;}' | tr -s '\n' ';')
/usr/bin/curl -d menu=swapstat -d password=$2 -d date=$today -d ip=$ip -d data=$data $1

  Swap交换空间使用率监控报警邮件示例图:
  点击在新窗口中浏览此图片

  (3)、计划任务:每30分钟将磁盘分区使用率发送给监控端接口,每10分钟将Swap交换空间使用率发送给监控端接口。
  /etc/cron.d/servmon
引用
0-30/30 * * * * root /bin/sh /usr/local/servmon/bin/diskstat_send http://192.168.0.28/servmon/interface.php yourpassword
0-50/10 * * * * root /bin/sh /usr/local/servmon/bin/swapstat_send http://192.168.0.28/servmon/interface.php yourpassword





  2、监控端服务器配置(Linux)
  (1)、启动sendmail
  /usr/sbin/sendmail -bd -q30m
  -b:指定Sendmail在后台运行,并且监听端口25的请求。
  -d:指定Sendmail以Daemon方式运行(守护进程)。
  -q:当Sendmail无法将邮件成功地发送到目的地时,它会将邮件保存在队列里。该参数指定邮件在队列里保存的时间。其中的30m表示保留30分钟。

  (2)、修改php.ini的[mail function]部分为以下内容,然后重启Apache,使PHP能够使用mail()函数发送电子邮件
引用
[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t -i


  (4)、在MySQL上创建一个数据库servmon,然后在该数据库中执行以下SQL语句创建表:
引用
CREATE TABLE `tb_diskstat` (
 `ip` varchar(128) NOT NULL default '',
 `date` int(10) NOT NULL default '0',
 UNIQUE KEY `ip` (`ip`)
) TYPE=MyISAM;

  备注:这张表是PHP接口程序用来记录发送磁盘分区报警邮件的时间,避免在一段时间内重复发送大量报警邮件的,其实完全可以用Session、文本文件来代替它。这里之所以用MySQL数据库,是因为PHP接口中还将增加一些需要记录信息到数据库的监控模块,所以就统一用数据库了。)

  (3)、PHP接口程序
  http://192.168.0.28/servmon/interface.php


Tags: ,
技术大类 » 其他Unix技术 | 评论(38) | 引用(0) | 阅读(38573)
tankinc
2009-12-5 17:28
通过snmp可以监控到进程吗
宝鸡seo Homepage
2010-1-25 10:47
看不太懂 。。。就来感受一下这里的气氛
dresses Email Homepage
2011-7-26 10:20
Here are a variety of the empire <a href="http://www.romancearound.com/">dresses</a>, I want to introduce yourself. The first shoulder chiffon <a href="http://www.romancearound.com/bridesmaid-dresses-c-197.html">bridesmaid dresses</a> empire style wedding will <a href="http://www.romancearound.com/wedding-dresses-trumpet-wedding-dresses-c-180_253.html">trumpet wedding dresses</a>.This Tia cowries, dressed in her wedding day.Chiffon of the empire the best clothes, because they are the size of the drum as complete motion from the wind the site makes it easy to create a plan impression.One romantic flowers floating above shoulder function and help catch the eyes of the cut of the chest and neck problems, so that more comprehensive coverage of physical illusion bust.Clothing do not like big long torso, short legs, or pear-shaped<a href="http://www.romancearound.com/bridesmaid-dresses-ankle-length-bridesmaid-dresses-c-197_198.html">ankle length bridesmaid dresses</a> figure.special is also suitable for pregnant brides since the mobility as a dress can accommodate more Many of the abdomen.
louis vuitton uk Email Homepage
2011-11-23 08:48
This louis vuitton uk for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this coach outlet store online. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine christian louboutin sale. Purse the elegance in bridal wedding. Enjoy the fashion.
coach factory outlet Email Homepage
2012-5-17 10:55
Today, following half a century, mentor leather-bases coach factory outlet continues to be the delicate craft of leather-based master is accountable for,Would you like to meet more friends, or go with the times? If yes, coach factory online is opening welcome doors to you.in the market you definitely can find various colorways that are designed in as well as the high quality that applied in. For most of you would like to come. So just come to our coach factory outlet online store to choose one.
louis vuitton sale Email Homepage
2012-5-17 10:55
Louis Vuitton belt at louis vuitton sale is one kind of fashion accessory with high cost performance among the Louis Vuitton accessories.Offering quality LV products with favorable prices, louis vuitton outlet store is at your service. Hurry up, or you can not seize the chance.in fact, louis vuitton is one of the most famous fashion design master.he opened the fist suitcase shop called after his name.
coach outlet online Email Homepage
2012-5-17 10:55
I heard of coach outlet online through the advertisement when I was shopping. And now I often brow the webpage and buy Coach bags online.It is a symbol regarding position not to mention nature.Here I would like to launch a excellent bags pertaining to business men.Which may be coach outlet store.coach outlet has always been simple,durable style features to win consumers.The products are more flexible,with easy bleaching,wear characteristics,and simply use a damp cloth.
coach outlet, Email Homepage
2012-5-17 10:56
Remember the coach outlet provide coach bags which won't be deteriorated into its overall styles by any means. It will maintain its looks, colors, and uniqueness for long time.coach outlet store online has been voted by Hour Detroit magazine readers as the Best of Detroit in their 12th annual readers'poll.Lots of women like which usually amount normally include a coach outlet online ,it provides coziness to many girls that don't even think it is a great bushel of great interest directly to them.
xujie777 Email
2012-5-18 15:53
We aim to make all our customers satisfy with our products. You will find a variety of Men's fashion louis vuitton uk, fashion Women's cheap Louis Vuitton bags in our store at affordable price.Thinking of interesting ways to cost a milestone birthday? louis vuitton online shop had one of the most distinctive distinctive celebrations.bakery along with living room operated by means of about three moment louis vuitton online Most effective Pastry Chef’s of the year Rammy Nominee Chef’s.
xujie777 Email
2012-5-18 15:53
The choices are likely to be basically countless seeing that louis vuitton outlet occurs with the help of completely new and also incredible concepts once in a while.Louis vuitton Wholesale Monogram Canvas HandbagsLouis Vuitton Collection Beach Handbags louis vuitton bags outlet Damier Canvas HandbagsLouis vuitton Mahina HandbagsLouis Vuitton Monogram Mini Lin HandbagsLouis Vuitton Monogram Multicolore HandbagsLouis vuitton Monogram Vernis HandbagsLouis Vuitton Wholesale Epi Leather HandbagsLouis Vuitton For Men HandbagsLouis Vuitton Damier Canvas WalletsLouis Vuitton Epi Leather WalletsLouis Vuitton Monogram Canvas WalletsLouis Vuitton Monogram Vernis WalleLouis Vuitton ShoesLouis Vuitton Men wallets.As the Authentic Louis Vuitton are so high-priced, so came the louis vuitton handbags outlet.
xujie777 Email
2012-5-18 15:53
coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers.Getting your hands on coach outlet store online can be a hefty investment of hundreds of dollars.But do not despair,the Coach Outlet store could be the answer to your prayers.coach outlet online is your smart choice when you want to get the discount Coach accessory. You can find the exact Coach Bags and other accessory you want at a low price that's right for you. My dear friends, let the coach outlet online pave your way into the world of high fashion with their ultimate fashion factory.
xujie123
2012-5-21 11:04
Our online store offers you discounted Designer louis vuitton replica wallet at present. You could find them in desirable quality and price. If you don't mind high class louis vuitton uk, have a good time here.louis vuitton Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable.Have you ever dreamed of being as charming as Madonna? Have you ever thought of becoming an envy of all your friends? If so, come to louis vuitton outlet.<br/>
xujie555
2012-5-21 13:29
coach factory outlet uses graceful accessories to match the classical logo of coach, which is the best combination of coach. The handmade coach products?can make you more charming and graceful.coach factory online provides people many coach goods. If you wish to snatch the coach handbag, then this best method is made for that you like for coach discount.coach factory outlet online is a fashion brand to ensure its quality. With designer coach shoulder bags, you will always attract people's attention. The bags will emphasize your personal style and taste.<br/>
xujie333
2012-5-21 14:50
coach outlet online Store guarantee that all the coach handbags offered are own high quality. In addition , all of them are sold at an unexpected low price.If you want to purchase, just visit their website.coach factory outlet is really sizzling kinds of shopping way for you. With the usage of the replica designer coach bags, you can surely be able to change your individual looks in a stunning manner.Coach bags on sale from the coach outlet are cheap or discount prices that you certainly will stand out from the crowd on your next camping trip!<br/>
xiaohai123 Email Homepage
2012-6-8 10:41
Les produits de la marque Versace, y compris les verres,<a href="http://www.saclongchampss.com">Sac Longchamp Pliage,Boutique,Sacs Longchamp Pas Cher</a>  le parfum des sacs de maquillage décoration intérieure écharpe montres bijoux soins de la peau http://www.saclongchampss.com ceinture, Gianni Versace SpA Groupe est le leader mondial de salle internationale design de mode. Le sac Mme les Xiekua (6:27) sacs Mme d'acheter (6:27), le classement de Mme la marque de sac (6:27) liste le sac de Mme. Bo?te A propos de Global conquérir le monde! Mondial bagages agent de gros net des sacs en cuir de marque Marchands Chine,
<a href="http://www.saclongchampss.com">sac pas cher</a> du cuir, sacs en cuir de rejoindre, à la conception des sacs, sacs à main en cuir d'information
Canada Goose Parka Email Homepage
2012-6-30 14:26
In order to have a warm winter, the Canada Goose Parka jackets are sure to be the must collected clearances for people. Ladies can find long length made Canada Goose Trillium coats which would offer you ultra windproof. And with qualified fabrics made Canada Goose Expedition would also be perfect for protection when for skating.
coach88888888 Email
2012-8-13 17:35
If you desire to go to Coach Factory Outlet, but have no idea in which to go, you can research online. It is no doubt that there is drastically information and details about it for the reference.Coach Factory Online are loved by many people, when you walk in the street, you could see many people take coach styles.hat experts claim Coach Outlet Online shopping is in the changes they are available in.Coach Outlet will send you a coupon in the post to use in their upon only after you type a achieve. The Coach bags are customarily somewhat many than the ones in the stores.
海阔天空 Homepage
2013-5-13 21:34
海阔天空俏佳人娱乐会所15026982229 小姐服务24小时出差旅游大学生兼职按摩小姐上门,处女开红,兼职空姐,,白俄罗斯小姐,兼职模特,性感少妇全国连锁,就近提供北京、上海、广州等地姐兼职美女上门保健按摩北京小姐上门,上海兼职美眉,广州美女上门保健按摩,西安女大学生兼职,重庆空姐兼职,杭州酒店宾馆美女,温州兼职美女,南京白领兼职,全国本地找小姐上门按摩,模特私拍,援助交际更多请进 www.lvcai.org 查看
分页: 2/2 第一页 上页 1 2 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]