程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> MSSQL >> 監控 log文件年夜小的存儲進程

監控 log文件年夜小的存儲進程

編輯:MSSQL

監控 log文件年夜小的存儲進程。本站提示廣大學習愛好者:(監控 log文件年夜小的存儲進程)文章只能為提供參考,不一定能成為您想要的結果。以下是監控 log文件年夜小的存儲進程正文


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 ='<html><H1>'+convert(varchar(5),YEAR(getdate()) )+'年'+convert(varchar(2),month(getdate()))+'月'+convert(varchar(2),day(getdate()))+'Mssqllog運轉成果</H1><body bgcolor=#E3F6CE><table border =1>
<tr><th>辦事器ip</th><th>數據庫</th><th>日記文件名</th><th>日記文件年夜小(mb)</th><th>狀況</th><th>物理途徑</th><th>增加類型</th><th>增加狀況</th><th>日期</th>'
if @xml is not null SET @body = @body + @xml +'</table></body></html>'
EXEC msdb.dbo.sp_send_dbmail
@recipients =N'[email protected]',
@body = @body,
@body_format ='HTML',
@subject =@a,
@profile_name ='profile1'
execute db_sendmail_mssqllogsize

2 郵件

 

 3配上簡略的報表

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved