#!/usr/bin/gawk -f # # netdrawmonsum -- 2008-05-19, last edit 2009-10-02 # # script to display summary of this month's data transfers # # Copyright (C) 2008 Grant Coady GPLv2 # BEGIN { ARGV[ARGC++] = "/etc/netdraw.conf" start = mktime(strftime("%Y %m")" 1 0 0 0") } /^$|^#/ { next } NR == FNR { conf[$1] = $2 if ($1 == "datafile") ARGV[ARGC++] = conf["datapath"] "/" $2 if ($1 == "monsumfile") out = conf["htmlpath"] "/" $2 next } { split($1, a, "[-.:]") if (mktime(a[1]" "a[2]" "a[3]" "a[4]" "a[5]" 30") > start) { day = a[3] + 0 hour = a[4] min = a[5] rx = $2 - lrx tx = $3 - ltx if (rx < 0) rx = 0 if (tx < 0) tx = 0 trx += rx ttx += tx mtrx += rx mttx += tx if (hour == 23 && min == 59) { drx[day] = trx dtx[day] = ttx trx = ttx = 0 } } lrx = $2; ltx = $3 } function s(v, p) { p = " " if (v >= 1000) { v /= 1000; p = "k" } if (v >= 1000) { v /= 1000; p = "M" } if (v >= 1000) { v /= 1000; p = "G" } return sprintf(" %#.4g", v) p "B" } BEGIN { out = "/tmp/netdrawmonsum.fly" tmp = "/tmp/netdrawmonsum.png" img = "/home/web/bugsplatter/netdraw/netdrawmonsum.png" htm = "/home/web/bugsplatter/netdraw/index/html" col_back = "215,231,252" col_shdw = "204,216,230" col_text = "0,0,0" } function fly_chart(x, y) { print "# " img > out print "new" > out print "size " x "," y > out print "type png" > out print "name " tmp > out print "fill 1,1," col_back > out } function fly_string(x, y, t) { print "string " col_shdw "," x + 1 "," y ",small," t > out print "string " col_shdw "," x + 1 "," y + 1 ",small," t > out print "string " col_text "," x "," y ",small," t > out } END { if (!drx[day]) drx[day] = trx if (!dtx[day]) dtx[day] = ttx for (i = 1; i <= day; i++) { if (drx[i] > prx) prx = drx[i] if (dtx[i] > ptx) ptx = dtx[i] } s1 = sprintf("Peak: Rx:%s Tx:%s\n", s(prx), s(ptx)) s2 = sprintf("Average: Rx:%s Tx:%s\n", s(mtrx / day), s(mttx / day)) s3 = sprintf("Today: Rx:%s Tx:%s", s(drx[day]), s(dtx[day])) # write fly script fly_chart(320, 48) fly_string(10, 4, s1) fly_string(10, 18, s2) fly_string(10, 32, s3) system("fly -q -i " out " && mv -f " tmp " " img) ##system("touch " htm) }