ข่าว: ข่าวประกาศ

  • 18 พฤษภาคม 2024, 14:24:38

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ผู้เขียน หัวข้อ: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat  (อ่าน 29458 ครั้ง)

admin

  • Administrator
  • Hero Member
  • *****
  • กระทู้: 3820
    • ดูรายละเอียด
    • อีเมล์
แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« เมื่อ: 10 สิงหาคม 2008, 02:33:24 »
ในการเก็บ Logfile นั้น ทางหาดใหญ่อินเตอร์เน็ตจะมีการจัดเก็บ Logfile ด้วยกัน 2 ส่วน สำคัญคือ

1. Traffic Log เพื่อใช้สำหรับตรวจสอบการใช้งาน และการเชื่อมต่อไปยัง Internet ของเครื่องลูกข่าย
2. Squid Log เพื่อใช้สำหรับตรวจสอบการใช้งาน WebSite ของเครื่องลูกข่าย

หัวข้อนี้จะนำเสนอวิธี การแปลง time stamp ใน access.log ของ squid

โดยปกติแล้ว access.log ของ squid นั้น จะมีรูปแบบดังนี้

โค๊ด: [Select]
1218284884.358      0 192.168.200.114 TCP_MEM_HIT/200 2304 GET http://sf.gg.in.th/index.html - NONE/- text/html
1218284884.399     40 192.168.200.114 TCP_MEM_HIT/200 1364 GET http://sf.gg.in.th/images/mom/bg.gif - NONE/- image/gif
1218284884.400      0 192.168.200.114 TCP_MEM_HIT/200 4993 GET http://sf.gg.in.th/images/mom/bt_gosite.jpg - NONE/- image/jpeg
1218284885.094    150 192.168.200.114 TCP_MEM_HIT/200 144979 GET http://sf.gg.in.th/images/mom/mom12aug08.swf - NONE/- application/x-shockwave-flash
1218284885.363    114 192.168.200.118 TCP_MISS/200 911 GET http://d.as.sanook.com/jserver/SITE=HI5.COM/AREA=HI5.MEMBER_HOME/AAMSZ=300X250/AGE=22/EY=9522/GENDER=M/LANG=TH/POSITION=POS.CENTER1/METHOD=JSCRIPT/PAGEID=555537165/ACC_RANDOM=425958387? - DIRECT/58.181.242.9 text/HTML
1218284885.460    158 192.168.200.114 TCP_MISS/200 798 GET http://sf.gg.in.th/truehitsstat.aspx?pagename=/SF_Mom/index.asp - DIRECT/61.90.203.111 text/html
1218284885.654    116 192.168.200.114 TCP_REFRESH_MISS/200 912 GET http://hits.truehits.in.th/data/s0028733.js - DIRECT/164.115.2.135 application/x-javascript
1218284885.667     12 192.168.200.114 TCP_HIT/200 5388 GET http://hits.truehits.in.th/func/th_donate_1.6.js - NONE/- text/javascript
1218284885.668      0 192.168.200.114 TCP_MEM_HIT/200 2838 GET http://hits.truehits.in.th/func/th_common_1.4.js - NONE/- text/javascript
1218284885.944    117 192.168.200.114 TCP_MISS/200 466 GET http://lvs.truehits.in.th/goggen.php?hc=s0028733&bv=10&rf=bookmark&web=CMppFCGwxF%2bGhHviFg4XYQ%3D%3D&bn=MSIE&ss=1280*1024&sc=32&sv=1.3&ck=y&ja=y&vt=6F4E8E49.13&fp=d&fv=9.0&truehitspage=SF/SF_Mom/index.asp&truehitsurl=http%3a//sf.gg.in.th/index.html - DIRECT/164.115.2.135 image/jpeg

โดยตัวเลขด้านหน้าจะหมายถึงเวลา ซึ่งอยู่ในรูปแบบ Unix Time stamp

ผมเคยเสนอวิธีการแปลงเวลาใน logfile ด้วยการใช้ perl script ไปครั้งนึงแล้ว

วันนี้จะเสนออีกวิธีการ ซึ่งง่ายและสะดวกกว่า โดยการใช้งาน  logformat

โดยทำการเพิ่ม

logformat common %{%Y-%m-%d %H:%M:%S}tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
cache_access_log  /var/log/squid/access.log common


แทนที่

cache_access_log  /var/log/squid/access.log

ลงในไฟล์ /etc/squid/squid.conf

เสร็จแล้วทำการ reload config ของ squid ใหม่ ด้วยคำสั่ง

/etc/init.d/squid reload

 * Reloading Squid configuration files
   ...done.

เพียงแค่นี้ ก็จะได้ Logfile ในรูปแบบใหม่ ที่มีวันที่และเวลาเป็นแบบที่สามารถตรวจสอบได้ง่าย

