Tag: mrtg

  • Oracle Database 12CR1 monitoring with MRTG

    • OS: Oracle Enterprise Linux  7.2  (CentOS 7.2)
    • วิธีติดตั้ง MRTG สามารถติดตั้งได้โดยสามารถดูคู่มือที่ ติดตั้ง mrtg บน ubuntu อาจไม่เหมือนกันแต่สามารถทำได้ทำนองเดียวกัน
    • กราฟสำหรับ Idle CPU and Load average, CPU Time spent waiting for IO, Traffic Analysis for eth0, TCP Current Establish สามารถใช้ script เดียวกับลิงค์ในข้อ ๒ ได้เลย
    • สร้างแฟ้ม /etc/mrtg/get-memory.sh มีข้อความว่า
      #!/bin/bash
      FREE=$(free |grep "Mem:"|awk '{print $7}')
      SWAP=$(free |grep "Swap:"|awk '{print $3}')
      TIME=$(uptime)
      echo "${FREE}"
      echo "${SWAP}"
      echo "$TIME"
      hostname 

      สร้างแฟ้ม /etc/mrtg/myhost-memory.cfg มีข้อความว่า
      WorkDir: /var/www/mrtg/myhost
      Target[myhost-mem]:`/etc/mrtg/get-memory.sh`
      MaxBytes[myhost-mem]: 20000000000
      Title[myhost-mem]: Free Memory and Swap Used
      PageTop[myhost-mem]: <H1>Free Memory and Swap Used</H1>
      ShortLegend[myhost-mem]: bytes
      YLegend[myhost-mem]: bytes
      LegendI[myhost-mem]:  Free Memory:
      LegendO[myhost-mem]: Swap Used:
      Legend1[myhost-mem]: Free memory, in bytes
      Legend2[myhost-mem]: Swap Used, in bytes
      Options[myhost-mem]: gauge, nopercent, growrightทดสอบสร้างภาพต้นแบบด้วยคำสั่ง

      env LANG=C /usr/bin/mrtg/myhost-memory.cfgปรับปรุงแฟ้ม index.html ด้วยคำสั่ง
      indexmaker --column=2 --output=/var/www/mrtg/myhost/index.html /etc/mrtg/myhost-cpu.cfg /etc/mrtg/myhost-cpu-io.cfg /etc/mrtg/myhost-speed-eth0.cfg /etc/mrtg/myhost-tcpestab.cfg /etc/mrtg/myhost-memory.cfg

    • โฟลเดอร์ที่ต้องเฝ้าระวังได้แก่ /u02/app/oracle/adump, /u02/app/oracle/diag/rdbms/regist/regist/alert, /u02/app/oracle/rdbms_trace ซึ่งเป็นโฟลเดอร์สำหรับเก็บ Log ไฟล์ต่างๆ ซึ่งอาจมีขนาดเพิ่มขึ้นจนระบบไม่สามารถให้บริการได้ และโฟลเดอร์ /u03 เป็นโฟลเดอร์ที่ใช้เก็บ archive log (ในกรณีที่ฐานข้อมูลเปิด archive log mode)
      • สร้างแฟ้ม /etc/mrtg/get-diskfree-misc1.sh มีข้อความว่า
        #!/bin/bash
        adump=$(du -sm /u02/app/oracle/adump|awk '{ print $1 }')
        free=$(df -m /u02|grep u02|awk '{ print $4 }')
        TEMP=$(uptime|grep -o "load average.*"|awk '{print $3}'|cut -d',' -f 1)
        LOAD=$(echo "${TEMP:-0} * 100"|bc|cut -d'.' -f 1)
        TIME=$(uptime)
        echo "${adump}"
        echo "${free}"
        echo "$TIME"
        hostname
      • สร้างแฟ้ม /etc/mrtg/myhost-diskfree-misc1.cfg มีข้อความว่า
        WorkDir: /var/www/mrtg/myhost
        Target[myhost-misc1]:`/etc/mrtg/get-diskfree-misc1.sh`
        MaxBytes[myhost-misc1]: 20000000000
        Title[myhost-misc1]: Free disk space and disk Used of /u02/app/oracle/adump
        PageTop[myhost-misc1]: Free disk space and disk Used of /u02/app/oracle/adump
        ShortLegend[myhost-misc1]: bytes
        kMG[myhost-misc1]: M,G,T
        kilo[myhost-misc1]: 1024
        YLegend[myhost-misc1]: bytes
        LegendI[myhost-misc1]: Disk Used:
        LegendO[myhost-misc1]: Free Disk:
        Legend1[myhost-misc1]: Disk usage, in Bytes
        Legend2[myhost-misc1]: Free Disk Space, in Bytes
        Options[myhost-misc1]: gauge, nopercent, growright
        Timezone[myhost-misc1]: Bangkok

        ทดสอบสร้างภาพต้นแบบด้วยคำสั่ง
        env LANG=C /usr/bin/mrtg /etc/mrtg/myhost-diskfree-misc1.cfg
        ปรับปรุงแฟ้ม index.html ด้วยคำสั่ง
        indexmaker --column=2 --output=/var/www/mrtg/myhost/index.html /etc/mrtg/myhost-cpu.cfg /etc/mrtg/myhost-cpu-io.cfg /etc/mrtg/myhost-speed-eth0.cfg /etc/mrtg/myhost-tcpestab.cfg /etc/mrtg/myhost-memory.cfg /etc/mrtg/myhost-diskfree-misc1.cfg
      • สร้างแฟ้มเลียนแบบข้อ 1 และ 2 สำหรับโฟลเดอร์ที่เหลือ
      • แก้ไขแฟ้ม /etc/mrtg/mymrtg.sh เพิ่มข้อความ  env LANG=C /usr/bin/mrtg /etc/mrtg/myhost-diskfree-misc1.cfg ต่อท้ายไฟล์และเพิ่มทุกไฟล์ของทุกโฟลเดอร์
      • สำหรับโฟลเดอร์ /u03 ให้สร้างแฟ้ม /etc/mrtg/get-diskfree-u03.sh มีข้อความว่า
        #!/bin/bash
        used=$(df -m /u03|grep u03|awk '{ print $3 }')
        free=$(df -m /u03|grep u03|awk '{ print $4 }')
        TEMP=$(uptime|grep -o "load average.*"|awk '{print $3}'|cut -d',' -f 1)
        LOAD=$(echo "${TEMP:-0} * 100"|bc|cut -d'.' -f 1)
        TIME=$(uptime)
        echo "${used}"
        echo "${free}"
        echo "$TIME"
        hostname
        nof=$(ls -d1 /u03/app/oracle/fast_recovery_area/REGIST/archivelog/* |wc -l)
        max=3if [ "${nof}" == "${max}" ]
        then
                nod=$(expr ${max} - 1)
                f2d=$(ls -d1 /u03/app/oracle/fast_recovery_area/REGIST/archivelog/*|head -${nod})
                rm -rf ${f2d}
                su - oracle -c "/bin/sh /home/oracle/reclaim.sh"
        fi
        สร้างแฟ้ม /home/oracle/reclaim.sh มีข้อความว่า
        rman target / <<EOF
        crosscheck archivelog all;
        delete noprompt expired archivelog all;
        quit
        EOF
        สร้างแฟ้ม /etc/mrtg/myhost-diskfree-u03.cfg มีข้อความว่า
        WorkDir: /var/www/mrtg/myhost
        Target[myhost-u03]:`/etc/mrtg/get-diskfree-u03.sh`
        MaxBytes[myhost-u03]: 20000000000
        Title[myhost-u03]: Free disk space and disk Used of /u03
        PageTop[myhost-u03]: Free disk space and disk Used of /u03
        ShortLegend[myhost-u03]: bytes
        kMG[myhost-u03]: M,G
        kilo[myhost-u03]: 1024
        YLegend[myhost-u03]: bytes
        LegendI[myhost-u03]: Disk Used:
        LegendO[myhost-u03]: Free Disk:
        Legend1[myhost-u03]: Disk usage, in Bytes
        Legend2[myhost-u03]: Free Disk Space, in Bytes
        Options[myhost-u03]: gauge, nopercent, growrightทดสอบสร้างภาพต้นแบบด้วยคำสั่ง
        env LANG=C /usr/bin/mrtg /etc/mrtg/myhost-diskfree-u03.cfg
        อย่าลืมปรับปรุงแฟ้ม index.html ด้วย
    • เฝ้าระวังขนาดของ Tablespace SYSTEM และ USERS
      • สร้างแฟ้ม /etc/mrtg/get-tablespace-system.sh มีข้อความว่า
        #!/bin/bash
        used=$(su - oracle -c "sh /home/oracle/monitor/tablespacesize.sh"|grep SYSTEM|awk '{ print $2 }'|sed -e 's/,//g')
        used=$(expr ${used} \* 1024)
        free=$(su - oracle -c "sh /home/oracle/monitor/tablespacesize.sh"|grep SYSTEM|awk '{ print $3 }'|sed -e 's/,//g')
        free=$(expr ${free} \* 1024)
        TIME=$(uptime)
        echo "${used}"
        echo "${free}"
        echo "$TIME"
        hostname

        สร้างแฟ้ม /home/oracle/monitor/tablespacesize.sh มีข้อความว่า
        #!/bin/bash
        sqlplus / as sysdba << EOF
        col "Tablespace" for a22
        col "Used MB" for 99,999,999
        col "Free MB" for 99,999,999
        col "Total MB" for 99,999,999
        select df.tablespace_name "Tablespace",
        totalusedspace "Used MB",
        (df.totalspace - tu.totalusedspace) "Free MB",
        df.totalspace "Total MB",
        round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))
        "Pct. Free"
        from
        (select tablespace_name,
        round(sum(bytes) / 1048576) TotalSpace
        from dba_data_files
        group by tablespace_name) df,
        (select round(sum(bytes)/(1024*1024)) totalusedspace, tablespace_name
        from dba_segments
        group by tablespace_name) tu
        where df.tablespace_name = tu.tablespace_name ;
        quit
        EOF

        สร้างแฟ้ม /etc/mrtg/myhost-tablespace-system.cfg
        WorkDir: /var/www/mrtg/myhost
        Target[myhost-system]:`/etc/mrtg/get-tablespace-system.sh`
        MaxBytes[myhost-system]: 20000000000
        Title[myhost-system]: Tablespace SYSTEM disk usage
        PageTop[myhost-system]: Tablespace SYSTEM Disk Usage
        ShortLegend[myhost-system]: bytes
        kMG[myhost-system]: k,M,G
        kilo[myhost-system]: 1024
        YLegend[myhost-system]: bytes
        LegendI[myhost-system]: Disk Used:
        LegendO[myhost-system]: Free Disk:
        Legend1[myhost-system]: Disk usage, in Bytes
        Legend2[myhost-system]: Free Disk Space, in Bytes
        Options[myhost-system]: gauge, nopercent, growrightทดสอบสร้างภาพต้นแบบด้วยคำสั่ง
        env LANG=C /usr/bin/mrtg /etc/mrtg/myhost-tablespace-system.cfgอย่าลืมปรับปรุง index.html ด้วย
      • ทำแบบเดียวกันกับ tablespace users
    • จบขอให้สนุก