Last active
August 29, 2015 14:26
-
-
Save rashkur/7782de50e144539a0d0a to your computer and use it in GitHub Desktop.
build png from nginx access log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE=$1 | |
FDATE=$(head -1 $FILE |awk '{print $4}'|sed -e 's/\[//'|sed -e 's/\//-/g'|sed -e 's/:/ /') | |
FDATE_S=$(date -d "$FDATE" '+%s'); | |
FDATE_T=$((FDATE_S + 3600)); | |
COUNT=0 | |
DATAFILE=$(mktemp) | |
RESULTFILE="result-"$(date -d "$FDATE" '+%Y-%m-%d')".png" | |
while read line | |
do | |
LDATE=$(echo $line|awk '{print $4}'|sed -e 's/\[//'|sed -e 's/\//-/g'|sed -e 's/:/ /') | |
LDATE_S=$(date -d "$LDATE" '+%s'); | |
if (( LDATE_S < FDATE_T )); then | |
COUNT=$((COUNT + 1)) | |
else | |
echo "$(date -d @"$((FDATE_T - 3600))" '+%Y-%m-%d %H:%M:%S') $COUNT" >>$DATAFILE | |
FDATE_T=$((FDATE_T + 3600)) | |
COUNT=1; | |
fi | |
done <$FILE | |
gnuplot << EOF | |
reset | |
set xdata time | |
set timefmt "%Y-%m-%d %H:%M:%S" | |
set format x "%m/%d\n%H:%M" | |
set autoscale | |
set ytics | |
#for sane graduation | |
set xtics 10000, 3600 | |
set grid y | |
set auto y | |
set term png truecolor | |
set output "$RESULTFILE" | |
set xlabel "Time" | |
set ylabel "Request per hour" | |
set grid | |
set boxwidth 0.95 relative | |
set style fill transparent solid 0.5 noborder | |
#size | |
set term png size 2800,400 | |
#x inscriptions rotation | |
#set xtics rotate by -30 | |
plot "$DATAFILE" using 1:3 w boxes lc rgb "green" notitle | |
EOF | |
rm -f $DATAFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment