New Server Instance

Our website has been moved to a new server instance at Linode.com in Dallas, Texas, USA. It was running on a 1gb instance, and now it’s running on a 2gb instance. This is trivia.

The point is that if you see something weird, that’s why.

Currently the Download counter isn’t working because this server is using different web server software, back to Apache from Nginx. A different log file format means a different log file parsing script is necessary.

The stats were being counted every minute by an awk script launched as a cronjob on a Debian linux server every minute (because):

*/1 * * * * gawk -f /var/www/karenware.com/web/production/cli/log-parse.awk /var/log/nginx/access.log > /tmp/log-parse.txt

It doesn’t work now because Apache’s log format is different by default, as a result, downloads are not being counted on the website and every page call causes an error to be logged because the file containing the last download count isn’t there because the script fails.

Here’s what the GNU’s AWK (gawk) looked like:

#  https://www.gnu.org/software/gawk/manual/gawk.html#Splitting-By-Content
BEGIN {
    FPAT = "([^ ]+)|(\"[^\"]+\")"
    DOWNLOADS = 0
    BYTES = 0
}

#{
#   print "NF = ", NF
#  for (i = 1; i <= NF; i++) {
#     printf("$%d = <%s>\n", i, $i)
#  }
#}

NR == 1 {
        split( substr($9,2) , dt, ":" )
        DATE = dt[1]
        FIRST = dt[2] ":" dt[3]
}

$1 == 200 && $2 == "\"www.karenware.com\"" && $3 ~ /GET \/d\//     {
        DOWNLOADS++
        BYTES = BYTES + $4
        split( substr($9,2) , dt, ":" )
        LAST = dt[2] ":" dt[3] " " substr( $10, 1, length($10)-1)
}

END {

        if( DOWNLOADS == 0 ) {
                print "No downloads yet, but the day's just getting started."
        } else if( DOWNLOADS == 1 ) {
                print "Someone downloaded a program already today!"
        } else {
                print DOWNLOADS
        }
}

Here’s what the new log entries look like (me downloading Karen’s Directory Printer… I’ve removed my IP address):

999.999.999.999 - - [19/May/2023:09:57:10 -0500] "GET /d/Karens-Directory-Printer-v5.4.4-Setup.exe HTTP/1.1" 200 1779129 "https://www.karenware.com/powertools/karens-directory-printer" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"

And the new awk script:

#  https://www.gnu.org/software/gawk/manual/gawk.html#Splitting-By-Content
BEGIN {
    FPAT = "([^ ]+)|(\"[^\"]+\")"
    DOWNLOADS = 0
    BYTES = 0
    TODAY=strftime("%d/%b/%Y")
}

#{
#   print "NF = ", NF
#  for (i = 1; i <= NF; i++) {
#     printf("$%d = <%s>\n", i, $i)
#  }
#}

$7 == 200 && $6 ~ /GET \/d\//     {
        split( substr($4,2) , dt, ":" )
        DATE = dt[1]
        if( DATE == TODAY ) {
                DOWNLOADS++
        }

}

END {

        if( DOWNLOADS == 0 ) {
                print "No downloads yet, but the day's just getting started."
        } else if( DOWNLOADS == 1 ) {
                print "Someone downloaded a program already today!"
        } else {
                print DOWNLOADS
        }
}

All fixed up.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top