【问题标题】:piwik log import invalid log linespiwik 日志导入无效的日志行
【发布时间】:2012-11-30 17:00:38
【问题描述】:

我是 piwik 的新手,正在尝试导入一堆日志。我需要有关日志格式正则表达式的帮助。日志中的示例行是:

"1.1.1.1" 2.2.2.2 - myuser [09/Dec/2012:04:03:29 -0500] "GET /signon.html HTTP/1.1" 304 "http://www.example.com/示例" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"

我的日志格式正则表达式如下所示:

--log-format-regex='\\\\"(?P<ip>\\\\S+)\\\\" \\\\S+ \\\\S+ \\\\S+ \\\\[(?P<date>.*?) (?P<timezone>.*?)\\\\] \\\\"\\\\S+ (?P<path>.*?) \\\\S+\\\\" (?P<status>\\\\S+) (?P<length>\\\\S+) \\\\"(?P<referrer>.*?)\\\\" \\\\"(?P<user_agent>.*?)\\\\"'

我一直收到所有“忽略的请求”和“无效的日志行”。例如:

日志导入摘要

0 requests imported successfully
0 requests were downloads
236252 requests ignored:
    236252 invalid log lines
    0 requests done by bots, search engines, ...
    0 HTTP errors
    0 HTTP redirects
    0 requests to static resources (css, js, ...)
    0 requests did not match any known site
    0 requests did not match any requested hostname

如何修复 log-format-regex?

tia, 丹

【问题讨论】:

    标签: analytics matomo log-analysis


    【解决方案1】:

    当使用 piwik (resp. matomo) 日志导入时,您可以发出 --debug 选项两次,这将产生无效行。

    这是一个显示它的脚本示例(但这是我的首选日志格式)

    python /opt/piwik.git/misc/log-analytics/import_logs.py \
        --debug --debug \
        --url=$piwik_site \
        --log-format-regex='(?P<host>\S+) (?P<ip>\S+) \S+ \[(?P<date>.*?) (?P<timezone>.*?)\] "\S+ (?P<path>.*?) \S+" (?P<status>\d+) (?P<length>\d+) "(?P<referrer>.*?)"$'
        --add-sites-new-hosts \
        --enable-http-errors \
        --enable-http-redirects \
        --enable-static \
        --strip-query-string \
        --show-progress \
        --show-progress-delay 2 \
        --recorders $cpu \
        "$1"
    

    $1 是我从中导入的文件的名称(我的 Apache、Nginx 和 Lighttpd boxen 都使用相同的格式)。

    输出将有几行如下所示:

    2013-09-03 19:42:34,145: [DEBUG] Invalid line detected (line did not match): edoceo.com 10.0.0.1 - [03/Sep/2013:16:41:03 -0700] "GET / HTTP/1.1" 301 - "-" "Some Bad Robot v0.1"
    

    这些会告诉您什么是无效的,并提供有关如何调整/调整您的正则表达式的线索。

    我在http://edoceo.com/howto/piwik#import获得了一些设置的详细信息

    【讨论】:

      猜你喜欢
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      • 2015-02-25
      • 2011-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多