zoukankan      html  css  js  c++  java
  • ProxySQL Query Logging

    Query Logging

    ProxySQL能够记录完整的查询日志,是通过查询规则来配置,粒度可大可小。

    Setup

    首先,全局启用logging

    SET mysql-eventslog_filename='queries.log'; 

    变量需要load到runtime,最后save到磁盘

    LOAD MYSQL VARIABLES TO RUNTIME;
    SAVE MYSQL VARIABLES TO DISK;

     接下来,创建查询路由规则。如果你需要记录所有的查询,简单配置一下即可:

    1 INSERT INTO mysql_query_rules (rule_id, active, match_digest, log,apply) VALUES (1,1,'.',1,0);
    View Code

    如果你想记录某个人的所有查询记录,如‘Bob’:

    1 INSERT INTO mysql_query_rules (rule_id, active, username, match_pattern, log,apply) VALUES (1, 1, 'Bob', '.', 1, 0);
    View Code

    现在,加载到runtime并持久化到磁盘即可:

    1 LOAD MYSQL QUERY RULES TO RUNTIME;
    2 SAVE MYSQL QUERY RULES TO DISK;
    View Code

    Reading Logged Queries

    查询日志以二进制的形式记录,源码中有一个app能将二进制转换成普通平面文件

    1 $ ./tools/eventslog_reader_sample /var/lib/proxysql/file1.log.00001258
    2 ProxySQL LOG QUERY: thread_id="2" username="root" schemaname=information_schema" client="127.0.0.1:58307" HID=0 server="127.0.0.1:3306" starttime="2016-10-23 12:34:37.132509" endtime="2016-10-23 12:34:38.347527" duration=1215018us digest="0xC5C3C490CA0825C1"
    3 select sleep(1)
    4 ProxySQL LOG QUERY: thread_id="2" username="root" schemaname=information_schema" client="127.0.0.1:58307" HID=0 server="127.0.0.1:3306" starttime="2016-10-23 12:41:38.604244" endtime="2016-10-23 12:41:38.813587" duration=209343us digest="0xE9D6D71A620B328F"
    5 SELECT DATABASE()
    6 ProxySQL LOG QUERY: thread_id="2" username="root" schemaname=test" client="127.0.0.1:58307" HID=0 server="127.0.0.1:3306" starttime="2016-10-23 12:42:38.511849" endtime="2016-10-23 12:42:38.712609" duration=200760us digest="0x524DB8D7A9B4C132"
    7 select aaaaaaa
    View Code

    https://github.com/sysown/proxysql/tree/v1.4.4/tools

    安装部署app:

    • 克隆repo或者download源码安装
    • cd到tools目录
    • 执行make

    Related Issues and Feature Requests

    下面是一些相关功能的讨论

    Issue #561  -- 记录所有查询

    Feature Request #871  -- 针对Splunk/ElasticStack应用保存为json格式的日志

    Feature Request #1184  -- 记录到数据库

    参考文档

  • 相关阅读:
    Gmail总是把MS发来的信作为垃圾邮件
    添加了CSpreadSheet.h后出现LNK2005错误
    弃用Eudora
    卸载Intel C++ Compiler后Visual C++ 6.0不能工作了
    Matlab对多CPU系统的支持
    Borland决定出售Delphi、JBuilder、C++Builder等IDE产品
    微软提供的免费软件
    生命在于运动?
    "Cannot modify header information"的解决方法
    慢慢的,我们长成了受困于数字的大人
  • 原文地址:https://www.cnblogs.com/geek-ace/p/9567366.html
Copyright © 2011-2022 走看看