手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

大型网站的监控、报警与故障转移

[日期:2012-01-22] 来源:Linux社区  作者:凤凰舞者 [字体:大 中 小]

1.2.1.2 内存监控

主要监控内存的使用情况,包括内存使用量和空闲量。主要步骤和程序如下:

(1)编写shell监控程序 meminfo.sh并赋权限为750。

[root@localhost monitor]# cat meminfo.sh

#!/bin/bash

#author         longxibendi

#blog           http://blog.csdn.net/longxibendi

#function       getmem usage information

 /usr/bin/free | grep Mem > mem.log

cat mem.log | awk ' { print $3;}'

cat mem.log | awk ' { print $2;}'

/usr/bin/uptime

/sbin/ifconfig | grep "inet addr" |head -n 1 | awk '{print $2;}'

 

(2配置mrtg的配置文件mrtg.cfg添加以下内容。

Target[localhost_mem]:`/root/Desktop/monitor/meminfo.sh`

Xsize[localhost_mem]: 300

Ysize[localhost_mem]: 100

Ytics[localhost_mem]: 10

MaxBytes[localhost_mem]: 4096

Title[localhost_mem]: Memory Stateof  Server

PageTop[localhost_mem]: <H1>MemoryState of Server</H1>

ShortLegend[localhost_mem]: B

kmg[localhost_mem]: M

YLegend[localhost_mem]: Memory Usage

Legend1[localhost_mem]: Used

Legend2[localhost_mem]: Total

LegendI[localhost_mem]: Used

LegendO[localhost_mem]: Total

Options[localhost_mem]:growright,gauge,nopercent

  

(3)制作index.html并生成监控数据

indexmaker  /etc/mrtg/mrtg.cfg >/var/www/html/index.html

LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

 

该监控方法是先通过执行程序meminfo.sh得到内存的使用量和空闲量,然后通过mrtg把相应的数据绘画出来,形成图形。结果如图8-2-1-2-1所示。


                  图8-2-1-2-1

如图8-2-1-2-1所示,横坐标表示时间,纵坐标表示内存使用量。其中绿色部分为内存使用量,蓝色部分为内存总量。图8-2-1-2-1为当天内存使用情况。周、月、年的展示图省略。

1.2.1.3 外设磁盘监控

主要监控磁盘的使用情况磁盘,包括磁盘的读出速度和写入速度

主要步骤和程序如下:

(1)编写shell监控程序 ioinfo.sh并赋权限为750。

[root@localhost monitor]# cat ioinfo.sh

#!/bin/bash

#author         longxibendi

#blog           http://blog.csdn.net/longxibendi

#function       getinformation  of  sda's io

 /usr/bin/iostat  |grep  "sda "   > ioinfo.log

cat ioinfo.log | awk ' { print $3;}'

cat ioinfo.log | awk ' { print $4;}'

/usr/bin/uptime

/sbin/ifconfig | grep "inet addr" |head -n 1 | awk '{print $2;}'

 

(2配置mrtg的配置文件mrtg.cfg添加以下内容。

Target[localhost_io]:`/root/Desktop/monitor/ioinfo.sh`

Xsize[localhost_io]: 300

Ysize[localhost_io]: 100

Ytics[localhost_io]: 10

MaxBytes[localhost_io]: 100

Title[localhost_io]: IO Stateof  Server

PageTop[localhost_io]: <H1>SDA State ofServer</H1>

ShortLegend[localhost_io]: blocks

YLegend[localhost_io]: Blk_read/s Blk_wrtn/s

Legend1[localhost_io]: Blk_read/s

Legend2[localhost_io]: Blk_wrtn/s

LegendI[localhost_io]: Blk_read/s

LegendO[localhost_io]: Blk_wrtn/s

Options[localhost_io]: growright,gauge,nopercent

  

(3)制作index.html并生成监控数据

indexmaker  /etc/mrtg/mrtg.cfg >/var/www/html/index.html

LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

 

该监控方法是先通过执行程序ioinfo.sh得到磁盘的读速度和写速度,然后通过mrtg把相应的数据绘画出来,形成图形。结果如图8-2-1-3-1所示。


 

                       图8-2-1-3-1

如图8-2-1-3-1所示,横坐标表示时间,纵坐标表示磁盘速度。其中绿色部分为磁盘读取速度,蓝色部分为磁盘写入速度。

图8-2-1-3-1为当天磁盘scsi磁盘的第一块分区使用情况,周、月、年展示图省略。如果想增大监控粒度,可以考虑监控inode节点数使用情况。因为节点数不够用也会报错。

linux
相关资讯       服务器 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款