โค๊ด: [Select]
2008-08-09 12:35:26      2 192.168.182.219 TCP_IMS_HIT/304 394 GET http://data.rockyou.com/crossdomain.xml - NONE/- application/xml
2008-08-09 12:35:26   1753 192.168.182.219 TCP_HIT/200 34499 GET http://c1.magmypic.com/usermags/e/8/e895491aacd795a9c0b530ed2ec6b6a9_4000.jpg - NONE/- image/jpeg
2008-08-09 12:35:27      1 192.168.182.219 TCP_MEM_HIT/200 3542 GET http://photos2.hi5.com/0047/941/361/JJBbwO941361-01.jpg - NONE/- image/jpeg
2008-08-09 12:35:27    987 192.168.182.121 TCP_MISS/200 17846 GET http://www.zheza.com/bandwidthtest.swf?1218285166265 - DIRECT/202.142.212.72 application/x-shockwave-flash
2008-08-09 12:35:27   1099 192.168.182.244 TCP_MISS/200 32126 GET http://forums.overclockzone.com/forums/forumdisplay.php?f=16&order=desc&page=2 - DIRECT/203.151.232.190 text/html
2008-08-09 12:35:27     47 192.168.182.219 TCP_HIT/200 3085 GET http://photos2.hi5.com/0046/820/421/Sfs8ZO820421-01.jpg - NONE/- image/jpeg
2008-08-09 12:35:27     45 192.168.182.219 TCP_HIT/200 3997 GET http://photos2.hi5.com/0046/054/857/y6a0Fk054857-01.jpg - NONE/- image/jpeg
2008-08-09 12:35:27    878 192.168.182.134 TCP_MISS/200 777 GET http://rad.msn.com/ADSAdClient31.dll?GetAd=&PG=IMUSX1 - DIRECT/65.55.15.124 text/html
2008-08-09 12:35:27    870 192.168.182.219 TCP_HIT/200 124453 GET http://cdn.rockyou.com/opensocial/common/js/scriptaculous/prototype.js - NONE/- application/x-javascript
2008-08-09 12:35:27   2084 192.168.182.219 TCP_HIT/200 35966 GET http://img.thzhost.com/i/13/16hg4.jpg - NONE/- image/jpeg
2008-08-09 12:35:27    560 192.168.182.219 TCP_MISS/200 948 GET http://data.rockyou.com/xml/glittertext/3/573/35736417.xml?1218285167765 - DIRECT/58.147.1.179 application/xml
2008-08-09 12:35:27    103 192.168.182.219 TCP_HIT/200 834 GET http://i207.photobucket.com/albums/bb267/tledakasa/violet.gif - NONE/- image/gif
2008-08-09 12:35:28    101 192.168.182.244 TCP_MISS/404 854 GET http://forums.overclockzone.com/forums/topbar.css - DIRECT/203.151.232.190 text/html

ลองนำไปทดสอบศึกษากันดูนะครับ
« แก้ไขครั้งสุดท้าย: 10 สิงหาคม 2008, 02:51:19 โดย admin »
<a href="http://www.hadyaiinternet.com/images/inetcafe.swf" target="_blank" rel="noopener noreferrer" class="bbc_link bbc_flash_disabled new_win">http://www.hadyaiinternet.com/images/inetcafe.swf</a>

mjionline

  • Newbie
  • *
  • กระทู้: 2
    • ดูรายละเอียด
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #1 เมื่อ: 10 สิงหาคม 2008, 17:05:43 »
ผมขอรบกวนสอบถาม file /var/log/squid/access.log ตัวนี้ในเครื่องของเราจะเก็บไฟล์นี้ไว้ระยะเท่าไร่ครับ

golfberserk

  • ตัวแทนที่ได้รับการแต่งตั้ง
  • Full Member
  • *****
  • กระทู้: 166
    • ดูรายละเอียด
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #2 เมื่อ: 11 สิงหาคม 2008, 22:33:13 »
[root@gateway ~]# service squid restart
Stopping squid: 2008/08/11 15:23:06| parseConfigFile: line 7 unrecognized: 'logf                                             ormat common %{%Y-%m-%d %H:%M:%S}tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A                                              %mt'
....                                                       [  OK  ]
Starting squid: .                                          [  OK  ]
[
ขึ้นแบบนี้อ่ะครับ

ปล. ใช้ squid2.5  ของ CC4.2 นะครับ ยังม่ะได้ลองใน Ubuntu

PoR

  • Administrator
  • Hero Member
  • *****
  • กระทู้: 833
    • ดูรายละเอียด
    • www.hadyaiinternet.com
    • อีเมล์
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #3 เมื่อ: 11 สิงหาคม 2008, 22:43:32 »
[root@gateway ~]# service squid restart
Stopping squid: 2008/08/11 15:23:06| parseConfigFile: line 7 unrecognized: 'logf                                             ormat common %{%Y-%m-%d %H:%M:%S}tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A                                              %mt'
....                                                       [  OK  ]
Starting squid: .                                          [  OK  ]
[
ขึ้นแบบนี้อ่ะครับ

ปล. ใช้ squid2.5  ของ CC4.2 นะครับ ยังม่ะได้ลองใน Ubuntu

ขึ้นเหมือนกันเลยนะครับ แต่ก็ใช้งานได้ตรวจสอบ log แล้วก็ไม่มีอะไรเปลี่ยนแปลงด้วยใช่หรือเปล่าครับ
Hadyaiinternet R&D LAB ยินดีให้บริการทุกท่าน
Call center โทร 084-9695561
E-mail:por_pk@hotmail.com

iCafe

  • Newbie
  • *
  • กระทู้: 45
    • ดูรายละเอียด
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #4 เมื่อ: 11 สิงหาคม 2008, 22:57:39 »
[root@gateway ~]# service squid restart
Stopping squid: 2008/08/11 15:23:06| parseConfigFile: line 7 unrecognized: 'logf                                             ormat common %{%Y-%m-%d %H:%M:%S}tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A                                              %mt'
....                                                       [  OK  ]
Starting squid: .                                          [  OK  ]
[
ขึ้นแบบนี้อ่ะครับ

ปล. ใช้ squid2.5  ของ CC4.2 นะครับ ยังม่ะได้ลองใน Ubuntu

ใน squid2.5 ใช้ไม่ได้ครับ
Best Regards,

zombie01

  • Newbie
  • *
  • กระทู้: 3
    • ดูรายละเอียด
    • อีเมล์
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #5 เมื่อ: 16 สิงหาคม 2008, 18:18:20 »
พอจะมีวิธีทำให้ squid 2.5 ใช้งาน time stamp แบบนี้ได้หรือเปล่าครับ ขอบคุณครับ

iCafe

  • Newbie
  • *
  • กระทู้: 45
    • ดูรายละเอียด
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #6 เมื่อ: 16 สิงหาคม 2008, 20:12:06 »
ไม่มีครับ เพราะ 2.5 ไม่มีฟังชั่น logformat ครับ
Best Regards,

zombie01

  • Newbie
  • *
  • กระทู้: 3
    • ดูรายละเอียด
    • อีเมล์
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #7 เมื่อ: 17 สิงหาคม 2008, 08:28:51 »
ขอบคุณครับผม

pithawas

  • Newbie
  • *
  • กระทู้: 2
    • ดูรายละเอียด
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #8 เมื่อ: 25 สิงหาคม 2008, 16:55:23 »
ขอความชี้แนะหน่อยนะครับ พอดีผมใช้ win2003 แล้วผมต้องไปใช้คำสั่งได้ที่ใหนครับ หรื่อว่าผมต้องลงโปรแกรมอะไรเพิ่ม
หรือป่าวครับ var/log/squid/asscce.log   คำสั่งนี้ผมต้องไปใช้กับตรงใหนครับ ขอความกรุณาชี้แนะด้วยนะครับ
จะได้เป็นความรู้เพิ่มเติม
 ขอบคุณครับ

zombie01

  • Newbie
  • *
  • กระทู้: 3
    • ดูรายละเอียด
    • อีเมล์
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #9 เมื่อ: 09 กันยายน 2008, 22:17:01 »
มาโพสตอบเองเลยนะครับ ที่เคยถามไว้
timestamp ใน squid 2.5

#vi /etc/squid/squid.conf
หาบรรทัดที่ีมี
# emulate_httpd_log on
เอาเครื่องหมาย # หน้า emulate_httpd_log on ออก
กด esc
กด shift + :
พิมพ์ x เอนเทอร์
พิมพ์ #service squid reload
และไปดูผลที่
#tail -f /var/log/squid/access.log

ได้ผลแน่นอนครับ

PoR

  • Administrator
  • Hero Member
  • *****
  • กระทู้: 833
    • ดูรายละเอียด
    • www.hadyaiinternet.com
    • อีเมล์
Re: แปลง time stamp ใน access.log ของ squid โดยใช้ logformat
« ตอบกลับ #10 เมื่อ: 09 กันยายน 2008, 22:54:35 »
ขอบคุณที่แวะมาให้ความรู้นะครับ ผมลองแล้วได้ผลจรงๆนะครับ

Hadyaiinternet R&D LAB ยินดีให้บริการทุกท่าน
Call center โทร 084-9695561
E-mail:por_pk@hotmail.com