jablonka.czprosek.czf

crusader

Subversion Repositories:
[/] [trunk/] [statistiky/] [opt/] [statistiky/] [collect_system_info.sh] - Rev 2 Go to most recent revision

Compare with Previous - Blame - Download


#!/bin/bash

PATH=/opt/rrdtool/bin:$PATH:/sbin

stat_dir="/var/statistiky/system"
mkdir -p $stat_dir

cd $stat_dir

function create_db()
{
    if [ ! -f mpstat.rrd ] ; then
        echo "Creating mpstat db"

        # sbirame jednou za minutu
        # poslednich 6 hodin chci mit vsechno => 60*6 = 360 PDP
        # za posledni tyden chci desetiminutove agregace => 10 dni * 24 hodin * 6 = 1440 rows
        # za posledni mesic chci hodinove agregace => 40 dni * 24 hodin = 960 rows
        # za posledni rok chci ctyrhodinove agregace => 365 * 6 = 2190 rows

        rrdtool create mpstat.rrd --step 60 --start `date +%s`    \
                          DS:user:GAUGE:120:0:100     \
                          DS:nice:GAUGE:120:0:100     \
                          DS:system:GAUGE:120:0:100   \
                          DS:iowait:GAUGE:120:0:100   \
                          DS:irq:GAUGE:120:0:100      \
                          DS:softirq:GAUGE:120:0:100  \
                          DS:idle:GAUGE:120:0:100     \
                          DS:intrs:GAUGE:120:0:U      \
                          RRA:AVERAGE:0.7:1:360           \
                          RRA:MAX:0.7:10:1440         \
                          RRA:MIN:0.7:10:1440         \
                          RRA:AVERAGE:0.7:10:1440     \
                          RRA:MAX:0.7:60:960         \
                          RRA:MIN:0.7:60:960         \
                          RRA:AVERAGE:0.7:60:960     \
                          RRA:MAX:0.7:240:2190       \
                          RRA:MIN:0.7:240:2190       \
                          RRA:AVERAGE:0.7:240:2190
    fi
    if [ ! -f conntrack.rrd ] ; then
        echo "Creating conntrack db"


        rrdtool create conntrack.rrd --step 60 --start `date +%s`    \
                          DS:tcp_syn_sent:GAUGE:120:0:65535      \
                          DS:tcp_syn_recv:GAUGE:120:0:65535      \
                          DS:tcp_established:GAUGE:120:0:65535   \
                          DS:tcp_close:GAUGE:120:0:65535         \
                          DS:tcp_close_wait:GAUGE:120:0:65535    \
                          DS:tcp_fin_wait:GAUGE:120:0:65535      \
                          DS:tcp_time_wait:GAUGE:120:0:65535     \
                          DS:udp:GAUGE:120:0:65535               \
                          DS:ip_conntrack_max:GAUGE:120:0:65535  \
                          RRA:AVERAGE:0.7:1:360           \
                          RRA:MAX:0.7:10:1440         \
                          RRA:MIN:0.7:10:1440         \
                          RRA:AVERAGE:0.7:10:1440     \
                          RRA:MAX:0.7:60:960         \
                          RRA:MIN:0.7:60:960         \
                          RRA:AVERAGE:0.7:60:960     \
                          RRA:MAX:0.7:240:2190       \
                          RRA:MIN:0.7:240:2190       \
                          RRA:AVERAGE:0.7:240:2190
    fi
        
}

function wait_to()
# $1 date for waiting to
{
    local time_now=`date +%s`;
    while [ $time_now -lt $1 ]
    do
        time_now=`date +%s`
        sleep 1;
    done
}

start_time=`date +%s`
# zaokrouhlime interval na deset sekund
interval=$(( $start_time / 10 * 10 + 10 ))

conntrack_file=/tmp/conntrack_file

while [ true ] ; do

    create_db

    wait_to $interval
    
    logfile="$stat_dir/mpstat"
    timenow=`date +%s`
    cpuline=`mpstat -P 0 1 3 | tail -2 | head -1`
#    echo $cpuline
    user_time=`echo $cpuline | awk '{print $4;}'`
    nice_time=`echo $cpuline | awk '{print $5;}'`
    system_time=`echo $cpuline | awk '{print $6;}'`
    iowait_time=`echo $cpuline | awk '{print $7;}'`
    irq_time=`echo $cpuline | awk '{print $8;}'`
    softirq_time=`echo $cpuline | awk '{print $9;}'`
    idle_time=`echo $cpuline | awk '{print $10;}'`
    intrs=`echo $cpuline | awk '{print $11;}'`

    echo  $interval $user_time $nice_time $system_time $iowait_time $irq_time $softirq_time $idle_time $intrs >>/var/log/statistiky/system.log
    rrdtool update mpstat.rrd -t user:nice:system:iowait:irq:softirq:idle:intrs $interval:$user_time:$nice_time:$system_time:$iowait_time:$irq_time:$softirq_time:$idle_time:$intrs

    cp /proc/net/ip_conntrack $conntrack_file
    tcp_syn_sent=`grep ^tcp.*SYN_SENT.* <$conntrack_file | wc -l`
    tcp_syn_recv=`grep ^tcp.*SYN_RECV.* <$conntrack_file | wc -l`
    tcp_established=`grep ^tcp.*ESTABLISHED.* <$conntrack_file | wc -l`
    tcp_close=`grep ^tcp.*CLOSE.* <$conntrack_file | wc -l`
    tcp_close_wait=`grep ^tcp.*CLOSE_WAIT.* <$conntrack_file | wc -l`
    tcp_fin_wait=`grep ^tcp.*FIN_WAIT.* <$conntrack_file | wc -l`
    tcp_time_wait=`grep ^tcp.*TIME_WAIT.* <$conntrack_file | wc -l`
    udp=`grep ^udp.* <$conntrack_file | wc -l`
    rm -f $conntrack_file

    ip_conntrack_max=`cat /proc/sys/net/ipv4/netfilter/ip_conntrack_max`

    echo $interval $tcp_syn_sent $tcp_syn_recv $tcp_established $tcp_close $tcp_close_wait $tcp_fin_wait $tcp_time_wait $udp >>/var/log/statistiky/conntrack.log
    rrdtool update conntrack.rrd -t tcp_syn_sent:tcp_syn_recv:tcp_established:tcp_close:tcp_close_wait:tcp_fin_wait:tcp_time_wait:udp:ip_conntrack_max \
                                    $interval:$tcp_syn_sent:$tcp_syn_recv:$tcp_established:$tcp_close:$tcp_close_wait:$tcp_fin_wait:$tcp_time_wait:$udp:$ip_conntrack_max 2>>/var/log/statistiky/conntrack.err
    echo "rrdtool update conntrack.rrd -t tcp_syn_sent:tcp_syn_recv:tcp_established:tcp_close:tcp_close_wait:tcp_fin_wait:tcp_time_wait:udp:ip_conntrack_max     $interval:$tcp_syn_sent:$tcp_syn_recv:$tcp_established:$tcp_close:$tcp_close_wait:$tcp_fin_wait:$tcp_time_wait:$udp:$ip_conntrack_max" >>/var/log/statistiky/conntrack.history

    interval=$(( $interval + 60 ))

done

Powered by WebSVN 2.2.1