当前位置:  数据库>sqlserver

监控 log文件大小的存储过程

    来源: 互联网  发布时间:2014-09-05

    本文导语:  1、监控log文件大小超过10g的server 和db 代码如下: create procedure db_sendmail_mssqllogsize as declare @sql varchar(max),@servername varchar(50),@px int; DECLARE @xml NVARCHAR(MAX) DECLARE @body NVARCHAR(MAX) declare @a varchar(200) declare @c datetime select @c=getdate(); select h...

1、监控log文件大小超过10g的server 和db
代码如下:

create procedure db_sendmail_mssqllogsize
as
declare @sql varchar(max),@servername varchar(50),@px int;
DECLARE @xml NVARCHAR(MAX)
DECLARE @body NVARCHAR(MAX)
declare @a varchar(200)
declare @c datetime
select @c=getdate();
select
hostname
,px=ROW_NUMBER()over(order by (select 1))
into #temp
from DB_ALLHostInfo as x1
inner join sys.servers as x2
on x1.hostname=x2.name
where isactive=1;
select @px=px,@servername=hostname from #temp where px=1;
while @@ROWCOUNT>0
begin
set @sql=
'insert into db_alldb_logsize
select *,cast(convert(char(8),GETDATE(),112) as datetime) as gdate ,'''+@servername+''' from openquery('+QUOTENAME(@servername)+',''select DB_NAME(database_id) as dbname,name as logname,round(cast(size as float)*8/1024,3) as [logsize(mb)],state_desc,physi
cal_name, is_percent_growth,growth,max_size
from
master.sys.master_files
where type_desc=''''log''''
and DB_NAME(database_id) not in(''''master'''',''''tempdb'''',''''msdb'''',''''reportserver'''',''''reportservertempdb'''',''''distribution'''',''''model'''')
and DATABASEPROPERTY(DB_NAME(database_id),''''IsReadOnly'''')1'') as b;'
execute(@sql)
select 1
select top(1) @px=px,@servername=hostname from #temp where px>@px
end;
set @xml=cast((select J.servername as 'td','', isnull(J.dbname,'') as 'td','', J.logname as 'td','' ,cast([logsize(mb)] as varchar(20))as 'td',''
,state_desc as 'td',''
,physical_name as 'td',''
,case when max_size =0 then '不允许增长' when max_size=-1 then '文件将一直增长到磁盘变满为止' when max_size=268435456 then ' 日志文件将增长到最大大小 2 TB' end as 'td',''
,case when is_percent_growth =1 then '以按百分比'+cast(growth AS varchar(3))+'%' when is_percent_growth =0 then ' 以按大小'+cast(growth*8/1024 AS varchar(50))+'(mb)增长' end as 'td',''
,convert(char(8),gdate,112) as 'td',''
from db_alldb_logsize as j where gdate=cast(CONVERT(char(8),getdate(),112) as datetime) and [logsize(mb)]>=10240
FOR XML PATH('tr'), ELEMENTS) AS NVARCHAR(MAX)) ;
set @a='Mssqllog运行结果_'+convert (varchar(50),convert(varchar(5),YEAR(getdate()-1))+'年'+convert(varchar(2),month(getdate()-1))+'月'+convert(varchar(2),day(getdate()-1)))+'日'
--print @a
SET @body =''+convert(varchar(5),YEAR(getdate()) )+'年'+convert(varchar(2),month(getdate()))+'月'+convert(varchar(2),day(getdate()))+'Mssqllog运行结果
服务器ip数据库日志文件名日志文件大小(mb)状态物理路径增长类型增长状态日期'
if @xml is not null SET @body = @body + @xml +''
EXEC msdb.dbo.sp_send_dbmail
@recipients =N'xuwj@5173.com',
@body = @body,
@body_format ='HTML',
@subject =@a,
@profile_name ='profile1'
execute db_sendmail_mssqllogsize

2 邮件

 

 3配上简单的报表


    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • Docker监控以及cAdvisor和Prometheus监控工具的对比
  • 网关监控(网管监控):监控员工上网内容、进出电子邮件内容、聊天内容、上传和下载内容,过滤不良网站;设置一部分电子邮件帐号只能够发
  • 针对Docker容器的监控指标
  • 业务系统监控 ​kaleido
  • shell监控脚本实例—监控mysql主从复制
  • Metric监控系统 node-bell
  • 网络接口监控 WMND
  • 应用监控系统 HawtIO
  • linux系统下如何监控和获取用户行为(高分悬赏)
  • 系统状态监控工具 ProcMeter3
  • Web服务器文件安全监控平台 Falcon
  • LDAP监控软件 CN=Monitor
  • 网络监控系统 FreeNATS
  • 网络管理与监控系统 JFFNMS
  • 关于文件监控~~~~~~~~~~~~~
  • nagios监控不正常
  • 数据库监控工具 TrafficObjects
  • Ganglia的批量作业监控插件 Job Monarch
  • OSA监控精灵
  • 监控多个文件目录
  • Redis 服务器监控系统 Angel


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3