mysql 错误日志和监控日志分离_Oracle监控系统错误日志过程

news/2024/7/7 13:22:56 标签: mysql 错误日志和监控日志分离

--创建临时表用来存放系统错误信息create table superflow(cust_id number(10),cust_name varchar2(100),d varchar(50),error_in

--创建临时表用来存放系统错误信息

create table superflow(cust_id number(10),cust_name varchar2(100),d varchar(50),error_info varchar2(500),client_ip varchar2(50),protocol varchar2(100),t number(20),sj date) tablespace db_data;

--drop table superflow

--创建数据写入路径

create directory db_dir as '/home/Oracle';

--把目录授权给用户

grant read,write on directory db_dir to db;

监控系统错误日志

过程完成任务有

把抽取出来错误日志插入到superflow

错误日志会写入操作系统/home/oracle/sql.txt文件下面

create or replace procedure pro_superflow as

pro_name VARCHAR2(50);

err_info VARCHAR2(1000);

v_Sql VARCHAR2(1000);

sj VARCHAR2(20);

JL NUMBER(10);

--cursor record_t_sms_customer_errlog is select c.cust_id "客户ID",cu.cust_name "客户名称",c.d "状态",c.error_info "错误信息",c.client_ip "客户IP",c.protocol "协议",c.t "记录数" from (select CUST_ID,case ACTION when '1' then '登入' else '下行' end d,ERROR_INFO,CLIENT_IP,PROTOCOL,COUNT(ERRLOG_ID) t from t_sms_customer_errlog where create_time > sysdate - interval '1' hour and err_code=8 group by cust_id, action, ERROR_INFO,client_ip, protocol) c,t_sms_customer cu where c.cust_id=cu.cust_id and t>5;

cursor record_t_sms_customer_errlog is select c.cust_id "客户ID",cu.cust_name "客户名称",c.d "状态",c.error_info "错误信息",c.client_ip "客户IP",c.protocol "协议",c.t "记录数" from (select CUST_ID,case ACTION when '1' then '登入' else '下行' end d,ERROR_INFO,CLIENT_IP,PROTOCOL,COUNT(ERRLOG_ID) t from t_sms_customer_errlog where err_code=8 group by cust_id, action, ERROR_INFO,client_ip, protocol) c,t_sms_customer cu where c.cust_id=cu.cust_id;

--all_record t_sms_customer_errlog%rowtype;

type table_type is record( cust_id_1 number(10),cust_name_1 varchar2(100),d varchar2(20),error_info_1 varchar2(1000),client_ip_1 varchar2(50),protocol_1 varchar2(1000),t_1 number(10));

all_record table_type;

vsfile UTL_FILE.file_type;

begin

SELECT COUNT(1)INTO JL FROM superflow;

IF JL >10000 THEN

delete FROM SUPERFLOW where sj < sysdate - interval '7' day;

END IF;

vsfile :=

UTL_FILE.fopen ('DB_DIR', --->使用fopen打开文件,定义了文件路径,文件名,读写方式以及每一行字符的最大长度,缺省为1024

'sql.txt',

'W');

for all_record in record_t_sms_customer_errlog

loop

insert into superflow values(all_record.客户id,all_record.客户名称,all_record.状态,all_record.错误信息,all_record.客户ip,all_record.协议,all_record.记录数,sysdate);

commit;

UTL_FILE.put_line (vsfile, all_record.客户id);

UTL_FILE.put_line (vsfile, all_record.客户名称);

UTL_FILE.put_line (vsfile, all_record.状态);

UTL_FILE.put_line (vsfile, all_record.错误信息);

UTL_FILE.put_line (vsfile, all_record.客户ip);

--UTL_FILE.put_line (vsfile, all_record.协议)

UTL_FILE.put_line (vsfile, all_record.记录数);

UTL_FILE.put_line (vsfile, sysdate);

-- 把输入内容写入文件

end loop;

UTL_FILE.fflush (vsfile);

UTL_FILE.fclose (vsfile);

exception

when others then

--sg_log_err('manage_partition',sqlerrm);

pro_name :='manage_partition';

err_info :=sqlerrm;

select sysdate into sj from dual;

v_Sql := 'insert into err_log values('||'''PRO_SUPERFLOW'''||','''||err_info||''','''||sj||''')';

execute immediate v_Sql;

commit;

dbms_output.put_line(sqlcode||sqlerrm);

end pro_superflow;

把错误日志以邮件形式发出去

echo '监控日志'|mail -s '系统日志' [email protected]

本文永久更新链接地址:,

f68f2add0b68e4f9810432fce46917b7.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!


http://www.niftyadmin.cn/n/629169.html

相关文章

html基础知识选择题,HTML笔试题目(附答案)HTML基础知识笔试题目(附答案).pdf

1、{HTML 题目 } 在 HTML页面中制作一个图像&#xff0c;想要在鼠标指向这个图像时浮出一条提示信息&#xff0c;应该使用的参数是 :( C ) ( 选择 1 项 )A) POP B) SRC C) ALT D) MSG2、{HTML题目 } 在页面中看不见的表单元素是那种&#xff1f; ( C ) (选择 1 项)A) B )C) D )…

华为首款鸿蒙平板发布,华为MatePad Pro发布!首款鸿蒙平板强势来袭

可以说&#xff0c;华为MatePad Pro的出现&#xff0c;让我一个平时并不常用平板电脑的人&#xff0c;再次重拾了对于平板电脑的兴趣。根据媒体发布的信息&#xff0c;新一代华为MatePad Pro或将是华为平板电脑业务升级的重要转折点&#xff0c;就在6月2日晚&#xff0c;华为召…

php和python哪个更简单_新手做一个简单的脚本工具开发PHP和python哪个比较好?

谢邀。题主说自己C语言可以&#xff0c;说明有编程基础&#xff0c;那么其实很容易了&#xff0c;无非是哪门语言简单然后用熟悉的工具来处理问题罢了。说到Python和PHP&#xff0c;PHP 是一种创建动态交互性站点的强有力的服务器端脚本语言&#xff0c;一般用来做网站的服务器…

记一次处理Apache无法启动的问题

一、问题现象使用/usr/local/apache/bin/apachectl start启动&#xff0c;apache服务无响应。 二、问题分析排查1.使用 ps -ef | grep http 查看进程&#xff0c;并kill掉&#xff0c;反复多次也没有解决2.查看apache的pid文件&#xff0c;并手动删除&#xff0c;也无法解决服务…

关闭html默认打开,有关文件打开默认方式如何恢复的问题

大家好&#xff0c;我问一个很多人都在烦恼的问题。Vista系统中&#xff0c;当一个未关联任何应用程序的文件类型&#xff0c;被误操作与某一应用程序关联后&#xff0c;如何才能将默认打开方式恢复到初始状态。例如&#xff1a; 将 .dll的打开方式误设为记事本&#xff0c;那么…

Gentoo更新portage记录

小记一下这两天更新服务器版本遇到的各种问题。 服务器系统&#xff1a; Gentoo 第一天 其实本来不打算更新系统的&#xff0c;因为最近想试试免费的SSL证书&#xff0c;于是自然而然搜到了letsencrypt&#xff0c;跟着他们的流程需要安装 $ sudo emerge -av app-crypt/certbot…

贵州省2021普通高考成绩什么查询,贵州2021高考成绩排名查询,贵州高考个人成绩排名如何查询...

一、贵州高考个人成绩排名如何查询2020年贵州高考成绩排名查询方法有两种&#xff0c;第一种可以通过贵州省招生考试院公布的高考成绩单上面的全省排名查询、第二种是根据2020年贵州省招生考试院公布的一分一段表来查询排名和位次。二、贵州高考成绩排名位次如何使用1.什么是贵…

jdbc连接mysql数据库增删_Java之简单的jdbc连接MySQL数据库实现增删改查

/*** 1.加载mysql驱动&#xff1a;com.mysql.jdbc.Driver* 2.获取连接:与数据库建立连接* 3.sql预编译对象:预编译对象* 4.执行sql语句* 5.释放资源* author 郑清*/public class JDBC_CRUD_Demo {public static void main(String[] args) {testCreateDatabase();//创建数据库ad…