常见日志格式 (Apache) 日志分析程序 您所在的位置:网站首页 apache日志格式 常见日志格式 (Apache) 日志分析程序

常见日志格式 (Apache) 日志分析程序

2023-03-09 06:15| 来源: 网络整理| 查看: 265

您可以为 FileLog 和 WinLog 收集器配置常见日志格式 (CLF) Apache 分析程序。

常见日志格式 (Apache) 分析程序

默认 CLF 分析程序会定义字段的以下顺序和名称。

host ident authuser datetime request statuscode bytes

分析程序名称:clf

CLF 分析程序特定的选项是 format。

format 选项

format 选项指定生成 Apache 日志所用的格式。该选项不是必备选项。

如果未指定格式,则会使用以下默认的常见日志格式。

%h %l %u %t \"%r\" %s %b

CLF 分析程序格式字符串不接受正则表达式。例如,指定空格而不是表达式 \s+。

要分析其他日志格式,请在代理的配置中指定该格式。服务器端会显示以下名称的已分析字段。

注: 在需要变量的情况下,如果配置中未提供 {VARNAME},则会忽略这些字段。 字段 值 '%a': "remote_ip" '%A': "local_ip" '%B', '%b': "response_size" '%C': 取决于在格式中指定的变量名称 '%c': 取决于在格式中指定的变量名称 '%D': "request_time_mcs" '%E': "error_status" '%e': 取决于在格式中指定的变量名称 '%F', '%f': "file_name" '%h': "remote_host" '%H': "request_protocol" '%i': 取决于在格式中指定的变量名称 '%k': "keepalive_request_count" '%l': "remote_log_name" '%L' "request_log_id" '%M': "log_message"(分析程序在到达此说明符后停止分析输入日志) '%m': "request_method" '%n': 取决于在格式中指定的变量名称 '%o': 取决于在格式中指定的变量名称 '%p': "server_port"

在以下说明符中可以使用一些额外的格式:%{format}p。支持的格式包括 "canonical"、"local" 或 "remote"。如果使用 "canonical" 格式,字段名称保留为 "server_port";如果使用 "local" 格式,字段名称将为 "local_server_port";如果使用 "remote" 格式,字段名称将为 "remote_server_port"。

'%P': "process_id"

在以下说明符中可以使用一些额外的格式:%{format}P。支持的格式包括 "pid"、"tid" 和 "hextid"。如果使用 "pid" 格式,字段名称将为 "process_id";而 "tid" 和 "hextid" 格式将生成名为 "thread_id" 的字段

'%q': "query_string" '%r': "request" '%R': "response_handler" '%s': "status_code",生成请求的最终状态。 '%t':

"timestamp",作为载入事件的时间戳,参与时间戳分析程序。要覆盖时间戳自动检测,可以用大括号指定日期和时间格式:%{%Y-%m-%d %H:%M:%S}t,请参见时间戳分析程序以了解更多详细信息。

CLF 分析程序的时间戳格式可以采用 "begin:" 或 "end:" 前缀开头。如果格式以 begin: 开头(默认),则该时间为请求处理开始时所用的时间。如果格式以 end: 开头,则该时间为写入日志条目的时间,此时请求处理临近结束。例如,CLF 分析程序支持如下格式:%h %l %u [%{begin:%d/%b/%Y %T}t.%{msec_frac}t] \"%r\" %>s %b

CLF 分析程序的时间戳格式说明符还支持以下格式标记: sec 自新纪元时间以来的秒数。这等同于时间戳分析程序的 %s 说明符。 msec 自新纪元时间以来的毫秒数 usec 自新纪元时间以来的微秒数 msec_frac 毫秒分数(等同于时间戳分析程序的 %f 说明符) musec 微秒分数(等同于时间戳分析程序的 %f 说明符) 要分析其时间戳以格式标记显示的日志,可以在配置中使用以下格式: format=%h %l %u %{sec}t \"%r\" %s %b format=%h %l %u %{msec}t \"%r\" %s %b format=%h %l %u %{usec}t \"%r\" %s %b

