跳转到主要内容

用于对HTTP访问日志执行响应时间分析的命令行工具

项目描述

简介

该项目向您的系统添加了一个新的实用命令: tinylogan。此实用程序仅与启用响应时间数据的Apache-like访问HTTP日志一起使用。

有关如何做到这一点,请参阅 这篇博客文章,或者简要地更改日志格式的配置,从类似以下内容

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

改为以下内容

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T/%D" combined

日志记录将变为类似以下内容

[31/Jan/2008:14:19:07 +0000] "GET / HTTP/1.1" 200 7918 ""
... "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20061201 Firefox/2.0.0.11 (Ubuntu-feisty)" 0/95491

秒和微秒

该实用程序只关注微秒(%D),因此您需要拥有 Apache 2

如何使用

这里完整的帮助信息

Usage: tinylogan [options] logfile

Simple bash utility for analyze HTTP access log with enabled response time

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -v, --verbose         verbose output during log analysis
  -s SIZE, --size=SIZE  choose the number of record to store in every log
  -q, --keep-query      keep query strings in URLs instead of cutting them.
                        Using this an URL with different query string is treat
                        like different URLs.
  -i INCLUDE_REGEX, --include=INCLUDE_REGEX
                        a regexp expression that an URLs must match of will be
                        discarded. Can be called multiple times, expanding the
                        set
  -e EXCLUDE_REGEX, --exclude=EXCLUDE_REGEX
                        a regexp expression that an URLs must not match of
                        will be discarded. Can be called multiple times,
                        reducing the set
  --skip-day=SKIP_DAY   A regexp that repr specific whole day or a set of
                        dates that must be ignored. Can be called multiple
                        times
  --min-time=MIN_TIME_MILLIS
                        ignore all entries that require less than this amount
                        of millisecs
  --max-time=MAX_TIME_MILLIS
                        ignore all entries that require more than this amount
                        of millisecs
  --min-times=MIN_TIMES
                        set a minimum number of times that a entry must be
                        found to be used in the "Top average time" statistic

  Date filters:
    For those kind of filters you need to specify a date. You are free to
    use a specific date in the format dd/mmm/aaaa, like "24/May/2011", but
    also some keywords for relative date like "today", "yesterday",
    "tomorrow", "week" and "month". Use of "week" and "month" mean
    referring to first day of the current week or month. You can also
    provide a numerical modifier using "+" or "-" followed by a day
    quantity (example: "week-5" for going back of 5 days from the start of
    the week).

    --start-date=START_DATE
                        date where to start analyze and record
    --end-date=END_DATE
                        date where to end analyze and record

  Time filters:
    When a time is needed, you must enter it in the format hh:mm:ss or
    simply hh:mm, like "09:21:30" or "09:21". Those filter are used for
    skip record that are registered "too late at night" or "too early in
    the morning".

    --skip-timeperiod-start=SKIP_TIME_START
                        do not analyse records before the given time
    --skip-timeperiod-end=SKIP_TIME_END
                        do not analyse records later the given time

  Default configuration profiles:
    You can read a set of default configuration options from a
    ".tinylogan" file placed in the user's home directory. If this file is
    found, parameters from the "DEFAULT" section are read, but you can
    also add other sections. You can always override those options from
    the command line.

    -c PROFILE          read a different profile section than DEFAULT
    -U                  Ignore the user default profile file (if exists)
    --example-profile   Print out an example profile file, then exit. You can
                        put this output in a ".tinylogan" file in your home,
                        then customize it

您也可以在您的用户主目录中的 .tinylogan 配置文件中配置默认值。有关详细信息,请参阅上面的帮助信息。

结果

让我们解释一下给出的结果

Starting from 15/Apr/2011:08:19:06
enough... stopped by user action
Ending at 28/Apr/2011:17:00:36
Elapsed time: 0:00:04.955008
Timedelta is 13 days, 8:41:30 (but only 7 days, 9:41:30 are counted due to time bounds)

Top total time
  0001 - /url1 46591.603 (4924 times, average 9.462, 7.28% of the total)
  0002 - /url2 12660.053 (1212 times, average 10.446, 1.98% of the total)
  ...

Top average time
  0001 - /url3 32.828 (15 times, 492 total)
  0002 - /url4 30.549 (7 times, 213 total)
  ...
