sql server监控

sql server监控,第1张

概述sql server监控http://www.mssqltips.com/sqlservertip/2522/sql-server-monitoring-checklist/1.查看sql server 服务运行状态:http://msdn.microsoft.com/zh-cn/library/ms189089%28v=sql.105%29.aspxexec master.dbo.xp_servicecontrol 'QUERYSTATE', 'MSSQLServer'exec master.dbo.xp_servicecontrol 'QUERYSTATE', 'SQLServerAgent'exec master.dbo.xp_servicecontrol 'QUERYSTATE', 'SQLBrowser' 2.查看sql server agent 工作执行情况:use msdbgoselect 'FAILED' as Status, cast(sj.name as varchar(100)) as "Job Name",cast(sjs.step_id as varchar(5)) as "Step ID",cast(sjs.step_name as varchar(30)) as "Step Name",cast(REPLACE(CONVERT(varchar,convert(datetime,convert(varchar,sjh.run_date)),102),'.','-')+' '+SUBSTRING(RIGHT('000000'+CONVERT(varchar,sjh.run_time),6),1,2)+':'+SUBSTRING(RIGHT('000000'+CONVERT(varchar,sjh.run_time),6),3,2)+':'+SUBSTRING(RIGHT('000000'+CONVERT(varchar,sjh.run_time),6),5,2) as varchar(30)) 'Start Date Time',sjh.message as "Message"from sysjobs sjjoin sysjobsteps sjson sj.job_id = sjs.job_idjoin sysjobhistory sjhon sj.job_id = sjh.job_id and sjs.step_id = sjh.step_idwhere sjh.run_status <> 1and cast(sjh.run_date as float)*1000000+sjh.run_time >cast(convert(varchar(8), getdate()-1, 112) as float)*1000000+70000 --yesterday at 7amunionselect 'FAILED',cast(sj.name as varchar(100)) as "Job Name",'MAIN' as "Step ID",'MAIN' as "Step Name",cast(REPLACE(CONVERT(varchar,convert(datetime,convert(varchar,sjh.run_date)),102),'.','-')+' '+SUBSTRING(RIGHT('000000'+CONVERT(varchar,sjh.run_time),6),1,2)+':'+SUBSTRING(RIGHT('000000'+CONVERT(varchar,sjh.run_time),6),3,2)+':'+SUBSTRING(RIGHT('000000'+CONVERT(varchar,sjh.run_time),6),5,2) as varchar(30)) 'Start Date Time',sjh.message as "Message"from sysjobs sjjoin sysjobhistory sjhon sj.job_id = sjh.job_idwhere sjh.run_status <> 1 and sjh.step_id=0and cast(sjh.run_date as float)*1000000+sjh.run_time >cast(convert(varchar(8), getdate()-1, 112) as float)*1000000+70000 --yesterday at 7am 3.查询数据库备份情况:SELECT d.name AS "Database",ISNULL(CONVERT(VARCHAR,b.backupdate,120),'NEVER') AS "Last Full Backup"FROM sys.databases dLEFT JOIN (SELECT database_name,type,MAX(backup_finish_date) backupdate FROM backupsetWHERE type LIKE 'D'GROUP BY database_name,type) b on d.name=b.database_nameWHERE (backupdate IS NULL OR backupdate < getdate()-1)SELECT d.name AS "Database",ISNULL(CONVERT(VARCHAR,b.backupdate,120),'NEVER') AS "Last Log Backup"FROM sys.databases dLEFT JOIN (SELECT database_name,type,MAX(backup_finish_date) backupdate FROM backupsetWHERE type LIKE 'L'GROUP BY database_name,type) b on d.name=b.database_nameWHERE recovery_model = 1AND (backupdate IS NULL OR backupdate < getdate()-1)4.查看sql server 错误日志情况:declare @Time_Start datetime;declare @Time_End datetime;set @Time_Start=getdate()-2;set @Time_End=getdate();-- Create the temporary tableCREATE TABLE #ErrorLog (logdate datetime, processinfo varchar(255), Message varchar(500))-- Populate the temporary tableINSERT #ErrorLog (logdate, processinfo, Message)EXEC master.dbo.xp_readerrorlog 0, 1, null, null , @Time_Start, @Time_End, N'desc';-- Filter the temporary tableSELECT LogDate, Message FROM #ErrorLogWHERE (Message LIKE '%error%' OR Message LIKE '%failed%') AND processinfo NOT LIKE 'logon'ORDER BY logdate DESC-- Drop the temporary tableDROP TABLE #ErrorLog5.查看磁盘剩余空间:--剩余空间exec master.dbo.xp_fixeddrives--总空间和剩余空间declare @svrName varchar(255)declare @sql varchar(400)--by default it will take the current server name, we can the set the server name as wellset @svrName = @@SERVERNAMEset @sql = 'powershell.exe -c "Get-WmiObject -ComputerName ' + QUOTENAME(@svrName,'''') + ' -Class Win32_Volume -Filter ''DriveType = 3'' | select name,capacity,freespace | foreach{$_.name+''|''+$_.capacity/1048576+''%''+$_.freespace/1048576+''*''}"'--creating a temporary tableCREATE TABLE #output(line varchar(255))--inserting disk name, total space and free space value in to temporary tableinsert #outputEXEC xp_cmdshell @sql--script to retrieve the values in MB from PS Script outputselect rtrim(ltrim(SUBSTRING(line,1,CHARINDEX('|',line) -1))) as drivename,round(cast(rtrim(ltrim(SUBSTRING(line,CHARINDEX('|',line)+1,(CHARINDEX('%',line) -1)-CHARINDEX('|',line)) )) as Float),0) as 'capacity(MB)',round(cast(rtrim(ltrim(SUBSTRING(line,CHARINDEX('%',line)+1,(CHARINDEX('*',line) -1)-CHARINDEX('%',line)) )) as Float),0) as 'freespace(MB)'from #outputwhere line like '[A-Z][:]%'order by drivename--script to retrieve the values in GB from PS Script outputselect rtrim(ltrim(SUBSTRING(line,1,CHARINDEX('|',line) -1))) as drivename,rou