这些标记不能彼此组合使用,也不能与采用相同格式字符串的时间戳分析程序格式组合使用。您可以改用多个 %{format}t 标记。例如,要使用包含毫秒的时间戳,可以使用以下组合的时间戳(时间戳分析程序的 %f 说明符除外): %{%d/%b/%Y %T}t.%{msec_frac}t 。

'%T': "request_time_sec" '%u': "remote_auth_user" '%U': "requested_url" '%v': "server_name" '%V': "self_referential_server_name" '%X': "connection_status",取决于在格式中指定的变量名称 '%x': 取决于在格式中指定的变量名称 '%I': "received_bytes" '%O': "sent_bytes" '%S': "transferred_size"

例如,要用 CLF 分析程序分析从 winlog 或 filelog 源收集的日志,请指定以下配置:

[filelog|clflogs] directory=D:\Logs include=*.txt parser=myclf [parser|myclf] debug=yes ;Note: use this option only while debugging and set it to ‘no’ when used in production. base_parser=clf format=%h %l %u %b %t \"%r\" %s

使用此配置,从 clflogs 源(例如,从 directory=D:\Logs 目录)收集的日志由 myclf 分析。myclf 分析程序仅分析以配置中描述的格式生成的那些日志。

对于分析程序,调试的默认值是 debug=no。

分析使用 CLF 生成的日志

要分析使用 CLF 生成的日志,必须在配置中定义相应的格式。例如,

format=%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User_Agent}i\"

使用说明符 %{Referer}i 和 %{User_Agent}i 的非空字段将分别以名称 referer 和 user_agent 显示在 vRealize Log Insight 服务器上。

将时间戳分析程序与 CLF 分析程序集成

可以分析具有自定义时间格式的 Apache 日志。

访问具有如下所示的自定义时间格式的日志。

format = %h %l %u %{%a, %d %b %Y %H:%M:%S}t \"%r\" %>s %b

如果未指定自定义时间,则 CLF 分析程序将尝试通过运行自动时间戳分析程序来自动推断时间格式,否则将使用自定义时间格式。

错误日志所支持的自定义时间格式如下:

自定义时间格式 描述 配置格式 %{u}t 包括微秒的当前时间 format=[%{u}t] [%l] [pid %P] [client %a] %M %{cu}t 采用精简 ISO 8601 格式的当前时间,包括微秒 format=[%{cu}t] [%l] [pid %P] [client %a] %M

有关支持的时间戳说明符的完整列表,请参见时间戳分析程序。

用于 Windows 的 Apache 默认访问日志配置

此示例说明如何为用于 Windows 的 Apache v2.4 访问日志配置设置格式。

;ACCESS LOG ;127.0.0.1 - - [13/May/2015:14:44:05 +0400] "GET /xampp/navi.php HTTP/1.1" 200 4023 "http://localhost/xampp/" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0" ;format=%h %l %u %{%d/%b/%Y:%H:%M:%S %z}t \"%r\" %>s %b \"%{Referer}i\" \"%{User_agent}i\" ; Section to collect Apache ACCESS logs [filelog|clflogs-access] directory=C:\xampp\apache\logs include=acc* parser=clfparser_apache_access enabled=yes ;Parser to parse Apache ACCESS logs [parser|clfparser_apache_access] debug=yes base_parser=clf format=%h %l %u %{%d/%b/%Y:%H:%M:%S %z}t \"%r\" %>s %b \"%{Referer}i\" \"%{User_agent}i\" 定义访问日志格式: 为访问日志格式 (httpd.conf) 配置 Apache: LogFormat "%h %l %u %{%d-%b-%Y:%H:%M:%S}t \"%r\" %a %A %e %k %l %L %m %n %T %v %V %>s %b \"%{Referer}i\" \"%{User_Agent}i\"" combined 定义 CLF 分析程序配置: ;ACCESS LOG ;127.0.0.1 unknown - 21-May-2015:13:59:35 "GET /xampp/navi.php HTTP/1.1" 127.0.0.1 127.0.0.1 - 0 unknown - GET - 1 localhost localhost 200 4023 "http://localhost/xampp/" "-" [filelog|clflogs-access] directory=C:\xampp\apache\logs include=acc*;_myAcc* parser=clfparser_apache_access enabled=yes ; Parser to parse Apache ACCESS logs [parser|clfparser_apache_access] debug=yes base_parser=clf format=%h %l %u %{%d-%b-%Y:%H:%M:%S}t \"%r\" %a %A %e %k %l %L %m %n %T %v %V %>s %b \"%{Referer}i\" \"%{User_Agent}i\" CLF 分析程序返回以下结果: remote_host=127.0.0.1 timestamp=2015-05-13T10:44:05 request=GET /xampp/navi.php HTTP/1.1 status_code=200 response_size=4023 referer=http://localhost/xampp/ user_agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0

