【MySQL】关于MySQL错误日志信息的收集
为方便维护MySQL,写了个脚本用以提供收集错误信息的接口。这些错误信息来自与MySQL错误日志,而 通过grep mysql可以获取error-log的路径。
#!/usr/bin/env python2.7
#-*- encoding: utf-8 -*- """
该模块用于提取每天mysql日志中的异常或错误信息
author: xiaomo
email: moxiaomomo@gmail.com
""" import os
import sys
import string
from datetime import * # 預設字符解碼器為utf-8
reload(sys)
sys.setdefaultencoding('utf-8') COMMON_FLAGS = ["error", "exception", "fail", "crash", "repair"] def _contain_flag(cur_str):
for flag in COMMON_FLAGS:
if flag in string.lower(cur_str):
return True
return False """
获取当前mysql实例的error_log文件路径
"""
def _get_mysql_error_log_path():
log_path = ''
grep_infos = os.popen('ps aux | grep mysql | grep "log-error"').read()
if len(grep_infos) > 1:
grep_infos = grep_infos.split("log-error=")
if len(grep_infos) > 1:
grep_infos = grep_infos[1].split(' ')
if len(grep_infos) > 1:
log_path = grep_infos[0]
return log_path """
读取mysql错误日志中包含异常或错误信息的行
"""
def _get_error_info(error_log, begin_date):
error_infos = []
f = open(error_log, 'r')
lines = f.readlines()
for line in lines:
data_array = line.split(' ')
if len(data_array) > 0 and len(data_array[0]) == 10:
dt_strs = data_array[0].split('-')
cur_date = date(int(dt_strs[0]), int(dt_strs[1]), int(dt_strs[2]))
if cur_date >= begin_date and _contain_flag(line):
error_infos.append(line)
f.close()
return error_infos """
组装并返回mysql错误日志信息
"""
def get_mysql_errors(begin_date=date.today()-timedelta(1)):
try:
err_log_path = _get_mysql_error_log_path()
if len(err_log_path) > 1:
return _get_error_info(err_log_path, begin_date)
except Exception,e:
print "[get_mysql_errors]%s"%e
return []
收集到的信息可以发邮件通知相关人员,也可以放到网站中方便浏览,这样在一定程度上减少了错误跟踪的时间。
【MySQL】关于MySQL错误日志信息的收集的更多相关文章
- ASP.NET MVC中错误日志信息记录
MVC中有一个处理异常的过滤器 HandleErrorAttribute 1.新建一个类继承自 HandleErrorAttribute,然后重写OnException这个方法 public clas ...
- 【转】ASP.NET MVC中错误日志信息记录
MVC中有一个处理异常的过滤器 HandleErrorAttribute 1.新建一个类继承自 HandleErrorAttribute,然后重写OnException这个方法 public clas ...
- C#添加错误日志信息
错误日志是软件用来记录运行时出错信息的文本文件.编程人员和维护人员等可以利用错误日志对系统进行调试和维护. 系统日志 系统日志包含了由Windows系统组件记录的事件.例如,在启动期间装入驱动程序或其 ...
- 如何打印完整的MYSQL带参数SQL日志信息
在mysql的jdbc中开启sql分析,如下: jdbc.url=jdbc:mysql://127.0.0.1/test?useUnicode=true&characterEncoding=U ...
- MySQL提供的错误日志中的错误级别一共有3个分别为:
ERROR_LEVEL-->错误级别 WARNING_LEVEL-->警告级别 INFORMATION_LEVEL-->信息级别
- log4j+AOP 记录错误日志信息到文件中
AOP 采用异常通知切入,把指定包的异常记录到日志文件. 先看log4j.properties ,控制台输出的是普通信息, 文件输出的是异常信息. log4j.rootLogger=DEBUG, Co ...
- Java保存错误日志信息
我们平时在撸代码的时候,有时候需要将某个代码块的具体错误信息保存到数据库或文件中,以便日后方便快速的查找问题. 使用e.printStackTrace(),我们可以将信息保存在具体的变量中,然后写入数 ...
- mysql错误日志路径
造成该问题的原因有很多,单纯的百度google这个问题,很难找到正确的解决办法,要对症下药测才能解决:1.查看具体错误信息: 按:计算机管理——>系统工具——>事件查看器——>Wi ...
- mysql 开发进阶篇系列 38 mysql日志之错误日志log-error
一.mysql日志概述 在mysql中,有4种不同的日志,分别是错误日志,二进制日志(binlog日志),查询日志,慢查询日志.这此日志记录着数据库在不同方面的踪迹(区别sql server里只有er ...
随机推荐
- HDU 5144 NPY and shot(三分法)
当时做这道题时一直想退出物理公式来,但是后来推到导数那一部分,由于数学不好,没有推出来那个关于Θ的最值,后来直接暴力了,很明显超时了,忘了三分法的应用,这道题又是典型的三分求最值,是个单峰曲线,下面是 ...
- jdbc连接数据库和jdbc-odbc桥接方式连接数据库
//这种方式为jdbc直接连接,需要添加jar文件 1 package com.howe2; import java.sql.*; public class test2 { public static ...
- 03-StreamReader和StreamWriter的案例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- POJ3750
#include <iostream> #include <stdio.h> #include <cstring> using namespace std; int ...
- Shell中的数值计算
#!/bin/bash echo "please input number:" read n a=`expr $n / 100` #a1=`expr $n - $a * 100` ...
- 限制窗口拉伸范围(二)——OnSizing
之前用的GetMinMaxInfo,在VS2015中会导致:Report模式的CListCtrl随窗口拉伸时,表头无法绘制超过原大小的区域.其他版本和控件未测试,而OnSizing没有这问题. 前一方 ...
- 异步socket大并发实现
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.So ...
- yum 安装 kvm
KVM是什么? for Kernel-based Virtual Machine 安装环境Centos 6.5 mini x64 禁用selinux, 禁用防火墙 安装过程: 1. 查看我们的电脑是 ...
- linux学习第一天(X window 及 语系查询设置)
前言: 在写这篇博文之前,我已经详细阅读了<鸟哥的Linux私房菜>,但是实践并不深入,只是单纯的为了了解常用的命令,扩展自己的知识广度.看过一遍感觉收获还是有的,但是并不是很精通.因此, ...
- @NotNull丶@NotBlank丶@NotEmpty
1.@NotNull:不能为 Null,但是可以为Empty:用在基本数据类型上. @NotNull(message="{state.notnull.valid}", groups ...