การติดตั้งระบบกราฟบันทึกปริมาณจราจรบนเครือข่ายด้วยโปรแกรม Mrtg


การติดตั้งระบบกราฟบันทึกปริมาณจราจรบนเครือข่ายด้วยโปรแกรม Mrtg

การติดตั้งระบบกราฟบันทึกปริมาณจราจรบนเครือข่ายด้วยโปรแกรม

วิธีติดตั้ง mrtg

  1. ต้องมีการติดตั้งโปรแกรม  apache มาก่อน ซึ่ง root directory ของ apache จะอยู่ที่  /var/www/html
    คำแนะนำติดตั้งโปรแกรม apache อยู่ที่โฮมเพจ
    http://rd.cc.psu.ac.th/content/view/19/46/

  2. ต้องมีการติดตั้งโปรแกรม net-snmp มาก่อน
    คำแนะนำติดตั้งโปรแกรม net-snmp อยู่ที่โฮมเพจ
    http://rd.cc.psu.ac.th/content/view/26/46/

  3. ติดตั้ง mrtg ด้วยคำสั่ง
    apt-get install mrtg

    ในกรณีที่ใช้ yum ให้เปลี่ยนคำว่า apt-get เป็น yum ดังตัวอย่าง
     yum install mrtg

  4. home directory ของ mrtg อยู่ที่  /var/www/mrtg

  5. คำแนะนำการใช้ mrtg อยู่ที่  /var/www/mrtg/index.hml

    **** fedora core 4 ไม่ได้ติดตั้งเอกสารคำแนะนำไว้ตามข้างบน
    แต่เป็นเอกสารอยู่ใน server แทน

  6. แก้ไขแฟ้ม /etc/httpd/conf.d/mrtg.conf
    เพื่ออนุญาติให้ทุก network สามารถอ่านข้อมูลได้ ดังตัวอย่าง
    <Location /mrtg>
        Order deny,allow
        Deny from all
        Allow from all
        Allow from 127.0.0.1
        # Allow from .example.com
    </Location>

  7. อย่าลืม reload httpd ด้วยคำสั่ง
    service  httpd  reload

  8. ตัวอย่างการติดตั้งสำหรับ server ชื่อ myhost.domain

    • ต้องตั้งค่า locale อย่าให้เป็น utf-8 ด้วยตัวอย่างคำสั่ง
      export LANG=en_US

    • สร้าง directory สำหรับเก็บข้อมูลแสดงผล
      mkdir /var/www/mrtg/myhost

    • สร้าง config file สำหรับ myhost
       cfgmaker  -global "options[_]:bits,growright" --global "workdir: /var/www/mrtg/myhost" [email protected] > /etc/mrtg/mrtg-myhost.cfg

    • ทดสอบสร้างภาพต้นแบบด้วยคำสั่ง
      mrtg /etc/mrtg/mrtg-myhost.cfg

    • สร้าง index.html สำหรับ homepage mrtg ของ myhost
      indexmaker --column=1 --output=/var/www/mrtg/myhost/index.html /etc/mrtg/mrtg-myhost.cfg

    • ตั้งค่าให้ mrtg บันทึกค่าทุกๆ 5 นาที ด้วยการสร้างแฟ้ม /etc/cron.d/mrtg-myhost ให้มีข้อความว่า
      0-59/5 * * * * root /usr/bin/mrtg /etc/mrtg/mrtg-myhost.cfg

    • สั่งให้ cron ทำงานใหม่ด้วยคำสั่ง
      service  crond  reload
      Reloading cron daemon configuration:                        [  OK  ]

  9. ทดสอบผลงานเรียกดูข้อมูลตัวอย่างได้ที่  http://mywebserver/mrtg/myhost

  10. ตัวอย่างการทำกราฟ TCP Establish connection

    • ใช้ข้อมูล tcpCurrEstab.0 จาก snmp
    • แสดงผลภาพเป็นกราฟพียงเส้นเดียว

    • ตัวอย่างแฟ้ม /etc/mrtg/myhost-tcpestab.cfg มีข้อมูลว่า

      WorkDir: /var/www/mrtg/myhost
      LoadMIBs: /usr/share/snmp/mibs/TCP-MIB.txt
      Target[myhost-tcpestab]: tcpCurrEstab.0&tcpCurrEstab.0:public@localhost
      RouterUptime[myhost-tcpestab]: public@localhost
      MaxBytes[myhost-tcpestab]: 1000000
      Title[myhost-tcpestab]: TCP Current Establish
      PageTop[myhost-tcpestab]: <H1>TCP Current Establish </H1>
      ShortLegend[myhost-tcpestab]: conns
      YLegend[myhost-tcpestab]: conns
      LegendI[myhost-tcpestab]: Current:
      LegendO[myhost-tcpestab]:
      Legend1[myhost-tcpestab]: Current, numbers of connections
      Legend2[myhost-tcpestab]:
      Options[myhost-tcpestab]: nopercent, growright, gauge

  11. ตัวอย่างการทำกราฟ Idle CPU and Load

    • ใช้ข้อมูล ssCpuIdle.0 และ laLoadInt.1 จาก snmp
    • แสดงผลภาพเป็นกราฟสองเส้น

    • ตัวอย่างแฟ้ม /etc/mrtg/myhost-cpu.cfg มีข้อมูลว่า
      WorkDir: /var/www/mrtg/myhost
      LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
      Target[myhost-cpu]:ssCpuIdle.0&laLoadInt.1:public@localhost
      RouterUptime[myhost-cpu]: public@localhost
      MaxBytes[myhost-cpu]: 10000
      Title[myhost-cpu]: Idle CPU and Load average
      PageTop[myhost-cpu]: <H1>Idle CPU and Load average</H1>
      ShortLegend[myhost-cpu]: %
      YLegend[myhost-cpu]: CPU and Load Utilization
      Legend1[myhost-cpu]: Idle CPU
      Legend2[myhost-cpu]: Load average
      LegendI[myhost-cpu]:  Idle
      LegendO[myhost-cpu]:  Load
      Options[myhost-cpu]: gauge, nopercent, growright

  12. ตัวอย่างการทำกราฟ Linux Print counter แสดงจำนวนกระดาษพิมพ์ผ่านโปรแกรมควบคุมงานพิมพ์ pykota

    • ไม่ได้ใช้ข้อมูลจาก snmp แต่ใช้ผลลัพธ์จาก shell script ชื่อ get-print-counter.sh
    • แสดงผลภาพเป็นกราฟสองเส้น

    • ตัวอย่างแฟ้ม /etc/mrtg/myhost-print.cfg มีข้อมูลว่า
      WorkDir: /var/www/mrtg/myhost
      Target[myhost-print]:`/etc/mrtg/get-print-counter.sh`
      MaxBytes[myhost-print]: 100000
      Title[myhost-print]: Linux Print counter
      PageTop[myhost-print]: <H1>Linux Print counter</H1>
      ShortLegend[myhost-print]: pages
      YLegend[myhost-print]: pages
      Legend1[myhost-print]: Today, only
      Legend2[myhost-print]: This Month, only
      LegendI[myhost-print]:  Today
      LegendO[myhost-print]:  This month
      Options[myhost-print]: gauge, nopercent, growright

    • ตัวอย่างแฟ้ม /etc/mrtg/get-print-counter.sh
      *** ต้องให้แสดงผลออกมาเป็น 4 บรรทัดเป็นลำดับคือ
      บรรทัดที่ 1 เป็นค่าที่บันทึกลงในกราฟที่ 1
      บรรทัดที่ 2 เป็นค่าที่บันทึกลงในกราฟที่ 2
      บรรทัดที่ 3 เป็นข้อมูลแสดงบรรทัดแรกของหน้ากราฟนี้
      บรรทัดที่ 4 เป็นข้อมูลแสดงบรรทัดที่สองของหน้ากราฟนี้

      #!/bin/sh
      temp_file1="/tmp/temp1-counter.tmp"
      temp_file2="/tmp/temp2-counter.tmp"

      today=`date '+%Y-%m-%d'`
      repykota > $temp_file1

      sum_pages=`grep "Total" $temp_file1|awk '{print $3}'`

      dumpykota -d history -o $temp_file2 > /dev/null

      start_pages=`grep $today $temp_file2|head -1|awk -F, '{print $7}'|cut -d'"' -f2`
      today_pages=`expr $sum_pages - $start_pages`

      echo "$today_pages"
      echo "$sum_pages"
      time=`uptime`
      echo "$time"
      echo "rd9"

  13. ตัวอย่างคำสั่งในการแสดง index สำหรับกราฟหลายรูปในหน้าเดียว

    indexmaker --column=1 --output=/var/www/mrtg/myhost/index.html /etc/mrtg/myhost-tcpestab.cfg  /etc/mrtg/myhost-cpu.cfg  /etc/mrtg/myhost-print.cfg  /etc/mrtg/mrtg-myhost.cfg
หมายเลขบันทึก: 107638เขียนเมื่อ 30 มิถุนายน 2007 17:15 น. ()แก้ไขเมื่อ 14 มิถุนายน 2012 15:52 น. ()สัญญาอนุญาต: จำนวนที่อ่านจำนวนที่อ่าน:


ความเห็น (0)

ไม่มีความเห็น

พบปัญหาการใช้งานกรุณาแจ้ง LINE ID @gotoknow
ClassStart
ระบบจัดการการเรียนการสอนผ่านอินเทอร์เน็ต
ทั้งเว็บทั้งแอปใช้งานฟรี
ClassStart Books
โครงการหนังสือจากคลาสสตาร์ท