此示例说明如何为用于 Windows 的 Apache v2.4 错误日志配置设置格式。

;ERROR LOG ;[Wed May 13 14:37:17.042371 2015] [mpm_winnt:notice] [pid 4488:tid 272] AH00354: Child: Starting 150 worker threads. ;[Wed May 13 14:37:27.042371 2015] [mpm_winnt:notice] [pid 5288] AH00418: Parent: Created child process 3480 ;format=[%{%a %b %d %H:%M:%S%f %Y}t] [%m:%{severity}i] [pid %P:tid %{thread_id}i] %E: %M ;format=[%{%a %b %d %H:%M:%S%f %Y}t] [%m:%{severity}i] [pid %P] %E: %M ; Section to collect Apache ERROR logs [filelog|clflogs-error] directory=C:\xampp\apache\logs include=err* parser=clfparser_apache_error enabled=yes ;Parser to parse Apache ERROR logs [parser|clfparser_apache_error] debug=yes base_parser=clf format=[%{%a %b %d %H:%M:%S%f %Y}t] [%m:%{severity}i] [pid %P:tid %{thread_id}i] %E: %M next_parser=clfparser_apache_error2 ;Parser to parse Apache ERROR logs [parser|clfparser_apache_error2] debug=yes base_parser=clf format=[%{%a %b %d %H:%M:%S%f %Y}t] [%m:%{severity}i] [pid %P] %E: %M 注: 提供的名称与组合日志格式相对应。另外还介绍了使用上述格式设置键(而不是 Apache 错误日志格式)的 Apache 错误日志。 定义错误日志格式: 为错误日志格式 (httpd.conf) 配置 Apache: LogFormat "%h %l %u %{%d-%b-%Y:%H:%M:%S}t \"%r\" %a %A %e %k %l %L %m %n %T %v %V %>s %b \"%{Referer}i\" \"%{User_Agent}i\"" combined 定义 CLF 分析程序配置: ;Parser to parse Apache ERROR logs [parser|clfparser_apache_error] debug=yes base_parser=clf format=[%{%a %b %d %H:%M:%S%f %Y}t] [%m:%{severity}i] [pid %P] %E: %M next_parser=clfparser_apache_error2 ;Parser to parse Apache ERROR logs [parser|clfparser_apache_error2] debug=yes base_parser=clf format=[%{%a %b %d %H:%M:%S%f %Y}t] [%m:%{severity}i] [pid %P:tid %{thread_id}i] %E: %M

日志条目:

[Wed May 13 14:37:17.042371 2015] [mpm_winnt:notice] [pid 4488:tid 272] AH00354: Child: Starting 150 worker threads. CLF 分析程序针对日志条目返回以下字段(如果使用 +0400 时区的分析程序): timestamp=2015-05-13T10:37:17.042371 request_method=mpm_winnt severity=notice process_id=4488 thread_id=272 error_status=AH00354 log_message=Child: Starting 150 worker threads.

日志条目:

[Wed May 13 14:37:27.042371 2015] [mpm_winnt:notice] [pid 5288] AH00418: Parent: Created child process 3480 CLF 分析程序针对日志条目返回以下字段(如果使用 +0400 时区的分析程序): timestamp=2015-05-13T10:37:27.042371 request_method=mpm_winnt severity=notice process_id=5288 error_status=AH00418 log_message=Parent: Created child process 3480


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有