Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Nedeľa, 21. júl 2024

Súbor: [Platon] / scripts / perl / syswatcher / create-graph.sh (stiahnutie)

Revízia 1.3, Wed Nov 12 12:35:33 2003 UTC (20 years, 8 months ago) by rajo


Zmeny od 1.2: +20 -4 [lines]

Generate graphs for any day (not only yesterday).

#!/bin/sh

#
# system-graph.sh
#
# Developed by Lubomir Host <rajo AT platon.sk>
# Copyright (c) 2003 Platon SDG, http://platon.sk/
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Run this script 1 minute after midnight (cron)
#

# $Platon: scripts/syswatcher/create-graph.sh,v 1.2 2003/11/12 12:11:25 rajo Exp $

DB_USER="syswatcher"
DATABASE="system"

output_dir="$HOME/public_html/graph"

umask 022

generate_loadavg()
{ # {{{

DATE=$1
output_loadavg="loadavg_$DATE"
xlabel="Date: [`echo $DATE | sed 's|-|/|g;'`]"

# LIMIT 90000 is for reason, if more than 1 row per second was inserted into table
# (1 day was 86400 seconds);
if [ ! -f "${output_loadavg}.dat" ]; then
    echo "SELECT
        date_format(time, '%Y/%m/%d/%T'), load1, load5, load15, procs_run, procs_total, last_pid, time
        FROM loadavg
        WHERE time > '$DATE' AND time < '$DATE' + INTERVAL 1 DAY 
        ORDER BY time LIMIT 90000;" \
    | mysql -B -u $DB_USER $DATABASE > "${output_loadavg}.dat";
fi

cat <<EOF | gnuplot - > /dev/null 2>&1
    set terminal png
    set grid
    set time

    set xdata time
    set timefmt "%Y/%m/%d/%H:%M:%S"
    set format x " %H:%M"
    set xlabel "$xlabel"
    set xtics rotate
    
    set output "$output_dir/loadavg_load01-$DATE.png"
    plot [] [0:2.0] "${output_loadavg}.dat" using 1:2 title "load per  1 min" with lines 1

    set output "$output_dir/loadavg_load05-$DATE.png"
    plot [] [0:2.0] "${output_loadavg}.dat" using 1:3 title "load per  5 min" with lines 2
    
    set output "$output_dir/loadavg_load15-$DATE.png"
    plot [] [0:2.0] "${output_loadavg}.dat" using 1:4 title "load per 15 min" with lines 3
    
    set output "$output_dir/loadavg_procs-$DATE.png"
    plot [] [0:200] "${output_loadavg}.dat" using 1:(20 * \$5) title "running processes (20 x zoom)" with lines 4, \
        "" using 1:6 title "processes total" with lines 5

EOF

# generate html document
cat <<EOF > "$output_dir/statistics-$DATE.html"
<html>
    <head>
        <title>Statistics of server `uname -n`:</title>
    </head>
    <H3>Statistics of server `uname -n`:</H3><BR><BR><BR>

    <img src="loadavg_load01-$DATE.png">
    <img src="loadavg_load05-$DATE.png">
    <img src="loadavg_load15-$DATE.png">
    <img src="loadavg_procs-$DATE.png">
</html>
EOF
} # }}}

if [ $# -lt 1 ]; then
    echo "Usage: $0 2003-11-10 [2003-11-11 [2003-11-12]]"
    exit 1;
fi

for date in $*; do
    generate_loadavg $date;
done

# vim600: fdm=marker fdc=3 fdl=0


Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok