search
HomeDatabaseMysql Tutorial 6. SQL Server数据库监控

6. SQL Server数据库监控

Jun 07, 2016 pm 04:48 PM
AlarmdatabasemonitorShort messagemail

常用的告警方式大致有:短信、邮件、应用程序(beep提示,图标提示,升窗提示等),可是不能一直坐在电脑前看着应用程序,或者用脚本部署监控,根本没有程序界面,

常用的告警方式大致有:短信、邮件、应用程序 (beep提示,图标提示,升窗提示等),可是不能一直坐在电脑前看着应用程序,或者用脚本部署监控,根本没有程序界面,所以通常用短信、邮件两种方式告警。

一. 告警方式

1. 短信

用程序发短信的方式一般有这两种:

(1) 硬件

需要1张SIM卡,1个SIM卡读卡设备 (比如:短信猫),然后把设备连接到电脑,应用程序根据设备的软件接口,传参并发送短信。记得把SIM卡设备放在信号好,无干扰的地方;

如果有大量短信要发,1张SIM卡是不够用的,而且发送过度频繁,可能被运营商视为恶意短信,把SIM卡号加入黑名单,那么就需要多张SIM卡甚至多个读卡设备。

显示号码为当前SIM卡号码,大多供应商都支持DLL、HTTP等多种接口,当然也可以基于接口二次开发。

DLL接口方法参考:SmsManager.sendTextMessage(…)

 

(2) 第三方短信接口

有多种接口形式提供,比如:Web Service形式,HTTP形式,还有邮件接口:往1380013900@xxx.com发个短小的邮件,这个邮件会以短信的形式转发到手机上,等等。只要往接口传参数,告诉它发给谁,发什么内容,就可以了。

显示号码为某个SIM卡号码,或者为固定号码 (如:106开头的),这取决于短信平台和运营商的实现方式,因为运营商发短信是不要卡的,直接可以发给目标号码,而且可以显示为固定的某个号码。

Web Service接口地址参考:?wsdl

Http接口地址参考:

 

2. 邮件

凡是实现了SMTP协议的组件,都可以发送邮件。

在Windows环境下,有系统自带的组件CDO (Collaboration Data Objects,以前叫OLE Messaging 或者Active Messaging),是MAPI库的COM封装。不管是自己开发程序,使用VBS,还是SQL Server的SQL Mail/Database Mail,通常都是调用的这个组件。

SMTP协议要求的参数大致如下:

SMTP Hostname: SMTP服务器名,如mail.test.com或者IP

SMTP Port: SMTP服务端口,25

SMTP Username: 通过SMTP发送邮件用来验证的用户名, 如果不要求身份验证,留空

SMTP Password: 通过SMTP发送邮件用来验证的密码, 如果不要求身份验证,留空

 

二. 选择告警方式并配置

1. 短信

不管是选择硬件,还是第三方接口,都需要一个程序来调用,可以是监控工具、脚本、甚至数据库。

(1)  监控工具/应用程序中,通常都留有短信接口的配置,配置接口地址即可;

(2) 在脚本中配置,Windows环境通常要借助OLE Automation;

OLE Automation后来改名叫Automation,是Windows上基于COM,用于脚本语言实现进程间通讯的机制,脚本如:VBS, SQL, Powershell,不包括BAT(BAT可以调用VBS)。

SQL Server中使用OLE Automation调用Web Service短信接口如下:

exec sp_configure'show advanced options', 1; RECONFIGURE; exec sp_configure'Ole Automation Procedures', 1; RECONFIGURE;   declare @text_message nvarchar(180)        ,@phone_numbernvarchar(15)        ,@soap_object  int        ,@status       int        ,@output       nvarchar(255)   set @text_message = N'Testing Mail' set @phone_number = N'138000139000'   --Create MSSOAP.SoapClient object exec @status=sp_OACreate'MSSOAP.SoapClient',@soap_object out   --SmsManager is Web Service name exec @status =sp_OAMethod@object, 'mssoapinit', null, 'http://123.456.789.000/SmsManager.asmx?wsdl', 'SmsManager'   --SendTextMessage is webservice method exec @status =sp_OAMethod@object, 'SendTextMessage', @output OUT, @phone_number,@text_message   if @status 0 begin    exec sp_OAGetErrorInfo@soap_object       select@soap_object end else begin    select@output end   --Destroy MSSOAP.SoapClient object exec @status =sp_OADestroy@soap_object GO

对于HTTP, DLL接口,和SOAP接口类似,用OLE Automation也都可以调用,主要区别就是在CreateObject() 时。

以VBS为例,调用HTTP, DLL时CreateObject()如下:

Dim http Set http =CreateObject("Msxml2.XMLHTTP")   Dim dll Set dll = CreateObject("工程名.类名")

 

2. 邮件

(1)  监控工具/应用程序中,通常都留有SMTP配置项,配置SMTP参数即可;

(2) 在脚本中配置,Windows环境通常要借助OLE Automation;

VBS发送邮件如下:

Dim ns ns ="http://schemas.microsoft.com/cdo/configuration/"   Dim title, content title = "db_maint_alert" content = "" content = content&"Hi All," content = content&chr(13)&chr(10) content = content&" " content = content&chr(13)&chr(10) content = content&"----testmail----" Msgbox('~1~')   Set cm =CreateObject("CDO.Message") cm.from ="from_user_name@abc.com" cm.to = "to_user_name@abc.com" cm.cc = "cc_user_name@abc.com" cm.subject = title cm.textbody = content 'cm.AddAttachment "" Msgbox('~2~')   'sendusing: 1 = pickup, 2 = port 'smtpauthenticate: 0 = anonymous,1 =common,2 = NTLM 'smtpusessl: 0 = no,1 = yes With cm.configuration.fields          .item(ns& "sendusing") = 2          .item(ns& "smtpserver") = "xxx.xxx.xxx.xxx"          .item(ns& "smtpserverport") = 25          .item(ns& "smtpauthenticate") = 1          .item(ns& "sendusername") = "user_name@abc.com"          .item(ns& "sendpassword") = "*****************"          .item(ns& "smtpconnectiontimeout") = 10          .item(ns& "smtpusessl") = 0          .update End With Msgbox('~3~')   cm.send Set cm = nothing Msgbox('~success~')


SQL Server 2000发送邮件如下:

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.