从 ... 开始

在日志中找到的第一个有效条目

足够... 被用户操作停止

只有在您在日志分析期间按下CTRL+C的情况下。这将停止日志扫描并立即跳转到结果

到 ... 结束

分析的最后一条条目

耗时: ...

日志分析所需的时间

时间差是 ...

日志第一条和最后一条记录的天数,这对于给用户提供从记录开始的总时间的百分比非常重要。

如果您使用上述某些时间过滤器,用于统计的值是句子中给出的值 但只计算xxx,因为受到时间限制

总时间最高的

这将按从最多消耗时间到最少的时间顺序显示,显示从分析日志中消耗最多时间的URL的层次结构。

        Total number of seconds taken
                     |                    Average time per call
Entry position       |                             |
      |              |                             |
     0001 - /url1 46591.603 (4924 times, average 9.462, 7.28% of the total)
              |               |                          |
       URL of the entry       |                          |
                              |             Percentage of the total time
                         Times called

平均时间最高的

这将按从最慢的记录到最慢的记录的顺序显示,考虑每次点击的平均时间,显示似乎最慢的URL的层次结构。

注意,您可能希望使用 --min-times 选项以获得更好的统计报告。如果不使用此选项,对非常慢的程序的一次及时调用可能会报告在这个层次结构中,即使它不会提供很好的平均数据。

让我们详细说明

     Average number of seconds taken
                    |
Entry position      |         Total time in seconds
      |             |                  |
     0001 - /url3 32.828 (15 times, 492 total)
              |              |
       URL of the entry      |
                             |
                        Times called

待办事项

  • 忽略匹配的多个出现中的最小和最大值的一种方法

  • 目前,所有记录都存储在内存中…很明显,这不是解析可能长达数GB的文件的方法

  • 识别默认视图(如:foo/other_foofoo/other_foo/index.html 相同)的一种方法

  • 目前,日志是从第一行读取的。因此,当使用 --start-date 时,达到远离第一条的记录可能非常慢

变更日志

0.4.0 (2011-10-04)

  • 在日志分析过程中发生错误时,报告错误行号

  • 修复了月份数组中的严重错误,这使得脚本从8月之后变得无用

  • 使用Python日志模块处理错误和详细程度;这稍微清理了输出

  • 如果遇到不符合日志格式的行,则记录警告

  • 添加了 weekmonth 日期过滤器

  • 为日期过滤器添加了数量修饰符

  • 修复了文档帮助

  • 添加了新的 skip-day 过滤器

  • 实现了用户默认配置文件并添加了相关选项

  • 当找到 --end-date 时,不要继续日志分析

  • --include 选项存在错误。现在使用它一次以上将包括到集合中的附加URL

0.3.0 (2011-06-23)

  • 添加了“已过时间”报告

  • 添加了 --verbose 选项

  • 添加了一种跳过记录的方法,如果它们所需的时间太少或太多

  • 处理了键盘中断(CTRL+C);第一个将简单地停止日志分析,而第二个将终止进程

  • 添加了 --min-times 选项,以控制何时将条目放入“平均时间最高”统计中

  • 更完整的文档

0.2.2 (2011-05-02)

  • 难以置信,我忘记了一个月: 五月 缺失!

0.2.1 (2011-04-29)

  • --skip-timeperiod-start-skip-timeperiod-end 的描述被颠倒了

  • 根页面(“/”)的URL被转换为空字符串

  • 撤销了自动将空格转换为 %20 用于过滤器的更改(对于必须是有效正则表达式的东西来说不是一个好主意)

0.2.0 (2011-04-28)

  • pep8 清理

  • 现在,带有尾随 / 的URL现在收集为不带 / 的URL相同

  • 现在,带有空格字符的过滤器被视为 %20

  • 添加了 -q 选项,以不再合并仅查询字符串不同的URL

0.1.0 (2011-04-27)

  • 初始版本

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码发行版

TinyLogAnalyzer-0.4.0.tar.gz (20.1 kB 查看哈希值)

上传时间 源代码

构建发行版

TinyLogAnalyzer-0.4.0-py2.6.egg (19.0 kB 查看哈希值)

上传时间 源代码

由以下支持