From f1fd1c9714256bb9b212462dd31ca6dc56ea31ef Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Thu, 21 Jul 2011 19:10:20 -0400 Subject: add in project web page --- docs/contents.png | Bin 0 -> 278 bytes docs/crossref.png | Bin 0 -> 147 bytes docs/documentation.css | 33 + docs/documentation.html | 269 +++++++ docs/img1.png | Bin 0 -> 154 bytes docs/img2.png | Bin 0 -> 214 bytes docs/img3.png | Bin 0 -> 318 bytes docs/img4.png | Bin 0 -> 564 bytes docs/index.html | 269 +++++++ docs/next.png | Bin 0 -> 245 bytes docs/next_g.png | Bin 0 -> 272 bytes docs/node1.html | 128 +++ docs/node2.html | 276 +++++++ docs/node3.html | 664 ++++++++++++++++ docs/node4.html | 2014 +++++++++++++++++++++++++++++++++++++++++++++++ docs/node5.html | 1270 ++++++++++++++++++++++++++++++ docs/node6.html | 74 ++ docs/prev.png | Bin 0 -> 279 bytes docs/prev_g.png | Bin 0 -> 327 bytes docs/style_1.css | 33 + docs/up.png | Bin 0 -> 211 bytes docs/up_g.png | Bin 0 -> 231 bytes 22 files changed, 5030 insertions(+) create mode 100644 docs/contents.png create mode 100644 docs/crossref.png create mode 100644 docs/documentation.css create mode 100644 docs/documentation.html create mode 100644 docs/img1.png create mode 100644 docs/img2.png create mode 100644 docs/img3.png create mode 100644 docs/img4.png create mode 100644 docs/index.html create mode 100644 docs/next.png create mode 100644 docs/next_g.png create mode 100644 docs/node1.html create mode 100644 docs/node2.html create mode 100644 docs/node3.html create mode 100644 docs/node4.html create mode 100644 docs/node5.html create mode 100644 docs/node6.html create mode 100644 docs/prev.png create mode 100644 docs/prev_g.png create mode 100644 docs/style_1.css create mode 100644 docs/up.png create mode 100644 docs/up_g.png (limited to 'docs') diff --git a/docs/contents.png b/docs/contents.png new file mode 100644 index 0000000..0c752c6 Binary files /dev/null and b/docs/contents.png differ diff --git a/docs/crossref.png b/docs/crossref.png new file mode 100644 index 0000000..7dd2ddd Binary files /dev/null and b/docs/crossref.png differ diff --git a/docs/documentation.css b/docs/documentation.css new file mode 100644 index 0000000..f12a3af --- /dev/null +++ b/docs/documentation.css @@ -0,0 +1,33 @@ +body { + margin-left: 3%; + background-color: #ccccFF; + font-family: sans-serif; +} + +h1 { + text-align: center; +} + +h2 { + margin-left: -1%; + font-size: 150%; +} + +h3 { + margin-left: -1%; +} + +h4 { + text-align: center; +} + +p { +} + +pre { + font-family: monospace; +} + +DD { + font-family: monospace; +} \ No newline at end of file diff --git a/docs/documentation.html b/docs/documentation.html new file mode 100644 index 0000000..d63b31f --- /dev/null +++ b/docs/documentation.html @@ -0,0 +1,269 @@ + + + + +
++ + + + +
+ +
+
Christopher Powell, <chris@grubbybaby.com>
++ + + + +
+ +
+
Christopher Powell, <chris@grubbybaby.com>
+
+
+ +
+ +
+ +
+This Apache module will permit you to log to a SQL database; it can +log each access request as well as data associated with each request: +cookies, notes, and inbound/outbound headers. Unlike logging to a +flat text file - which is standard in Apache - a SQL-based log exhibits +tremendous flexibility and power of data extraction. (See section +4.1.1 in the FAQ for further discussion and examples of the +advantages to SQL.) + +
+This module can either replace or happily coexist with mod_log_config, +Apache's text file logging facility. In addition to being more configurable +than the standard module, mod_log_sql is much more flexible. + +
+ +
+This project was formerly known as ``mod_log_mysql.'' It was +renamed ``mod_log_sql'' in order to reflect the project goal +of database-inspecificity. The module currently supports MySQL, but +support for other database backends is underway. + +
+In order to save speed and overhead, links are kept alive in between +queries. This module uses one dedicated SQL link per httpd child, +opened by each child process when it is born. Among other things, +this means that this module supports logging into only one MySQL server, +and for now, also, only one SQL database. But that's a small tradeoff +compared to the blinding speed of this module. Error reporting is +robust throughout the module and will inform the administrator of +database issues in the Apache ERRORLOG for the server/virtual +server. + +
+Virtual hosts are supported in the same manner they are in the regular +logging modules. The administrator defines some basic 'global' directives +in the main server config, then defines more specific 'local' directives +inside each VirtualHost stanza. + +
+A robust "preserve" capability has now been implemented. +This permits the module to preserve any failed INSERT commands to +a local file on its machine. In any situation that the database is +unavailable - e.g. the network fails or the database host is rebooted +- mod_log_sql will note this in the error log and begin appending +its log entries to the preserve file (which is created with the user +& group ID of the running Apache process, e.g. "nobody/nobody" +on many Linux installations). When database availablity returns, mod_log_sql +seamlessly resumes logging to it. When convenient for the sysadmin, +he/she can easily import the preserve file into the database because +it is simply a series of SQL insert statements. + +
+ +
+All the data that would be contained in the "Combined Log +Format" is logged by default, plus a little extra. Your best +bet is to begin by accepting this default, then later customize the +log configuration based on your needs. + +
+The documentation of the run-time directives includes a full explanation +of what you can log, including examples - see section 3.6. + +
+ +
+ +
+In MySQL 3.21 and above you can easily convert this to a human readable +format using from_unixtime(), e.g.: + +
+ +
+
+ +
+The actual logging code was taken from the already existing flat file +text modules, so all that credit goes to the Apache Server group. + +
+The MySQL routines and directives were added by Zeev Suraski <bourbon@netvision.net.il>. + +
+All changes from 1.06+ and the new documentation were added by Chris +Powell <chris@grubbybaby.com>. It seems that the module had fallen +into the "unmaintained" category - it hadn't been +updated since 1998 - so Chris adopted it as the new maintainer. + +
+
+ +
+ +
+ +
+These installation documents assume a relatively modern GNU/Linux +scenario. mod_log_sql has been ported to other platforms; following +are notes on compiling the module for those platforms. + +
+ +
+The nanosleep() function used in mod_log_sql relies on linking aginst +the librt library. Make the following alterations before proceeding: + +
+ +
+ +
+No notes are available at present, but they are desired. If you have +successfully ported mod_log_sql to BSD, please contact the maintaniner, Chris Powell (chris@grubbybaby.com) +and help fill in this section. + +
+ +
+No notes are available at present, but they are desired. If you have +successfully ported mod_log_sql to Win32, please contact +the maintaniner, Chris Powell (chris@grubbybaby.com) and help +fill in this section. + +
+ +
+You need to know the answer to this question before you proceed. The +answer is pretty straightforward: what have you done in the past? +If you like all your Apache modules to be dynamic, then you should +keep doing that. If you're more of an old-school type and prefer to +compile the modules right into apache, do that. Both methods work +equally well. + +
+FWIW, the DSO method is more modern and increasing in popularity because +apxs takes care of a lot of dirty little details for you. As you'll +see below, the static-module method is a little more complex. + +
+ +
+ +
+ +
+# cd /usr/local/src/mod_log_sql +
+ +
+
+
+
+ +
+ +
+ +
+gcc -DLINUX=22 -DNO_DBM_REWRITEMAP -DMOD_SSL=208111 -DUSE_HS... + +
+gcc -shared -o mod_log_sql.so mod_log_sql.o -Wc,-O2 -Wc,-Wall -Wc... +
+
+ +
+ +
+cp mod_log_sql.so /usr/local/Apache/libexec/mod_log_sql.so + +
+chmod 755 /usr/local/Apache/libexec/mod_log_sql.so +
+ +
+ +
+ +
+ +
+ +
+ +
+/usr/local/apache/bin/apachectl startssl: httpd could not be started +
+Now skip below to section 3, Configuration. + +
+
+ +
+ +
+ +
+# cd /usr/local/src/mod_log_sql +
+ +
+
+
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+http_core.c + +
+mod_log_sql.c <- That's the line you're looking for. + +
+mod_env.c + +
+mod_log_config.c + +
+mod_mime.c + +
+mod_negotiation.c + +
+etc... +
+ +
+# mv /usr/local/Apache/bin/httpd ~/httpd-save + +
+# cp -f ./httpd /usr/local/Apache/bin/ +
+
+ +
+You have to prepare the database to receive data from mod_log_sql, +and set up run-time directives in httpd.conf to control how and what +mod_log_sql logs. + +
+This section will discuss how to get started with a basic config. +Full documentation of all available run-time directives is available +in section 3.6. + +
+ +
+ +
+Enter password: + +
+mysql> create database apachelogs; +
+ +
+ +
+identified by 'l0gger'; +
+ +
+identified by 'l0gger'; +
+ +
+ +
+ +
+ +
+So, edit httpd.conf and insert the following lines somewhere after +any LoadModule / AddModule statements. Make sure these statements +are ``global,'' i.e. not inside any VirtualHost stanza. You will +also note that you are embedding a password in the file. Therefore +you are advised to ``chmod 660 httpd.conf'' to prevent unauthorized +regular users from viewing your database user and password. + +
+Example: Use the MySQL database called "apachelogs" +running on "dbmachine.foo.com". Use username "loguser" +and password "l0gg3r" to authenticate to the database. +Permit the module create tables for us. + +
+ +
+LogSQLDatabase apachelogs + +
+LogSQLCreateTables on +
+ +
+ +
+ +
+ [snip] + +
+ LogSQLTransferLogTable access_log + +
+ [snip] + +
+</VirtualHost> +
+ +
+# /etc/rc.d/init.d/httpd start +
+ +
+ +
+ +
+Enter password: +
+
+ +
+ +
+The most basic directive for the module is LOGSQLTRANSFERLOGFORMAT, +which tells the module which information to send to the database; +logging to the database will not take place without it. Place a LOGSQLTRANSFERLOGFORMAT +directive in the VirtualHost stanza of each virtual host that you +want to activate. + +
+After LOGSQLTRANSFERLOGFORMAT you supply a string of characters +that tell the module what information to log. In the configuration +directive reference (section 3.6.17) there is a table which +clearly defines all the possible things to log. Let's say you want +to log only the ``request time,'' the ``remote host,'' and +the ``request''; you'd use: + +
+ +
+ +
+If you don't choose to log everything that is available, that's fine. +Fields in the unused columns in your table will simply contain NULL. + +
+Some of the LOGSQLTRANSFERLOGFORMAT characters require a +little extra configuration: + +
+ +
+ +
+One ``accept'' and two ``ignore'' directives allow you to +fine-tune what the module should not log. These are very handy for +keeping your database as uncluttered as possible and keeping your +statistics free of unneeded numbers. Think of each one as a gatekeeper. + +
+It is important to remember that each of these three directives +is purely optional. mod_log_sql's default is to log everything. + +
+When a request comes in, the contents of LOGSQLREQUESTACCEPT +are evaluated first. This optional, ``blanket'' directive lets +you specify that only certain things are to be accepted for logging, +and everything else discarded. Because it is evaluated before LOGSQLREQUESTIGNORE +and LOGSQLREMHOSTIGNORE it can halt logging before those +two filtering directives ``get their chance.'' + +
+Once a request makes it past LOGSQLREQUESTACCEPT, it still +can be excluded based on LOGSQLREMHOSTIGNORE and LOGSQLREQUESTIGNORE. +A good way to use LOGSQLREMHOSTIGNORE is to prevent the module +from logging the traffic that your internal hosts generate. LOGSQLREQUESTIGNORE +is great for preventing things like requests for ``favicon.ico'' +from cluttering up your database, as well as excluding the various +requests that worms make, etc. + +
+You can specify a series of strings after each directive. Do not use +any type of globbing or regular-expression syntax - each string is +considered a match if it is a substring of the larger request +or remote-host; the comarison is case-sensitive. This means that +``LOGSQLREMHOSTIGNORE micro'' will ignore requests from +``microsoft.com,'' ``microworld.net,'' ``mymicroscope.org,'' +etc. ``LOGSQLREQUESTIGNORE gif'' will instruct the module +to ignore requests for ``leftbar.gif,'' ``bluedot.gif'' and +even ``giftwrap.jpg'' - but ``RED.GIF'' and ``Tree.Gif'' +would still get logged because of case sensitivity. + +
+A summary of the decision flow: + +
+ +
+ +
+LogSQLRequestIgnore statistics.html bluedot.jpg +
+Tip: if you want to match all the hosts in your domain such as ``host1.corp.foo.com'' +and ``server.dmz.foo.com'', simply specify: + +
+ +
+ +
+ +
+ +
+ +
+mod_log_sql has three basic tiers of operation: + +
+ +
+ +
+In an ISP scenario the admin is likely to have a cluster of many front-end +webservers logging to a back-end database. mod_log_sql has a feature +that permits analysis of how well the web servers are loadbalancing: +the LOGSQLMACHINEID directive. The administrator uses this +directive to assign a unique identifier to each machine in the web +cluster, e.g. ``LOGSQLMACHINEID web01,'' ``LOGSQLMACHINEID +web02,'' etc. Used in conjunction with the 'M' character in LOGSQLTRANSFERLOGFORMAT, +each entry in the SQL log will include the machine ID of the machine +that created the entry. This permits the administrator to count the +entries made by each particular machine and thereby analyze the front-end +loadbalancing algorithm. + +
+ +
+A given HTTP request can have a one-to-many relationship with certain +kinds of data. For example, a single HTTP request can have 4 cookies, +3 headers and 5 ``mod_gzip'' notes associated with it. mod_log_sql +is capable of logging these relationships due to the elegance of SQL +relational data. + +
+You already have a single table containing access requests. One of +the columns in that table is 'id' which is intended to contain the +unique request ID supplied by the standard Apache module mod_unique_id +- all you need to do is compile in that module and employ the LOGSQLTRANSFERLOGFORMAT +character 'I'. Thereafter, each request gets a unique ID that can +be thought of as a primary key within the database, useful for joining +multiple tables. So let's envision several new tables: a notes table, +a cookies table, and a table for inbound and outbound headers. + +
+
+ +
+
++ +
+
+
+
+ +
+
++We have a certain request, and its unique ID is ``PPIDskBRH30AAGPtAsg''. +Within each separate table will be multiple entries with that request +ID: several cookie entries, several header entries, etc. As you can +see in tables 1, 2 and 3, you +have a one-to-many relationship for request PPIDskBRH30AAGPtAsg: that +one access has two associated notes and four associated headers. You +can extract this data easily using the power of SQL's ``select'' +statement and table joins. To see the notes associated with a particular +request: + +
+ +
+where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg'; + +
+
remote_host | +request_uri | +item | +val | +
zerberus.aiacs.net | +/mod_log_sql/index.html | +mod_gzip_result | +OK | +
zerberus.aiacs.net | +/mod_log_sql/index.html | +mod_gzip_compression_ratio | +69 | +
+ +
+
+In order to use this capability of mod_log_sql, you must do several +things: + +
+ +
+ (snip) + +
+ LogSQLNotesLogTable notestable + +
+ LogSQLWhichCookies bluecookie redcookie greencookie + +
+ LogSQLWhichNotes mod_gzip_result mod_gzip_compression_ratio + +
+ LogSQLWhichHeadersOut Expires Content-Type Cache-Control + +
+ LogSQLWhichHeadersIn UserAgent Accept-Encoding Host + +
+ (snip) + +
+</VirtualHost> +
+ +
+Although suboptimal, it is not uncommon to use the same backend database +for the ``production'' webservers as well as the ``test'' +webservers (budgetary constraints, rackspace limits, etc.). Furthermore, +an administrator in this situation may be unable to use LOGSQLREMHOSTIGNORE +to exclude requests from the test servers - perhaps the generated +entries are genuinely useful for analytical or QA purposes, but their +value after analysis is minimal. + +
+It is wasteful and potentially confusing to permit this internal test +data to clutter the database, and a solution to the problem is the +proper use of the LOGSQLMACHINEID directive. Assume a scenario +where the production webservers have IDs like ``web01,'' ``web02,'' +and so on - and the test webservers have IDs like ``test01,'' +``test02,'' etc. Because entries in the log database are distinguished +by their source machine, an administrator may purge unneeded test +data from the access log as follows: + +
+ +
+ +
+A busy MySQL database will have SELECT statements running concurrently +with INSERT and UPDATE statements. A long-running SELECT can in certain +circumstances block INSERTs and therefore block mod_log_sql. A workaround +is to compile mod_log_sql for ``delayed inserts,'' which are +described as follows in the MySQL documentation: + +
+
+The DELAYED option for the INSERT statement is a MySQL-specific option +that is very useful if you have clients that can't wait for the INSERT +to complete. This is a common problem when you use MySQL for logging +and you also periodically run SELECT and UPDATE statements that take +a long time to complete. DELAYED was introduced in MySQL Version 3.22.15. +It is a MySQL extension to ANSI SQL92. ++
+
INSERT DELAYED only works with ISAM and MyISAM tables. Note that as +MyISAM tables supports concurrent SELECT and INSERT, if there is no +free blocks in the middle of the data file, you very seldom need to +use INSERT DELAYED with MyISAM. ++
+
When you use INSERT DELAYED, the client will get an OK at once and +the row will be inserted when the table is not in use by any other +thread. ++
+
Another major benefit of using INSERT DELAYED is that inserts from +many clients are bundled together and written in one block. This is +much faster than doing many separate inserts. + ++The general disadvantages of delayed inserts are: + +
+ +
+If you are experiencing issues which could be solved by delayed inserts, +uncomment the #MYSQLDELAYED line in the Makefile by removing the +# that is in front of it. Recompile and reinstall your module. All +regular INSERT statements are now INSERT DELAYED, and you should see +no more blocking of the module. + +
+ +
+It is imperative that you understand which directives are used only +once in the main server config, and which are used inside VirtualHost +stanzas and therefore multiple times within httpd.conf. The ``context'' +listed with each entry informs you of this. + +
+ +
+ +
+Example: LogSQLCookieLogTable cookie_log + +
+Default: cookies + +
+Context: virtual host +
+Note that you must create the table (see create-tables.sql, included +in the package), or LOGSQLCREATETABLES must be set to ``on''. + +
+ +
+ +
+Example: LogSQLCreateTables On + +
+Default: Off + +
+Context: main server config +
+There is a slight disadvantage: if you wish to activate this feature, +then the userid specified in LOGSQLLOGININFO must have CREATE +privileges on the database. In an absolutely paranoid, locked-down +situation you may only want to grant your mod_log_sql user INSERT +privileges on the database; in that situation you are unable to take +advantage of LOGSQLCREATETABLES. But most people - even +the very security-conscious - will find that granting CREATE on the +logging database is reasonable. + +
+This is defined only once in the httpd.conf file. + +
+ +
+ +
+Syntax: LogSQLDatabase database + +
+Example: LogSQLDatabase loggingdb + +
+Context: main server config +
+This is defined only once in the httpd.conf file. + +
+ +
+ +
+Example: LogSQLPreserveFile on + +
+Default: off + +
+Context: main server config +
+This is presumably a directive for temporary use only; it could be +dangerous if you set it and forget it, as all your entries will simply +pile up in the preserve file. + +
+This is defined only once in the httpd.conf file. + +
+ +
+ +
+Example: LogSQLHeadersInLogTable headers + +
+Default: headers_in + +
+Context: virtual host +
+Note that you must create the table (see create-tables.sql, included +in the package), or LOGSQLCREATETABLES must be set to ``on''. + +
+ +
+ +
+Example: LogSQLHeadersOutLogTable headers + +
+Default: headers_out + +
+Context: virtual host +
+Note that you must create the table (see create-tables.sql, included +in the package), or LOGSQLCREATETABLES must be set to ``on''. + +
+ +
+ +
+Syntax: LogSQLLoginInfo host user password + +
+Example: LogSQLLoginInfo foobar.baz.com logwriter passw0rd + +
+Context: main server config +
+This is defined only once in the httpd.conf file. + +
+ +
+ +
+Example: LogSQLMachineID web01 + +
+Context: main server config +
+This is defined only once in the httpd.conf file. + +
+ +
+ +
+Example: LogSQLMassVirtualHosting On + +
+Default: Off + +
+Context: main server config +
+ +
+You are advised to investigate the use of Apache's USECANONICALNAME +ON directive with this directive in order to ensure that each virtual +host maps to one table namespace. + +
+This is defined only once in the httpd.conf file. + +
+ +
+ +
+Example: LogSQLNotesLogTable notes_log + +
+Default: notes + +
+Context: virtual host +
+Note that you must create the table (see create-tables.sql, included +in the package), or LOGSQLCREATETABLES must be set to ``on''. + +
+ +
+ +
+Example: LogSQLPreserveFile offline-preserve + +
+Default: /tmp/sql-preserve + +
+Context: virtual host +
+ +
+The module will log to Apache's ERRORLOG when it notices +a database outage, and upon database return. You will therefore know +when the preserve file is being used, although it is your responsibility +to import the file. + +
+The file does not need to be created in advance. It is safe to remove +or rename the file without interrupting Apache, as the module closes +the filehandle immediately after completing the write. The file is +created with the user & group ID of the running Apache process (e.g. +'nobody' on many Linux distributions). + +
+ +
+ +
+Example: LogSQLRemhostIgnore localnet.com + +
+Context: virtual host +
+Each string is separated by a space, and no regular expressions or +globbing are allowed. Each string is evaluated as a substring of the +REMOTE_HOST using strstr(). The comparison is case sensitive. + +
+ +
+ +
+Example: LogSQLRequestAccept .html .php .jpg + +
+Default: if not specified, all requests are ``accepted'' + +
+Context: virtual host +
+This directive is useful for cutting down on log clutter when you +are certain that you only want to log certain kinds of requests, and +just blanket-ignore everything else. See section 3.4.2 +for some tips for using this directive. + +
+Each string is separated by a space, and no regular expressions or +globbing are allowed. Each string is evaluated as a substring of the +URI using strstr(). The comparison is case sensitive. + +
+This directive is completely optional. It is more general than LOGSQLREQUESTIGNORE +and is evaluated before LOGSQLREQUESTIGNORE. If +this directive is not used, all requests are accepted and +passed on to the other filtering directives. Therefore, only use this +directive if you have a specific reason to do so. + +
+ +
+ +
+Example: LogSQLRequestIgnore root.exe cmd.exe default.ida favicon.ico + +
+Context: virtual host +
+Each string is separated by a space, and no regular expressions or +globbing are allowed. Each string is evaluated as a substring of the +URI using strstr(). The comparison is case sensitive. + +
+ +
+ +
+Example: LogSQLSocketFile /tmp/mysql.sock + +
+Default: /var/lib/mysql/mysql.sock + +
+Context: main server config +
+mod_log_sql will automatically employ the socket for db communications +if the database resides on the local host. If the db resides on a +separate host the module will automatically use TCP/IP. This is a +function of the MySQL API and is not user-configurable. + +
+This is defined only once in the httpd.conf file. + +
+ +
+ +
+Example: LogSQLTCPPort 3309 + +
+Default: 3306 + +
+Context: main server config +
+This is defined only once in the httpd.conf file. + +
+ +
+ +
+Example: LogSQLTransferLogFormat huSUTv + +
+Default: AbHhmRSsTUuv + +
+Context: virtual host +
+
+++
+ + What is this? +Data field +Column type +Example ++ A +User agent +agent +varchar(255) +Mozilla/4.0 (compat; MSIE 6.0; Windows) ++ a +CGI request arguments +request_args +varchar(255) +user=Smith&cart=1231&item=532 ++ b +Bytes transfered +bytes_sent +int unsigned +32561 ++ c +Text of cookie +cookie +varchar(255) +Apache=sdyn.fooonline.net.1300102700823 ++ H +HTTP request protocol +request_protocol +varchar(10) +HTTP/1.1 ++ h +Name of remote host +remote_host +varchar(50) +blah.foobar.com ++ I +Request ID (from mod_unique_id) +id +char(19) +POlFcUBRH30AAALdBG8 ++ l +Ident user info +remote_logname +varchar(50) +bobby ++ M +Machine ID +machine_id +varchar(25) +web01 ++ m +HTTP request method +request_method +varchar(6) +GET ++ P +httpd child PID +child_pid +smallint unsigned +3215 ++ p +httpd port +server_port +smallint unsigned +80 ++ R +Referer +referer +varchar(255) +http://www.biglinks4u.com/linkpage.html ++ r +Request in full form +request_line +varchar(255) +GET /books-cycroad.html HTTP/1.1 ++ S +Time of request in UNIX format +time_stamp +int unsigned +1005598029 ++ s +HTTP status of request +status +smallint unsigned +404 ++ T +Seconds to service request +request_duration +smallint unsigned +2 ++ t +Time of request in human format +request_time +char(28) +[02/Dec/2001:15:01:26 -0800] ++ U +Request in simple form +request_uri +varchar(255) +/books-cycroad.html ++ u +User info from HTTP auth +remote_user +varchar(50) +bobby ++ v +Virtual host servicing the request +virtual_host +varchar(50) +www.foobar.com +
+
++
+
You must also specify LOGSQLWHICHCOOKIE +for this to take effect. ++
+
You must also specify LOGSQLMACHINEID for +this to take effect. + ++If you have compiled mod_log_sql with SSL logging capability, you +also can use these: + +
+
++ ++
++ + What is this? +Data field +Column Type +Example ++ z +SSL cipher used +ssl_cipher +varchar(25) +RC4-MD5 ++ q +Keysize of the SSL connection +ssl_keysize +smallint unsigned +56 ++ Q +Maximum keysize supported +ssl_maxkeysize +smallint unsigned +128 +
+ +
+ +
+Syntax: LogSQLTransferLogTable table-name + +
+Example: LogSQLTransferLogTable access_log_table + +
+Context: virtual host +
+This directive is not necessary if you declare LOGSQLMASSVIRTUALHOSTING +ON, since that directive activates dynamically-named tables. If you +attempt to use LOGSQLTRANSFERLOGTABLE at the same time a +warning will be logged and it will be ignored, since LOGSQLMASSVIRTUALHOSTING +takes priority. + +
+ +
+ +
+Example: LogSQLWhichCookie Clicks + +
+Default: None + +
+Context: virtual host +
+You must include a 'c' character in LOGSQLTRANSFERLOGFORMAT +for this directive to take effect; once you specify 'c', LOGSQLWHICHCOOKIE +tells mod_log_sql which cookie to log. This is necessary because +you will usually be setting and receiving more than one cookie from +a client; this cookie designates which one to log. + +
+Note: although this was intended for people who are using mod_usertrack +to set user-tracking cookies, you aren't restricted in any way. You +can choose which cookie you wish to log to the database -any cookie +at all - and it doesn't necessarily have to have anything to do with +mod_usertrack. + +
+ +
+ +
+Example: LogSQLWhichCookies userlogin foobar foobaz + +
+Default: None + +
+Context: virtual host +
+Note that you must have already created the table (see create-tables.sql, +included in the package), or LOGSQLCREATETABLES must be set +to ``on''. + +
+ +
+ +
+Example: LogSQLWhichHeadersIn UserAgent Accept-Encoding Host + +
+Default: None + +
+Context: virtual host +
+Note that you must have already created the table (see create-tables.sql, +included in the package), or LOGSQLCREATETABLES must be set +to ``on''. + +
+ +
+ +
+Example: LogSQLWhichHeadersOut Expires Content-Type Cache-Control + +
+Default: None + +
+Context: virtual host +
+Note that you must have already created the table (see create-tables.sql, +included in the package), or LOGSQLCREATETABLES must be set +to ``on''. + +
+ +
+ +
+Example: LogSQLWhichNotes mod_gzip_result mod_gzip_compression_ratio + +
+Default: None + +
+Context: virtual host +
+Note that you must have already created the table (see create-tables.sql, +included in the package), or LOGSQLCREATETABLES must be set +to ``on''. + +
+
+ +
+ +
+To begin with, let's get it out of the way: logging to a database +is not a panacea. But while there are complexities with this solution, +the benefit can be substantial for certain classes of administrator +or people with advanced requirements: + +
+ +
+ +
+from acc_log_tbl where status=404 order by time_stamp; + +
+
remote_host | +status | +request_uri | +bytes_sent | +from_unixtime(time_stamp) | +
marge.mmm.co.uk | +404 | +/favicon.ico | +321 | +2001-11-20 02:30:56 | +
62.180.239.251 | +404 | +/favicon.ico | +333 | +2001-11-20 02:45:25 | +
212.234.12.66 | +404 | +/favicon.ico | +321 | +2001-11-20 03:01:00 | +
212.210.78.254 | +404 | +/favicon.ico | +333 | +2001-11-20 03:26:05 | +
+ +
+
+ +
+acc_log_tbl where request_uri like '%mod_log_sql%' group by request_uri order + +
+by howmany desc; + +
+
request_uri | +bytes | +howmany | +
/mod_log_sql/style_1.css | +157396 | +1288 | +
/mod_log_sql/ | +2514337 | +801 | +
/mod_log_sql/mod_log_sql.tar.gz | +9769312 | +456 | +
/mod_log_sql/faq.html | +5038728 | +436 | +
+ +
+
+ +
+request_uri='/mod_log_sql/' group by referer order by num desc; + +
+
num | +referer | +
271 | +http://freshmeat.net/projects/mod_log_sql/ | +
96 | +http://modules.apache.org/search?id=339 | +
48 | +http://freshmeat.net/ | +
8 | +http://freshmeat.net | +
+ +
+
+ +
+MySQL is a robust, free, and very powerful production-quality database +engine. It is well supported and comes with detailed documentation. +Many 3rd-party software pacakges (e.g. Slashcode, the engine that +powers Slashdot) run exclusively with MySQL. In other words, you will +belong to a very robust and well-supported community by choosing MySQL. + +
+That being said, there are alternatives. PostgreSQL is probably MySQL's +leading "competitor" in the free database world. +There is also an excellent module available for Apache to permit logging +to a PostgreSQL database, called pgLOGd (http://www.digitalstratum.com/pglogd/). + +
+ +
+By all accounts it is. It is known to work without a problem on many-thousands-of-hits-per-day +webservers. Does that mean it is 100% bug free? Well, no software +is. But it is well-tested and believed to be fully compatible with +production environments. (The usual disclaimers apply. This software +is provided without warranty of any kind.) + +
+ +
+Good question! It would be great to find out! If you are a production-level +mod_log_sql user, please contact the maintainer, Chris Powell (chris@grubbybaby.com) +so that you can be mentioned here. + +
+ +
+There are circumstances when that would be quite unwise - for example, +if Apache could not reach the MySQL server for some reason and needed +to log that fact. Without a text-based error log you'd never know +anything was wrong, because Apache would be trying to log a database +connection error to the database... you get the point. + +
+Error logs are usually not very high-traffic and are really best left +as text files on a web server machine. + +
+ +
+As of this writing, no. The Apache Group significantly altered the +module API with the release of Apache 2.0. All modules written for +1.3, including mod_log_sql, will not work with 2.0. + +
+mod_log_sql will eventually be ported to Apache 2.x, but not immediately. +It is going to take some time, and there are other features that have +higher priority. Please sign up for the announcements list (on the +main website) or monitor the website for updates to learn when the +port (and other releases) are available. + +
+<OPINION>If you're a *NIX user, stick with Apache 1.3.x for now. +Major modules like mod_ssl and PHP are not even ready for 2.0 yet, +and the main benefits in 2.0 are for Win32 users anyway. Apache 1.3.x +is rock-stable and performs equally well on *NIX as 2.0.</OPINION> + +
+ +
+It depends! This is not determined by mod_log_sql. mod_log_sql +relies on a connection command that is supplied in the MySQL API, +and that command is somewhat intelligent. How it works: + +
+ +
+ +
+Please contact the maintainer (chris@grubbybaby.com)! Your +comments, suggestions, bugfixes, bug catches, and usage testimonials +are always welcome. As free software, mod_log_sql is intended to +be a community effort - any code contributions or other ideas will +be fully and openly credited, of course. + +
+ +
+ +
+This occurs if you compiled PHP with MySQL database support. PHP utilizes +its internal, bundled MySQL libraries by default. These conflict with +the ``real'' MySQL libraries linked by mod_log_sql, causing +the segmentation fault. + +
+The solution is to configure PHP to link against the real MySQL libraries +and recompile mod_php. Apache will run properly once the modules +are all using the same version of the MySQL libraries. + +
+ +
+If you do not see any entries in the access_log, then something is +preventing the inserts from happening. This could be caused by several +things: + +
+ +
+First examine the MySQL log that you established in step 6 +of section 3.1. Ensure that the INSERT statements are +not being rejected because of a malformed table name or other typographical +error. By enabling that log, you instructed MySQL to log every connection +and command it receives - if you see no INSERT attempts in the log, +the module isn't successfully connecting to the database. If you see +nothing at all in the log - not even a record of your administrative +connection attempts, then you did not enable the log correctly. If +you do see INSERT attempts but they are failing, the log should tell +you why. + +
+Second, confirm that your LOGSQL* directives are all correct. + +
+Third, examine the Apache error logs for messages from mod_log_sql; +the module will offer hints as to why it cannot connect, etc. + +
+The next thing to do is recompile the module with debugging output +activated. change the "#undef DEBUG" on line 8 +of mod_log_sql.c to "#define DEBUG" and recompile/reinstall. +The module will now output copious notes about what it is doing, and +this will help you (and the maintainer) solve the problem. In order +to see the debugging messages, ensure that you make them visible using +the LOGLEVEL directive in the main server config +as well as in each VIRTUALHOST config: + +
+ +
+ErrorLog /var/log/httpd/server-messages +
+ +
+At a minimum, LOGSQLDATABASE and LOGSQLLOGININFO +must be defined in order for the module to be able to establish a +database link. If these are not defined or are incomplete you will +receive this error message. + +
+ +
+The rule of thumb: if you have n webservers each configured +to support y MAXCLIENTS, then your database must be +able to handle simultenous connections in the worst +case. Certainly you must use common sense, consider reasonable traffic +expectations and structure things accordingly. + +
+Tweaking my.cnf to scale to high connection loads is imperative. But +if hardware limitations prevent your MySQL server from gracefully +handling the number of incoming connections, it would be beneficial +to upgrade the memory or CPU on that server in order to handle the +load. + +
+Jeremy Zawodny, a highly respected MySQL user and contributor to Linux +Magazine, has this very helpful and highly appropriate article on +tuning MySQL: http://jeremy.zawodny.com/blog/archives/000173.html + +
+Please remember that mod_log_sql's overriding principle is performance +- that is what the target audience demands and expects. Other database +logging solutions do not open and maintain many database connections, +but their performance suffers drastically. For example, pgLOGd funnels +all log connections through a separate daemon that connects to the +database, but that bottlenecks the entire process. mod_log_sql achieves +performance numbers an order of magnitude greater than the alternatives +because it dispenses with the overhead associated with rapid connection +cycling, and it doesn't attempt to shoehorn all the database traffic +through a single extra daemon or proxy process. + +
+ +
+This message may appear every now and then in your Apache error log, +especially on very lightly loaded servers. This doesn't mean that +anything is necessarily wrong. Within each httpd child process, mod_log_sql +will open (and keep open) a connection to the MySQL server. MySQL, +however, will close connections that haven't been used in a while; +the default timeout is 8 hours. When this occurs, mod_log_sql will +notice and re-open the connection. That event is what is being logged, +and looks like this: + +
+ +
+ API said: error 2013, Lost connection to MySQL server during query + +
+[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: reconnect successful + +
+[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: second attempt successful +
+ +
+ +
+mod_log_sql scales to very high loads. Apache 1.3.22 + mod_log_sql +was benchmarked using the "ab" (Apache Bench) program +that comes with the Apache distribution; here are the results. + +
+Overall configuration: + +
+ +
+ +
+KeepAlive On + +
+MaxKeepAliveRequests 100 + +
+KeepAliveTimeout 15 + +
+MinSpareServers 5 + +
+StartServers 10 + +
+MaxSpareServers 15 + +
+MaxClients 256 + +
+MaxRequestsPerChild 5000 + +
+LogSQLTransferLogFormat AbHhmRSsTUuvc + +
+LogSQLWhichCookie Clicks + +
+CookieTracking on + +
+CookieName Clicks +
+ +
+Ten total ab runs were conducted: five with MySQL logging enabled, +and five with all MySQL directives commented out of httpd.conf. Then +each five were averaged. The results: + +
+ +
+If you run this benchmark yourself, take note of three things: + +
+ +
+mysql> optimize table access_log; +
+ +
+Short answer: you shouldn't be worried. + +
+Long answer: you might be evaluating at the output of ``ps -aufxw'' +and becoming alarmed at all the 7MB httpd processes or 22MB mysqld +children that you see. Don't be alarmed. It's true that mod_log_sql +opens and holds open many MySQL connections: each httpd child maintains +one open database connection (and holds it open for performance reasons). +Four webservers, each running 20 Apache children, will hold open 80 +MySQL connections, which means that your MySQL server needs to handle +80 simultaneous connections. In truth, your MySQL server needs to +handle far more than that if traffic to your website spikes and the +Apache webservers spawn off an additional 30 children each... + +
+Fortunately the cost reported by 'ps -aufxw' is deceptive. This is +due to an OS memory-management feature called ``copy-on-write.'' +When you have a number of identical child processes (e.g. Apache, +MySQL), it would appear in ``ps'' as though each one occupies +a great deal of RAM - as much as 7MB per httpd child! In actuality +each additional child only occupies a small bit of extra memory - +most of the memory pages are common to each child and therefore shared +in a ``read-only'' fashion. The OS can get away with this because +the majority of memory pages for one child are identical across all +children. Instead of thinking of each child as a rubber stamp of the +others, think of each child as a basket of links to a common memory +area. + +
+A memory page is only duplicated when it needs to be written to, hence +``copy-on-write.'' The result is efficiency and decreased memory +consumption. ``ps'' may report 7MB per child, but it might really +only ``cost'' 900K of extra memory to add one more child. It is +not correct to assume that 20 Apache +children with a VSZ of 7MB each equals + of memory +consumption - the real answer is much, much lower. The same ``copy-on-write'' +rules apply to all your MySQL children: 40 mysqld children @ 22MB +each do not occupy 880MB of RAM. + +
+The bottom line: although there is a cost to spawn extra httpd or +mysqld children, that cost is not as great as ``ps'' would lead +you to believe. + +
+ +
+If you have exhausted all the tuning possibilities on your existing +server, it is probably time you evaluated the benefits of clustering +two or more webservers together in a load-balanced fashion. In fact, +users of such a setup are mod_log_sql's target audience! + +
+ +
+There are several. + +
+ +
+If after understanding these problems you still wish to enable delayed +inserts, section 3.5.4 discusses how. + +
+ +
+ +
+Proper usage of the Apache runtime SERVERNAME directive and +the directive USECANONICALNAME ON (or DNS) are necessary +to prevent this problem. ``On'' is the default for USECANONICALNAME, +and specifies that self-referential URLs are generated from the SERVERNAME +part of your VirtualHost: + +
+
+With UseCanonicalName on (and in all versions prior to 1.3) Apache +will use the ServerName and Port directives to construct the canonical +name for the server. With UseCanonicalName off Apache will form self-referential +URLs using the hostname and port supplied by the client if any are +supplied (otherwise it will use the canonical name, as defined above). +[From the Apache documentation http://httpd.apache.org/docs/mod/core.html#usecanonicalname] + ++The module inherits Apache's ``knowledge'' about the server name +being accessed. As long as those two directives are properly configured, +mod_log_sql will log to only one table per virtual host while using +LOGSQLMASSVIRTUALHOSTING. + +
+ +
+mod_log_sql would be virtually useless if there weren't a way for +you to extract the data from your database in a somewhat meaningful +fashion. To that end there's a Perl script enclosed with the distribution. +That script (make_combined_log.pl) is designed to extract N-many +days worth of access logs and provide them in a Combined Log Format +output. You can use this very tool right in /etc/crontab to extract +logs on a regular basis so that your favorite web analysis tool can +read them. Or you can examine the Perl code to construct your own +custom tool. + +
+For example, let's say that you want your web statistics updated once +per day in the wee hours of the morning. A good way to accomplish +that could be the following entries in /etc/crontab: + +
+ +
+05 04 * * * root make_combined_log.pl 1 www.grubbybaby.com > /var/log/temp01 + +
+# Run webalizer on httpd log + +
+30 04 * * * root webalizer -c /etc/webalizer.conf; rm -f /var/log/temp01 +
+ +
+/usr/local/sbin/make_combined_log.pl 1 www.yourdomain.com > /var/log/httpd/templog + +
+/usr/local/bin/webalizer -q -c /etc/webalizer.conf + +
+rm -f /var/log/httpd/templog +
+ +
+A number of people like to log mod_usertrack cookies in their Apache +TransferLog to aid in understanding their visitors' clickstreams. +This is accomplished, for example, with a statement as follows: + +
+ +
+First make sure you have a column called "cookie" +in the MySQL database to hold the cookies, which can be done as follows +if you already have a working database: + +
+ +
+ +
+ CookieTracking on + +
+ CookieStyle Cookie + +
+ CookieName Foobar + +
+ LogSQLTransferLogFormat huSUsbTvRAc + +
+ LogSQLWhichCookie Foobar + +
+</VirtualHost> +
+Recap: the 'c' character activates cookie logging, and the +LOGSQLWHICHCOOKIE directive chooses which cookie to +log. + +
+FYI, you are advised NOT to use COOKIESTYLE COOKIE2 - it +seems that even newer browsers (IE 5.5, etc.) have trouble with the +new COOKIE2 (RFC 2965) format. Just stick with the standard COOKIE +format and you'll be fine. + +
+Perform some hits on your server and run a select: + +
+ +
+
request_uri | +cookie | +
/mod_log_sql/ | +ool-18e4.dyn.optonline.net.130051007102700823 | +
/mod_log_sql/usa.gif | +ool-18e4.dyn.optonline.net.130051007102700823 | +
/mod_log_sql/style_1.css | +ool-18e4.dyn.optonline.net.130051007102700823 | +
+ +
+
+ +
+As of version 1.17, you have a choice in how you want cookie logging +handled. + +
+If you are interested in logging only one cookie per request, follow +the instructions in section 4.4.3 above. That cookie will +be logged to a column in the regular access_log table, and the actual +cookie you want to log is specified with LOGSQLWHICHCOOKIE. +Don't forget to specify the 'c' character in LOGSQLTRANSFERLOGFORMAT. + +
+If, however, you need to log multiple cookies per request, you must +employ the LOGSQLWHICHCOOKIES (note the plural) directive. +The cookies you specify will be logged to a separate table (as discussed +in section 3.5.2), and entries in that table will be +linked to the regular access_log entries via the unique ID that is +supplied by mod_unique_id. Without mod_unique_id the information +will still be logged but you will be unable to correlate which cookies +go with which access-requests. Furthermore, with LOGSQLWHICHCOOKIES, +you do not need to include the 'c' character in LOGSQLTRANSFERLOGFORMAT. + +
+LOGSQLWHICHCOOKIE and LOGSQLWHICHCOOKIES can coexist +without conflict because they operate on entireley different tables, +but you're better off choosing the one you need. + +
+ +
+Note: you do not need to compile SSL support into mod_log_sql +in order to simply use it with a secure site. You only need to compile +SSL support into mod_log_sql if you want to log SSL-specific data +such as the cipher type used, or the keysize that was negotiated. +If that information is unimportant to you, you can ignore this FAQ. + +
+By adding certain characters to your LOGSQLTRANSFERLOGFORMAT +string you can tell mod_log_sql to log the SSL cipher, the SSL keysize +of the connection, and the maximum keysize that was available. This +would let you tell, for example, which clients were using only export-grade +security to access your secure software area. + +
+You can compile mod_log_sql with SSL logging support if you have +the right packages installed. If you already have an SSL-enabled Apache +then you by definition have the correct packages already installed: +OpenSSL and mod_ssl. + +
+You need to ensure that your database is set up to log the SSL data. +Issue the following commands to MySQL if your access table does not +already have them: + +
+ +
+alter table access_log add column ssl_keysize smallint unsigned; + +
+alter table access_log add column ssl_maxkeysize smallint unsigned; +
+ +
+ LogSQLTransferLogFormat AbHhmRSsTUuvcQqz + +
+</VirtualHost> +
+Restart Apache, then perform some hits on your server. Then run the +following select statement: + +
+ +
+from access_log where ssl_cipher is not null; + +
+
remote_host | +request_uri | +ssl_cipher | +ssl_keysize | +ssl_maxkeysize | +
216.190.52.4 | +/dir/somefile.html | +RC4-MD5 | +128 | +128 | +
216.190.52.4 | +/dir/somefile.gif | +RC4-MD5 | +128 | +128 | +
216.190.52.4 | +/dir/somefile.jpg | +RC4-MD5 | +128 | +128 | +
+ +
+
+This document was generated using the +LaTeX2HTML translator Version 2002-1 (1.68) +
+Copyright © 1993, 1994, 1995, 1996,
+Nikos Drakos,
+Computer Based Learning Unit, University of Leeds.
+
+Copyright © 1997, 1998, 1999,
+Ross Moore,
+Mathematics Department, Macquarie University, Sydney.
+
+The command line arguments were:
+ latex2html -local_icons -show_section_numbers -split 4 -navigation -noindex_in_navigation -contents_in_navigation -dir Documentation/HTML Documentation/documentation.tex
+
+The translation was initiated by Chris Powell on 2002-12-18
+