定时发送服务器运行数据并设置阀值警报方法

案例分析:笔者架设了公司总体的服务器系统监控系统,实现运行数据收集,筛选,报警的机制,采用了windows系统自带的性能监视器,可是在实施的过程当中,遇到了一个问题:性能监视器没法对sql server 2008(基于window server 2008)进行系统性能监控,没法从监控主机连上目前机器,就没法收集数据进行处理。因这台服务器比较重要,是公司的ERP数据库服务器,已经连续发生了两次因D盘空间爆满,sql server没法启动,致使大面积用户没法登录正常使用的状况。笔者针对现状,决定采起脚本与批处理结合的办法,天天定时发送服务器运行数据到指定邮箱,并手工对D盘作阀值报警设置,步骤以下:sql

1. 经过脚本收集数据到指定文件夹(见前几批博文介绍)数据库

2. 在发送数据到指定文件夹的同时,放置一份数据到临时文件,而后每次收集时进行更新windows

echo off服务器

echo %date% %time% >>info.txt ‘写入固定文件夹,每次新增ide

echo CPU Information:>>info.txt性能

cscript //Nologo cpu.vbs >> info.txtcode

echo Memery Information:>>info.txtorm

cscript //Nologo ram.vbs >> info.txtserver

cscript //Nologo hard.vbs >> info.txttoken

echo %date% %time% >temp.txt ‘写入临时文件夹,每次刷新

echo CPU Information:>>temp.txt

cscript //Nologo cpu.vbs >>temp.txt

echo Memery Information:>>temp.txt

cscript //Nologo ram.vbs >> temp.txt

cscript //Nologo hard.vbs >> temp.txt

3. 在监控服务器的计划任务中添加邮件发送任务,天天10:00定时发送temp的内容到指定服务器

content= "C:\perflogs-remote\PROD-SQL\temp.txt"

set fso=createobject("scripting.filesystemobject")

if fso.fileexists(content) then

set fil=fso.getfile(content)

filename=fil.name

if lcase(right(filename,4))=".txt" then

set txt=fso.opentextfile(content,1)

code=txt.readall

txt.close

end if

end if

nr=code

Const Email_From = "abc@163.com"

'Const Password = ""

Const Email_To = "def@163.com"

Set CDO = CreateObject("CDO.Message")

CDO.Subject = " Status Report"

CDO.From = Email_From

CDO.To = Email_To

CDO.TextBody = nr

'cdo.AddAttachment = "C:\hello.txt"

Const schema = "http://schemas.microsoft.com/cdo/configuration/"

With CDO.Configuration.Fields

.Item(schema & "sendusing") = 2

.Item(schema & "smtpserver") = "10.4.100.70"

.Item(schema & "smtpauthenticate") = 0

.Item(schema & "sendusername") = Email_From

'.Item(schema & "sendpassword") = Password

.Item(schema & "smtpserverport") = 25

.Item(schema & "smtpusessl") = False

.Item(schema & "smtpconnectiontimeout") = 60

.Update

End With

CDO.Send

msgbox "Email sent!"

D盘阀值设置步骤:

1. 截取temp.txt中的关于D盘的须要字段

2012/11/21 16:44:09.22

CPU Information:

CPU Usage: 19%

Memery Information:

Total Memery: 16384 MB

Available Memery: 617 MB

Memery Usage:96%

Harddisk information£o

Partition:C

Available Space:3.733 GB

Total Space:39.9 GB

Usage:90.6433553637135%

Partition:D

Available Space:24.383 GB

Total Space:59.997 GB

Usage:59.3590957097753%

在上述信息中,须要截取D盘的使用率,值是59,代码以下:

@echo off

for /f "tokens=*" %%i in (temp.txt) do set str=%%i&call set str=%%str:~6,2%%’获取D盘的值并赋值给str

if %str% LSS 30 start c:\perflogs-remote\PROD-SQL\Prod-sql-alert.vbs’str值与30作比较,如小于30就发送报警邮件。

具体的如何实现报警的方法,请参见以前介绍过的SMTP脚本。

相关文章
相关标签/搜索