sql server监控

http://www.mssqltips.com/sqlservertip/2522/sql-server-monitoring-checkList/

1.查看sql server 服务运行状态:

http://msdn.microsoft.com/zh-cn/library/ms189089%28v=sql.105%29.aspx

master.dbo.xp_servicecontrol , master.dbo.xp_servicecontrol , master.dbo.xp_servicecontrol ,

2.查看sql server agent 工作执行情况:

Status,(sj.name ()) (sJs.step_ID ()) (sJs.step_name ()) (((,(,(,sjh.run_date)),),,) (((,sjh.run_time),),,)(((,,,) ()) sj.job_ID sj.job_ID sjh.job_ID sJs.step_ID sjh.run_status (sjh.run_date )sjh.run_time (((),(),) ) , sj.job_ID sjh.run_status sjh.step_ID (sjh.run_date )sjh.run_time (((),) )

3.查询数据库备份情况:

d.name "((,b.backupdate,),) "Last ( database_name,type,(backup_finish_date) backupdate type database_name,type) b d.name (backupdate backupdate () d.name ") "Last ( database_name,(backup_finish_date) backupdate type database_name,type) b d.name recovery_model (backupdate backupdate ())

4.查看sql server 错误日志情况:

() #ErrorLog (logdate (( master.dbo.xp_readerrorlog ,,,,N LogDate,Message (Message Message ) processinfo logdate #ErrorLog

5.查看磁盘剩余空间:

( ( (,) ( xp_cmdshell (((line,(,line) ))) (((((line,line)(,line) )(,line)) )) ),) (,((,line) )(,) line (((line,line)) )) ),) ) ,) line #output

6.sql server内存使用情况:

available_physical_memory_kb (total_physical_memory_kb) " sys.dm_os_sys_memory

7.sql 执行消耗情况(IO vs. cpu vs. Elapsed Time):

total_physical_readstotal_logical_writes)execution_count execution_count) execution_count) "Execution "query total_elapsed_timeexecution_count

8.数据库连接情况:

p.dbIDd.database_ID

9.正在处理的请求数:

counter_name DELAY (cntr_value) "Batch Requests counter_name

9.

总结

以上是内存溢出为你收集整理的sql server监控全部内容,希望文章能够帮你解决sql server监控所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1169106.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存