Поставил на freebsd 6.2 программу squidalyser для более тонкой настройки отчетности squid.
В файле squidalyser.sql есть пример куска лога от squid для просмотра в проге squidalyser:# MySQL dump 8.13
#
# Host: localhost Database: squid
#--------------------------------------------------------
# Server version 3.23.36#
# Table structure for table 'groups'
#CREATE TABLE groups (
id int(11) NOT NULL auto_increment,
group_name varchar(32) default NULL,
status int(11) default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;#
# Dumping data for table 'groups'
#
#
# Table structure for table 'logfile'
#CREATE TABLE logfile (
id int(11) NOT NULL auto_increment,
remotehost varchar(255) default NULL,
rfc931 varchar(64) default NULL,
authuser varchar(64) default NULL,
request text,
status int(11) default NULL,
bytes int(11) default NULL,
time float(10,3) default NULL,
PRIMARY KEY (id),
KEY user_time (rfc931,time),
KEY time_index (time),
KEY user_status (rfc931,status)
) TYPE=MyISAM;#
# Dumping data for table 'logfile'
#INSERT INTO logfile VALUES (1,'127.0.0.1','richard','-','http://images2.slashdot.org/Slashdot/pc.gif?',200,387,1008797504.000);
INSERT INTO logfile VALUES (2,'127.0.0.1','richard','-','http://slashdot.org/',200,33885,1008797504.000);
INSERT INTO logfile VALUES (3,'127.0.0.1','richard','-','http://images.slashdot.org/banner/rack0164en.gif?',200,12441,1008797504.000);
INSERT INTO logfile VALUES (4,'127.0.0.1','richard','-','http://images2.slashdot.org/Slashdot/pc.gif?',200,387,1008797504.000);
INSERT INTO logfile VALUES (5,'127.0.0.1','richard','-','http://images.slashdot.org/banner/inte5044en.gif?',200,460,1008797504.000);
INSERT INTO logfile VALUES (6,'127.0.0.1','richard','-','http://ad.uk.doubleclick.net/ad/N2044.itportal.uk.komet/B465...',302,616,1008797568.000);
INSERT INTO logfile VALUES (7,'127.0.0.1','richard','-','http://slashdot.org/article.pl?',200,80168,1008797568.000);
INSERT INTO logfile VALUES (8,'127.0.0.1','richard','-','http://www.theregister.co.uk/Themes/Normal/Masthead.gif',200,10023,1008797568.000);
INSERT INTO logfile VALUES (9,'127.0.0.1','richard','-','http://www.theregister.co.uk/Themes/Normal/Slogan.gif',200,1990,1008797568.000);
INSERT INTO logfile VALUES (10,'127.0.0.1','richard','-','http://www.theregister.co.uk/Themes/Normal/SearchSmall.gif',200,2325,1008797568.000);
INSERT INTO logfile VALUES (11,'127.0.0.1','richard','-','http://www.theregister.co.uk/images/go.gif',200,730,1008797568.000);
INSERT INTO logfile VALUES (12,'127.0.0.1','richard','-','http://www.theregister.co.uk/images/advert.gif',200,945,1008797568.000);
INSERT INTO logfile VALUES (13,'127.0.0.1','richard','-','http://www.domainbuster.com/bizad.gif',200,12031,1008797568.000);
INSERT INTO logfile VALUES (14,'127.0.0.1','richard','-','http://www.theregister.co.uk/media/684.gif',200,24422,1008797568.000);
INSERT INTO logfile VALUES (15,'127.0.0.1','richard','-','http://www.theregister.co.uk/Themes/Normal/Sections.gif',200,675,1008797632.000);
INSERT INTO logfile VALUES (16,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/1-on.gif',200,935,1008797632.000);
INSERT INTO logfile VALUES (17,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/53-off.gif',200,1052,1008797632.000);
INSERT INTO logfile VALUES (18,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/4-off.gif',200,689,1008797632.000);
INSERT INTO logfile VALUES (19,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/54-off.gif',200,953,1008797632.000);
INSERT INTO logfile VALUES (20,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/3-off.gif',200,800,1008797632.000);
INSERT INTO logfile VALUES (21,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/6-off.gif',200,651,1008797632.000);
INSERT INTO logfile VALUES (22,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/56-off.gif',200,944,1008797632.000);
INSERT INTO logfile VALUES (23,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/5-off.gif',200,693,1008797632.000);
INSERT INTO logfile VALUES (24,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/7-off.gif',200,691,1008797632.000);
INSERT INTO logfile VALUES (25,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/55-off.gif',200,864,1008797632.000);
INSERT INTO logfile VALUES (26,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/28-off.gif',200,706,1008797632.000);
INSERT INTO logfile VALUES (27,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/29-off.gif',200,864,1008797632.000);
INSERT INTO logfile VALUES (28,'127.0.0.1','richard','-','http://www.theregister.co.uk/media/New.Net/Logo.gif',200,2965,1008797632.000);
INSERT INTO logfile VALUES (29,'127.0.0.1','richard','-','http://www.theregister.co.uk/media/New.Net/Go.gif',200,684,1008797632.000);
INSERT INTO logfile VALUES (30,'127.0.0.1','richard','-','http://www.theregister.co.uk/',200,29743,1008797632.000);
INSERT INTO logfile VALUES (31,'127.0.0.1','richard','-','http://ad.uk.doubleclick.net/ad/theregister.co.uk/regindex;a...?',302,517,1008797632.000);
INSERT INTO logfile VALUES (32,'127.0.0.1','richard','-','http://130.94.70.82/~web_ani/A6770AAF.gif',200,5753,1008797632.000);
INSERT INTO logfile VALUES (33,'127.0.0.1','richard','-','http://secure.webconnect.net/cgi-bin/webconnecthome.dll?',302,492,1008797632.000);
INSERT INTO logfile VALUES (34,'127.0.0.1','richard','-','http://ad.uk.doubleclick.net/adl/theregister.co.uk/regindex;...?',200,901,1008797632.000);
INSERT INTO logfile VALUES (35,'127.0.0.1','richard','-','http://www.theregister.co.uk/images/reg_bullet.gif',200,1014,1008797632.000);
INSERT INTO logfile VALUES (36,'127.0.0.1','richard','-','http://www.theregister.co.uk/nav/1-off.gif',200,763,1008797632.000);
INSERT INTO logfile VALUES (37,'127.0.0.1','richard','-','http://ad.uk.doubleclick.net/ad/theregister.co.uk/softhome;a...?',302,517,1008797632.000);
INSERT INTO logfile VALUES (38,'127.0.0.1','richard','-','http://www.theregister.co.uk/content/4/23465.html',200,20487,1008797632.000);
INSERT INTO logfile VALUES (39,'127.0.0.1','richard','-','http://ad.uk.doubleclick.net/adl/theregister.co.uk/softhome;...?',200,821,1008797632.000);
INSERT INTO logfile VALUES (40,'127.0.0.1','richard','-','http://www.theregister.co.uk/media/646.gif',200,12499,1008797632.000);
INSERT INTO logfile VALUES (41,'127.0.0.1','david','-','http://www.perlmonks.org/',200,31007,1008797632.000);
INSERT INTO logfile VALUES (42,'127.0.0.1','david','-','http://perlmonks.org/images/clearpixel.gif',200,458,1008797632.000);
INSERT INTO logfile VALUES (43,'127.0.0.1','david','-','http://perlmonks.org/images/clearpixel.gif',200,458,1008797632.000);
INSERT INTO logfile VALUES (44,'127.0.0.1','david','-','http://perlmonks.org/images/robo.gif',200,3170,1008797632.000);
INSERT INTO logfile VALUES (45,'127.0.0.1','david','-','http://perlmonks.org/images/bluesearch.gif',200,1645,1008797632.000);
INSERT INTO logfile VALUES (46,'127.0.0.1','david','-','http://perlmonks.org/images/clearpixel.gif',200,458,1008797632.000);
INSERT INTO logfile VALUES (47,'127.0.0.1','david','-','http://perlmonks.org/images/blueperlmonkssm.gif',200,1148,1008797632.000);
INSERT INTO logfile VALUES (48,'127.0.0.1','david','-','http://perlmonks.org/images/monasterygatestitle2.jpg',200,4367,1008797632.000);
INSERT INTO logfile VALUES (49,'127.0.0.1','david','-','http://perlmonks.org/images/dibona_sm.gif',200,3778,1008797632.000);
INSERT INTO logfile VALUES (50,'127.0.0.1','david','-','http://www.perlmonks.org/index.pl?',200,23434,1008797632.000);
INSERT INTO logfile VALUES (51,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/',200,6186,1008797696.000);
INSERT INTO logfile VALUES (52,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/fr1.jpg',200,3015,1008797696.000);
INSERT INTO logfile VALUES (53,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/celt-bg.gif',200,1029,1008797696.000);
INSERT INTO logfile VALUES (54,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/dr1.jpg',200,3198,1008797696.000);
INSERT INTO logfile VALUES (55,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/cottage.jpg',200,3382,1008797696.000);
INSERT INTO logfile VALUES (56,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/bed1.jpg',200,2720,1008797696.000);
INSERT INTO logfile VALUES (57,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/fr2.jpg',200,3237,1008797696.000);
INSERT INTO logfile VALUES (58,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/bed2.jpg',200,2787,1008797696.000);
INSERT INTO logfile VALUES (59,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/tour/cottage.htm',200,1400,1008797696.000);
INSERT INTO logfile VALUES (60,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/arrows/left.gif',200,607,1008797696.000);
INSERT INTO logfile VALUES (61,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/arrows/right.gif',200,603,1008797696.000);
INSERT INTO logfile VALUES (62,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/photos/cottage.jpg',200,43111,1008797696.000);
INSERT INTO logfile VALUES (63,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/tour/lr1.htm',200,1382,1008797696.000);
INSERT INTO logfile VALUES (64,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/photos/livingroom...',200,25322,1008797696.000);
INSERT INTO logfile VALUES (65,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/tour/lr2.htm',200,1360,1008797696.000);
INSERT INTO logfile VALUES (66,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/photos/livingroom...',200,26156,1008797696.000);
INSERT INTO logfile VALUES (67,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/tour/dr.htm',200,1388,1008797696.000);
INSERT INTO logfile VALUES (68,'127.0.0.1','simon','-','http://www.holidaywestwales.co.uk/graphics/photos/diningroom...',200,25226,1008797696.000);
INSERT INTO logfile VALUES (69,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/index.htm',200,9055,1008797760.000);
INSERT INTO logfile VALUES (70,'127.0.0.1','simon','-','http://www.abergwaun.com/whiteback.bmp',0,1496,1008797760.000);
INSERT INTO logfile VALUES (71,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic05small.jpg',200,8537,1008797760.000);
INSERT INTO logfile VALUES (72,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic07small.jpg',200,5468,1008797760.000);
INSERT INTO logfile VALUES (73,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic06small.jpg',200,7576,1008797760.000);
INSERT INTO logfile VALUES (74,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic01180.jpg',200,16578,1008797760.000);
INSERT INTO logfile VALUES (75,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic02big.jpg',200,9853,1008797760.000);
INSERT INTO logfile VALUES (76,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic08small.jpg',200,12485,1008797760.000);
INSERT INTO logfile VALUES (77,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/13150.jpg',200,7374,1008797760.000);
INSERT INTO logfile VALUES (78,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/15150.jpg',200,7676,1008797760.000);
INSERT INTO logfile VALUES (79,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/16150.jpg',200,11706,1008797760.000);
INSERT INTO logfile VALUES (80,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic11small.jpg',200,6412,1008797760.000);
INSERT INTO logfile VALUES (81,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/18150.jpg',200,9125,1008797760.000);
INSERT INTO logfile VALUES (82,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/20150.jpg',200,7289,1008797760.000);
INSERT INTO logfile VALUES (83,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/22150.jpg',200,9109,1008797760.000);
INSERT INTO logfile VALUES (84,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/24150.jpg',200,8511,1008797760.000);
INSERT INTO logfile VALUES (85,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic10small.jpg',200,7088,1008797760.000);
INSERT INTO logfile VALUES (86,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/14150.jpg',200,8032,1008797760.000);
INSERT INTO logfile VALUES (87,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic04small.jpg',200,9279,1008797760.000);
INSERT INTO logfile VALUES (88,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/21150.jpg',200,9206,1008797760.000);
INSERT INTO logfile VALUES (89,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/17150.jpg',200,11994,1008797760.000);
INSERT INTO logfile VALUES (90,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic03small.jpg',200,7352,1008797760.000);
INSERT INTO logfile VALUES (91,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic12small.jpg',200,5443,1008797760.000);
INSERT INTO logfile VALUES (92,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/19150.jpg',200,9775,1008797760.000);
INSERT INTO logfile VALUES (93,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic09small.jpg',200,5547,1008797760.000);
INSERT INTO logfile VALUES (94,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/23150.jpg',200,7457,1008797760.000);
INSERT INTO logfile VALUES (95,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/pic13small.jpg',200,9034,1008797760.000);
INSERT INTO logfile VALUES (96,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/lower16.htm',200,2418,1008797760.000);
INSERT INTO logfile VALUES (97,'127.0.0.1','simon','-','http://www.abergwaun.com/places/lowertown/16790.jpg',200,143854,1008797760.000);
INSERT INTO logfile VALUES (98,'127.0.0.1','andy','-','http://www.gnu.org/',200,11795,1008797760.000);
INSERT INTO logfile VALUES (99,'127.0.0.1','andy','-','http://www.gnu.org/graphics/gnu-head-sm.jpg',200,6366,1008797760.000);
INSERT INTO logfile VALUES (100,'127.0.0.1','andy','-','http://www.gnu.org/server/whatsnew.html',200,21039,1008797824.000);
INSERT INTO logfile VALUES (101,'127.0.0.1','andy','-','http://www.gnu.org/philosophy/freedom-or-power.html',200,7545,1008797824.000);
INSERT INTO logfile VALUES (102,'127.0.0.1','andy','-','http://www.gnu.org/graphics/philosophical-gnu-sm.jpg',200,6542,1008797824.000);#
# Table structure for table 'members'
#CREATE TABLE members (
id int(11) NOT NULL auto_increment,
group_id int(11) default NULL,
rfc931 varchar(64) default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;#
# Dumping data for table 'members'
#
#
# Table structure for table 'words_list'
#CREATE TABLE words_list (
id int(11) NOT NULL auto_increment,
word varchar(64) default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;#
# Dumping data for table 'words_list'
#Вопрос, как мне из файла access.log данные подставить в squidalyser.sql
сразу скажу, команда cp /usr/local/squid/log/access.log /usr/local/squidalyser/sql/squidalyser.sql мне не подходит, нужно так же как в файле *.sql все красиво подставить. В MySQL не силен, только недавно её начал изучать.
Могу предложить вот такой вот скрипт заносит лог access.log в Mysql
для создания таблицы вот скрипт на shmysql --user=root --password=pass --database=squid_stat --execute="drop table squid"
mysql --user=root --password=pass --database=squid_stat \
--execute="create table squid(time varchar(14),ip varchar(16),result_codes varchar(50) \
,bytes bigint unsigned default 0,method varchar(10),url varchar(255),short_url varchar(255),user varchar(30),hierarchy_code varchar(30));"Заносит только те строчки в БД из лога, которые по времени старше самой старой строчки в БД.
Если мой скрипт что-то не заносит, можно поправить, не сложно, добавить поле в таблице, и элемент массива @a с нужным индексом писать в это поле.массив @b сделан для записи в бд урл вида http://site.ru/
#!/usr/local/bin/perl
use DBI;$full_path='/var/log/squid/access.log';
$dbh = DBI->connect("DBI:mysql:squid_stat:localhost",root,pass);
$max_date_query="SELECT MAX(time) FROM squid;";
$sth = $dbh->prepare($max_date_query);
$sth->execute();
$max_date=$sth->fetchrow_array();
#print($max_date."\n");
open(F,$full_path) || die "Can't open traffic plain file";
$k=0;
$i=0;
while ($str=<F>)
{
$k++;
chomp($str);
@a=split('\s+',$str);
if (@a[0]>$max_date)
{
$i++;
@b=split('\/',@a[6]);
$ins_query="INSERT INTO squid (time, ip, result_codes, bytes, method, url, short_url,\
user, hierarchy_code) values ('".@a[0]."','".@a[2]."','".@a[3]."','".@a[4]."','".@a[5]."','".@a[6]."','".@b[0]."//".@b[2]."/"."','".@a[7]."','".@a[8]."');";
$sth = $dbh->prepare($ins_query);
$sth->execute();
}
};
print("The number of parsed strings is ".$k." and was added to database only ".$i." strings.\n");
close(F);
Когда запускаю твой второй скрипт переделанный под себя#!/usr/local/bin/perl
use DBI;$full_path='/var/log/squid/access.log';
$dbh = DBI->connect("DBI:mysql:squid_stat:localhost",root,pass);
$max_date_query="SELECT MAX(time) FROM squid;";
$sth = $dbh->prepare($max_date_query);
и т.д.пишет следующие строчки.
DBD::mysql::st execute failed: Table 'squid.squid' doesn't exist at ./2 line 9.
DBD::mysql::st fetchrow_array failed: fetch() without execute() at ./2 line 10.
The number of parsed strings is 2930 and was added to database only 2930 strings.
>[оверквотинг удален]
>$max_date_query="SELECT MAX(time) FROM squid;";
>$sth = $dbh->prepare($max_date_query);
>и т.д.
>
>пишет следующие строчки.
>
>DBD::mysql::st execute failed: Table 'squid.squid' doesn't exist at ./2 line 9.
>DBD::mysql::st fetchrow_array failed: fetch() without execute() at ./2 line 10.
>The number of parsed strings is 2930 and was added to database
>only 2930 strings.ДБ должна называться squid_stat табличка squid.
Он у тебя и пишет что не существует таблица squid.squid
>ДБ должна называться squid_stat табличка squid.
>Он у тебя и пишет что не существует таблица squid.squidУ меня БД называется не squid_stat, а squid
>
>>ДБ должна называться squid_stat табличка squid.
>>Он у тебя и пишет что не существует таблица squid.squid
>
>У меня БД называется не squid_stat, а squidЗНачит ты ее не создал, скрипт для создания таблицы не создает бд. ICQ 128352030
стучи, помогу
а я сразу в mysql кладу.
немного изменений в access_log.c и все.
Получается риалтайм
>а я сразу в mysql кладу.
>немного изменений в access_log.c и все.
>Получается риалтаймА пример у тебя скрипта есть, чтобы сразу в мускул кидать.