Logs and Monitoring for Apache Servers

转载 2011年01月11日 18:02:00

Logs and Monitoring for Apache Servers

Daniel Lopez
Excerpted from Apache Phrasebook, published by Pearson Education, Sams Publishing © 2006

Introduction to Logging in Apache

In addition to the error logging functionality described in the previous chapter, Apache provides extensive facilities for recording information about every aspect of a request. This chapter covers the most common issues found when logging requests, such as conditional logging, log rotation, resolution of IP addresses, and piped logging. It also covers a number of bundled and third-party modules and utilities for monitoring the status of your Apache server and to analyze its logs.

Default Apache Log Files

Apache provides a number of monitoring and logging facilities to track the correct operation of the server. The default Apache configuration provides two log files, placed inside the logs directory of the installation directory:

  • The access_log file (access.log in Windows) contains information about the requests that have been served by the server, such as the URL requested, the IP address of the client, and whether the request completed successfully or not.
  • The error_log file (error.log in Windows) contains information related to error conditions, as well as different events in the lifecycle of the server.

Creating Log Formats

  view plain | print | copy to clipboard | ?
1 LogFormat "%h %l %u %t /"%r/" %>s %b" common  
2 LogFormat "%h %l %u %t /"%r/" %>s %b" 
3     /"%{Referer}i/" /"%{User-agent}i/"" combined  

The LogFormat directive allows you to tell Apache which aspects of the request you want to record. You will still need additional directives to tell Apache where to log that information, but that is addressed in the next section. This example shows the configuration for the two most popular formats, the Common Log Format and the Combined Log Format. When Apache receives a request, it will substitute each one of the fields prefixed by a % with the corresponding request attribute. If you are using the CLF, each entry in your log file will look like this:

  view plain | print | copy to clipboard | ?
1 - someuser [12/Jun/2005:08:33:34  
2     +0500] "GET /example.png HTTP/1.0" 200 1234  

If you are using the combined common format, each entry in your log file will look like this:

  view plain | print | copy to clipboard | ?
1 - someuser [12/Jun/2005:08:33:34  
2     +0500] "GET /example.png HTTP/1.0" 200 1234  
3     http://www.example.com/index.html "Mozilla/5.0
4     (Windows; U; Windows NT 5.1; en-US; rv:1.7.7)" 

Although the appendix provides a comprehensive logging format reference, this list describes the most important fields:

  • %h: The IP address of the client that sent the request to the web server, or the client's hostname if you have HostNameLookups enabled ( in this example.)
  • %u: The user id of the user who sent the request determined by HTTP authentication (someuser in the example). See Chapter 6 for more details on how to configure HTTP-based authentication.
  • %t: Time when the request was received by the server.
  • %r: Text of the original request line from the client including the HTTP method used, the resource requested, and the HTTP protocol version used by the client's browser ("GET /example.png HTTP/1.0" in the example).
  • %>s: The final HTTP request status code that the web server sends back to the client (200 in the example, indicating that the request was completed successfully).
  • %b: The size in bytes of the object sent to the client in response to the request excluding the response headers (1234 in the example).

The combined log format extends the common log format with two additional fields. It is defined as

  • %{Referer}i: The Referer HTTP request header; that is, the web page that referred to the current document (http://www.example.com/index.html in the example).
  • %{User-agent}i: The User-agent HTTP request header. It includes information about the client's browser ("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7)" in the example).

jmeter性能监控插件-Servers Performance Monitoring

Servers Performance Monitoring IntroductionMetrics collectedHow it works ConceptInstallation...
  • hualusiyu
  • hualusiyu
  • 2013年05月14日 15:43
  • 1369

使用IBM Tivoli Monitoring Universal Agent自定义开发Windows Terminal Service监控服务

使用IBM Tivoli Monitoring UniversalAgent自定义开发Windows Terminal Service监控服务IBM TivoliMonitoring产品简称ITM,当...
  • jaminwm
  • jaminwm
  • 2015年04月09日 14:59
  • 2604

解决apache 文件夹下 logs 错误日志文件过大的问题

apache用久了,就会发现在logs文件夹下面 error.log 和 access.log 这两个文件就会超过1个G了,占用太多的磁盘空间,直接删除也没用,还会再生成这么大的文件。 其实只需更改...
  • kof820
  • kof820
  • 2012年03月26日 14:11
  • 4799

Apache不能启动: Unable to open logs

Apache不能启动: Unable to open logs 原因记录:       1: 80端口被占,我遇到的情况就是QQ音乐把80端口占用,关掉对应程序就OK       2: 配置参数...
  • jaray
  • jaray
  • 2014年04月22日 15:18
  • 2123

Jmeter 结合 Servers Performance Monitoring 插件进行性能监控

我们在使用Jmeter进行性能测试的时候很多时候都得关注服务端的性能的资源占用情况。所以你可能就得另外找个工具来进行数据的采集了。但是Jmeter实际上已经有对应的插件完成了这项工作了。 介绍Serv...
  • qq744746842
  • qq744746842
  • 2016年04月10日 19:26
  • 1321

apache启动问题 操作失败 Unable to open logs

Apache不能启动: Unable to open logs很难从给出的信息中发现有用的东西,让你不知道是哪除了问题,幸好通常你不会是第一个碰到这个问题的人,又幸好有google。今天一开机,Apa...
  • lgh1117
  • lgh1117
  • 2011年05月09日 13:56
  • 1344

Monitoring and Troubleshooting Using Event Logs

原文: http://www.windowsnetworking.com/articles_tutorials/Monitoring-Troubleshooting-Event-Logs.htmlTh...
  • dctfjy
  • dctfjy
  • 2009年08月04日 13:53
  • 523

apache启动失败,提示Unable to open logs

查看搜索一番,多数提示80端口被占用,确认没用的占用情况下,仔细阅读配置文件。查看日志文件,显示的错误信息是:Unable to open logs。网搜,有说本机并没有配置域名,配置参数中有个Ser...
  • ebiyuan
  • ebiyuan
  • 2009年12月13日 23:27
  • 6806

Instructions for Pulling BMC Logs - Servers

Configure the network interface:The Servers BMC controller shares the network interface with the...
  • ghostly78
  • ghostly78
  • 2007年07月27日 20:54
  • 795


Normal 0 0 2 false false false EN-US JA X-NONE ...
  • lk_cool
  • lk_cool
  • 2009年09月08日 15:55
  • 7325
您举报文章:Logs and Monitoring for Apache Servers