sqlserver JOB 監控
1,建立DTS 執行 ,
a .select b.originating_server as HOSTNAME,
'10.182.15.91' as HOSTIP,
b.name as JOB_NAME,
case a.last_run_outcome
when 0 then
'作業失敗'
when 1 then
'作業成功'
when 3 then
'作業取消'
when 5 then
'第一次執行'
else
'other'
end LAST_RUN_STATUS,
/* 'FAIL' as LASR_RUN_STTUS,*/
a.last_run_time LAST_RUN_TIME,
GETDATE() as RECODE_DATE,
/*'20120416' LAST_RUN_DATE*/
a.last_run_date LAST_RUN_DATE
from msdb .. sysjobservers a
left join msdb .. sysjobs b on a.job_id = b.job_id
where a.last_run_outcome in (0, 1, 3, 5) and b.enabled = 1
'10.182.15.91' as HOSTIP,
b.name as JOB_NAME,
case a.last_run_outcome
when 0 then
'作業失敗'
when 1 then
'作業成功'
when 3 then
'作業取消'
when 5 then
'第一次執行'
else
'other'
end LAST_RUN_STATUS,
/* 'FAIL' as LASR_RUN_STTUS,*/
a.last_run_time LAST_RUN_TIME,
GETDATE() as RECODE_DATE,
/*'20120416' LAST_RUN_DATE*/
a.last_run_date LAST_RUN_DATE
from msdb .. sysjobservers a
left join msdb .. sysjobs b on a.job_id = b.job_id
where a.last_run_outcome in (0, 1, 3, 5) and b.enabled = 1
b,和oracle監控建立對應的表 連線
create table MSQL_JOB
(
HOSTNAME VARCHAR2(30),
HOSTIP VARCHAR2(15),
JOB_NAME VARCHAR2(200),
LAST_RUN_STATUS VARCHAR2(10),
LAST_RUN_TIME NUMBER,
RECORD_DATE DATE,
LAST_RUN_DATE NUMBER
)
(
HOSTNAME VARCHAR2(30),
HOSTIP VARCHAR2(15),
JOB_NAME VARCHAR2(200),
LAST_RUN_STATUS VARCHAR2(10),
LAST_RUN_TIME NUMBER,
RECORD_DATE DATE,
LAST_RUN_DATE NUMBER
)
C,mssql建立JOB定時執行。
2,建立監控product。
a,自動增加product
create or replace procedure SendWFL_SQL_ADDJOB is
num integer;
begin
--?耞琌?Τ??JOB/DTS
select nvl(count(*), 0)
into num
from (select distinct (a.job_name) v_name
from msql_job a
where to_char(a.record_date, 'YYYYMMDD') =
to_char(sysdate, 'YYYYMMDD')
and a.job_name not in (select b.v_name from factory_dts b));
if num >0 then --?狦??碞秈︽礎?
for jb in ( select distinct (a.job_name) v_name
from msql_job a
where
to_char(a.record_date, 'YYYYMMDD') = to_char(sysdate, 'YYYYMMDD')
and a.job_name not in (select b.v_name from factory_dts b)) loop
num integer;
begin
--?耞琌?Τ??JOB/DTS
select nvl(count(*), 0)
into num
from (select distinct (a.job_name) v_name
from msql_job a
where to_char(a.record_date, 'YYYYMMDD') =
to_char(sysdate, 'YYYYMMDD')
and a.job_name not in (select b.v_name from factory_dts b));
if num >0 then --?狦??碞秈︽礎?
for jb in ( select distinct (a.job_name) v_name
from msql_job a
where
to_char(a.record_date, 'YYYYMMDD') = to_char(sysdate, 'YYYYMMDD')
and a.job_name not in (select b.v_name from factory_dts b)) loop
insert into factory_dts
select HOSTIP HOST,
decode(substr(hostip, 1, 5),
'10.18',
'猀盺',
'10.86',
'??畄',
'10.89',
'瞐?',
'10.52',
'犁?') FACTORY,
'JOB' V_TYPE,
JOB_NAME V_NAME,
'' V_DEC,
'' V_MAN,
'' status,
'' code
from msql_job
where job_name = jb.v_name and rownum=1;
commit;
end loop;
select HOSTIP HOST,
decode(substr(hostip, 1, 5),
'10.18',
'猀盺',
'10.86',
'??畄',
'10.89',
'瞐?',
'10.52',
'犁?') FACTORY,
'JOB' V_TYPE,
JOB_NAME V_NAME,
'' V_DEC,
'' V_MAN,
'' status,
'' code
from msql_job
where job_name = jb.v_name and rownum=1;
commit;
end loop;
end if;
exception -- 缽盽矪瞶
when others then
null;
exception -- 缽盽矪瞶
when others then
null;
end SendWFL_SQL_ADDJOB;
b,失敗監控
b,失敗監控
create or replace procedure SendWFL_SQLSERVER is
begin
for v in (select wfl.seq_wfs_tb_fcsmail.nextval@lk_wfl_wasa1,
'DBMS' a2,
'DBMS資料庫系統監控@163.com' a3,
v_mail a4,
'系統來信?' || factory || 'SQLServer_JOB執行失敗:' ||
hostip || ',JOB名稱:' || job_name || '' a5,
'' || factory || 'SQLServer_JOB執行失敗,主機:' || hostip ||
',JOB名稱' || job_name || '' a6
from (select a.hostname,
b.factory,
a.hostip,
a.job_name,
a.last_run_status,
decode(v_mail, '', 'Darcy_Q.L._He/ZDT@ZDT', v_mail) as v_mail,
substr(a.last_run_date, 1, 4) || '/' ||
substr(a.last_run_date, 5, 2) || '/' ||
substr(a.last_run_date, 7, 2) || ' ' ||
substr(lpad(a.last_run_time, 6, '0'), 1, 2) || ':' ||
substr(lpad(a.last_run_time, 6, '0'), 3, 2) AS last_run_time
from msql_job a,
FACTORY_DTS b,
wfl.wfs_tb_auth@lk_ws c
where record_date between
(select sysdate - 1 / 4 from dual) and sysdate
/*and c.v_type = 'ALL'*/
and a.hostip = b.host
and decode(trim(b.v_man),
'',
decode(substr(a.hostip, 1, 5),
'10.18',
'廠區一?',
'10.86',
'廠區二,
'10.89',
'廠區三',
'10.52',
廠區三?',
'總部'),
trim(b.v_man)) = c.v_name
and c.v_isdel = '0'
AND trim(a.job_name) = b.v_name
and b.v_type = 'JOB'
and last_run_status = '作業失敗) a) loop
insert into wfl.wfs_tb_fcsmail@lk_wfl_40
(n_id, v_sysid, v_from, v_to, v_subject, v_body)
values
(v.a1, v.a2, v.a3, v.a4, v.a5, v.a6);
commit;
end loop;
exception -- 執行失敗
begin
for v in (select wfl.seq_wfs_tb_fcsmail.nextval@lk_wfl_wasa1,
'DBMS' a2,
'DBMS資料庫系統監控@163.com' a3,
v_mail a4,
'系統來信?' || factory || 'SQLServer_JOB執行失敗:' ||
hostip || ',JOB名稱:' || job_name || '' a5,
'' || factory || 'SQLServer_JOB執行失敗,主機:' || hostip ||
',JOB名稱' || job_name || '' a6
from (select a.hostname,
b.factory,
a.hostip,
a.job_name,
a.last_run_status,
decode(v_mail, '', 'Darcy_Q.L._He/ZDT@ZDT', v_mail) as v_mail,
substr(a.last_run_date, 1, 4) || '/' ||
substr(a.last_run_date, 5, 2) || '/' ||
substr(a.last_run_date, 7, 2) || ' ' ||
substr(lpad(a.last_run_time, 6, '0'), 1, 2) || ':' ||
substr(lpad(a.last_run_time, 6, '0'), 3, 2) AS last_run_time
from msql_job a,
FACTORY_DTS b,
wfl.wfs_tb_auth@lk_ws c
where record_date between
(select sysdate - 1 / 4 from dual) and sysdate
/*and c.v_type = 'ALL'*/
and a.hostip = b.host
and decode(trim(b.v_man),
'',
decode(substr(a.hostip, 1, 5),
'10.18',
'廠區一?',
'10.86',
'廠區二,
'10.89',
'廠區三',
'10.52',
廠區三?',
'總部'),
trim(b.v_man)) = c.v_name
and c.v_isdel = '0'
AND trim(a.job_name) = b.v_name
and b.v_type = 'JOB'
and last_run_status = '作業失敗) a) loop
insert into wfl.wfs_tb_fcsmail@lk_wfl_40
(n_id, v_sysid, v_from, v_to, v_subject, v_body)
values
(v.a1, v.a2, v.a3, v.a4, v.a5, v.a6);
commit;
end loop;
exception -- 執行失敗
when others then
null;
end SendWFL_SQLSERVER;
null;
end SendWFL_SQLSERVER;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15187685/viewspace-755897/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- LoadRunner監控SQLServerSQLServer
- SQLserver 監控資料檔案SQLServer
- SQLServer如何監控阻塞會話SQLServer會話
- 監控server磁碟使用率的jobServer
- MYSQL和SQLServer效能監控指標MySqlServer指標
- oracle監控表空間,JOB,rman備份Oracle
- Zabbix監控 MS SqlServer2019SQLServer
- html格式郵件監控failures大於0的jobHTMLAI
- sqlserver資料庫系統效能監控步驟SQLServer資料庫
- 幾款SQLSERVER資料庫監控軟體介紹SQLServer資料庫
- SQLServer統計監控SQL執行計劃突變的方法SQLServer
- sqlserver監控指令碼_發現某個等待就發出郵件SQLServer指令碼
- 黑盒監控、日誌監控
- 6.prometheus監控--監控dockerPrometheusDocker
- TiDB監控實現--存活監控TiDB
- 聊聊前端監控——錯誤監控篇前端
- nagios監控例項 -- PostgreSQL監控iOSSQL
- APM效能監控軟體的監控型別服務及監控流程型別
- 【SQL監控】SQL完全監控的指令碼SQL指令碼
- 伺服器監控之 ping 監控伺服器
- 3-主機監控、應用監控
- Redis監控Redis
- 批量監控
- index 監控Index
- nginx監控Nginx
- centos 監控CentOS
- zabbix監控
- 夜鶯監控
- mysql 的一個監控指令碼,監控heartbeatMySql指令碼
- Sqlserver重啟alwayson監聽埠SQLServer
- Prometheus+Grafana實現服務效能監控:windows主機監控、Spring Boot監控、Spring Cloud Alibaba Seata監控PrometheusGrafanaWindowsSpring BootCloud
- 一種對雲主機進行效能監控的監控系統及其監控方法
- 前端資料監控到底在監控什麼?前端
- Hystrix 監控視覺化頁面——Dashboard 流監控視覺化
- MySQL監控-Datadog資料庫監控調研MySql資料庫
- 監控寶SQL Server效能監控的功能和配置SQLServer
- nagios的配置(監控端和被監控端)iOS
- mysql mon 的一個監控指令碼,監控heartbeatMySql指令碼