Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85fe4cc

Browse files
committed
Contribution for logging Apache Web stats to PostgreSQL
From: Terry Mackintosh <terry@terrym.com>
1 parentd15544c commit85fe4cc

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

‎contrib/apache_logging/README

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
HOW TO get Apache to log to PostgreSQL
2+
3+
First, this is intended mostly as a starting point, an example of how to do it.
4+
5+
The file 'httpconf.txt' is commented and contains two example lines to make
6+
this work, a custom log format, and a line that sends the log data to psql.
7+
I think that the comments in this file should be sufficient.
8+
9+
The file 'apachelog.sql' is a little SQL to create the table and grant
10+
permissions to it.
11+
12+
You must:
13+
14+
1. Already have 'nobody' (or what ever your web server runs as) as a valid
15+
PostgreSQL user.
16+
17+
2. Create the database to hold the log, (example 'createdb www_log')
18+
19+
3. Edit the file 'apachelog.sql' and change the name of the table to what
20+
ever you used in step 2. ALSO if need be, change the name 'nobody' in
21+
the grant statement.
22+
23+
4. As an appropriate user (postgres is ok), do 'psql www_log < apachelog.sql'.
24+
This should have created the table and granted access to it.
25+
26+
5. SAVE A COPY OF YOUR httpd.conf !!!
27+
28+
6. Edit httpd.conf, add the two lines in the example file as appropriate,
29+
IN THE ORDER IN WHICH THEY APPEAR. This is simple for a single server,
30+
but a little more complex for virtual hosts, but if you set up virtual
31+
hosts, then you should know were to put these lines.
32+
33+
7. Down and restart your httpd. I do it on Red Hat 4.1 like this:
34+
/etc/rc.d/init.d/httpd.init stop
35+
then
36+
/etc/rc.d/init.d/httpd.init start
37+
OR I understand you can send it a signal 16 like 'kill -16 <pid>' and do it.
38+
39+
8. I should be working, query the web server about 30 or more times then look
40+
in the db and see what you have, if nothing then query the web server
41+
30 or 50 more time and then check. If still nothing, look in the server's
42+
error log to see what is going on. But you should have data.
43+
44+
NOTES:
45+
The log data is cached some where, and so will not appear INSTANTLY in the
46+
database! I found that it took around 30 queries of the web server, then
47+
many rows are written to the db at once.
48+
49+
ALSO, I leave it up to you to create any indexes on the table that you want.
50+
51+
The error log can (*I think*) also be sent to PostgreSQL in the same fashion.
52+
53+
At some point in the future, I will be writing some PHP to interface to this
54+
and generate statistical type reports, so check my site once and a while if
55+
you are interested it this.
56+
57+
Terry Mackintosh <terry@terrym.com>
58+
http://www.terrym.com
59+
60+
Have fun ... and remember, this is mostly just intended as a stating point,
61+
not as a finished idea.

‎contrib/apache_logging/apachelog.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
droptable access;
2+
CREATETABLEaccess (hostchar(200), identchar(200), authuserchar(200), accdate datetime, requestchar(500), ttime int2, status int2, bytes int4) archive= none;
3+
grant allon access to nobody;

‎contrib/apache_logging/httpconf.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This is mostly the same as the default, except for no square brakets around
2+
# the time or the extra timezone info, also added the download time, 3rd from
3+
# the end, number of seconds.
4+
5+
LogFormat "insert into access values ( '%h', '%l', '%u', '%{%d/%b/%Y:%H:%M:%S}t', '%r', %T, %s, %b );"
6+
7+
8+
# The above format ALMOST eleminates the need to use sed, except that I noticed
9+
# that when a frameset page is called, then the bytes transfered is '-', which
10+
# will choke the insert, so replaced it with '-1'.
11+
12+
TransferLog '| su -c "sed \"s/, - );$/, -1 );/\" | /usr/local/pgsql/bin/psql www_log" nobody'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp