Apache2 BootCamp : Logging and Monitoring

24
Day #2 Logging and Monitoring Wildan Maulana [email protected] http://workshop.openthinklabs.com #8

Transcript of Apache2 BootCamp : Logging and Monitoring

Page 2: Apache2 BootCamp : Logging and Monitoring

Overview

● Understand log formats and logging levels● Rotate and analyze logs● Interpret common errors that might appear in

your logs● Monitor Apache resource usage and

performance using mod_status

Page 3: Apache2 BootCamp : Logging and Monitoring

Logging HTTP Requests

● Define what you want to log; your log format● Define where you want to log it; your log files, a

database, an external program● Define whether or not to log; conditional

logging rules

Page 4: Apache2 BootCamp : Logging and Monitoring

What Do You Want to Log?

● Common Log Format (CLF) :“%h %l %u %t \”%r\” %>s %b”

10.0.0.1 - - [19/Nov/2001:11:34:56 -0800] “GET / HTTP/1.1” 200 1456

LogFormat “%h %l %u %t \”%r\” %>s %b” common

Log Formatting Directives : http://bit.ly/lAayTL

Page 5: Apache2 BootCamp : Logging and Monitoring

Where Do You Want to Log the Information?

● Logging to Files● Logging to a Program● Logging to Databases● Cluster Logging

Page 6: Apache2 BootCamp : Logging and Monitoring

Where Do You Want to Log the Information?Logging to Files

LogFormat “%h %l %u %t \”%r\” %>s %b \”%{User-agent}i\””TransferLog logs/access_log

LogFormat “%h %l %u %t \”%r\” %>s %b \”%{User-agent}i\”” myformatCustomLog logs/access_log myformat

CustomLog logs/access_log “%h %l %u %t \”%r\” %>s %b \”%{User-agent}i\””

Page 7: Apache2 BootCamp : Logging and Monitoring

Where Do You Want to Log the Information?Logging to a Program

|

Page 8: Apache2 BootCamp : Logging and Monitoring

Where Do You Want to Log the Information?Logging to Databases

http://bit.ly/c8EiYy

Page 9: Apache2 BootCamp : Logging and Monitoring

Where Do You Want to Log the Information?Cluster Logging

mod_log_spread

Page 10: Apache2 BootCamp : Logging and Monitoring

Conditional Logging

● The HostNameLookups Directive● The IdentityCheck Directive● Environment Variables● Status Code

Page 11: Apache2 BootCamp : Logging and Monitoring

Conditional LoggingThe HostNameLookups Directive

HostNameLookups on|off|double

Page 12: Apache2 BootCamp : Logging and Monitoring

Conditional LoggingThe IdentityCheck Directive

IdentityCheck on|off

Page 13: Apache2 BootCamp : Logging and Monitoring

Conditional LoggingEnvironment Variables

SetEnvIf Request_URI “(\.gif|\.jpg)$” imageCustomLog logs/access_log common env=!image

Page 14: Apache2 BootCamp : Logging and Monitoring

Conditional LoggingStatus Code

%400,501{User-agent}i

400 : malformed requests501 : methods not implemented

Page 15: Apache2 BootCamp : Logging and Monitoring

Error Messages

● Logging to a File● Logging to a Program● The syslog Daemon Argument● The LogLevel Directive

Page 16: Apache2 BootCamp : Logging and Monitoring

Error MessagesLogging to a File

ErrorLog logs/my_error_log

Page 17: Apache2 BootCamp : Logging and Monitoring

Error MessagesLogging to a Program

ErrorLog “|/usr/local/bin/someprogram”

Page 18: Apache2 BootCamp : Logging and Monitoring

Error MessagesThe syslog Daemon Argument

ErrorLog syslog:local6

Page 19: Apache2 BootCamp : Logging and Monitoring

Monitoring Apache

mod_info

mod_status

<Location /server-status>SetHandler server-statusOrder deny,allowDeny from allAllow from .example.com</Location>

<Location /server-info>SetHandler server-infoOrder deny,allowDeny from allAllow from .example.com</Location>

Page 20: Apache2 BootCamp : Logging and Monitoring

Error MessagesThe LogLevel Directive

LogLevel warn

http://httpd.apache.org/docs/2.0/mod/core.html#loglevel

Page 21: Apache2 BootCamp : Logging and Monitoring

Managing Logs

● Resolving Hostnames● Log Rotation● Merging and Splitting Logs● Logging to Databases● Log Analysis● Monitoring Error Logs

Page 22: Apache2 BootCamp : Logging and Monitoring

Common Errors

● Connection Reset by Peer● File favico.icon Not Found● File robots.txt Not Found● httpd.pid Overwritten

Page 24: Apache2 BootCamp : Logging and Monitoring

Reference

● Daniel Lopez Ridruezo; SAMS Teach Yourself Apache2 in 24 Hours, SAMS Publishing, 2002 (Buy this book on Amazon)