From: www.itworld.com

Unix Tip: Building and Using Analog on Solaris

by Sandra Henry-Stocker

March 30, 2006 —

 

Send in your Unix questions today!


See additional Unix tips and tricks



Analog is a free web traffic analysis tool that prepares reports on activity on your web sites, including graphs that summarize hourly, daily, file size file type, visiting site, return codes and numerous other statistics that illustrate how your web sites are being used. I recently compiled and deployed Analog on a couple of Solaris 9 servers. Today's column is a how-to on building Analog and a quick introduction to how it works.



To compile Apache on a Solaris system, you should first grab a copy of the source code. I went to http://www.analog.cx/download.html and downloaded analog-6.0.tar.gz. This command should work on the command line if you have wget installed:



wget http://www.analog.cx/analog-6.0.tar.gz



I then gunzipped and extracted the contents of the downloaded file and attempted to compile the application:
$ gunzip analog-6.0.tar.gz
$ tar xf analog-6.0.tar
$ cd analog-6.0
$ make



My attempt to compile Analog ran into some problems -- notably undefined symbols.

        $ make
        cd src && make
        make[1]: Entering directory `/export/home/henrystocker/analog-6.0/src'
        gcc            -O2      -DUNIX          -c alias.c
        gcc            -O2      -DUNIX          -c analog.c
        gcc            -O2      -DUNIX          -c cache.c
        ... omitted output ...
        Undefined                       first referenced
         symbol                             in file
        gethostbyaddr                       alias.o
        inet_addr                           alias.o
        ld: fatal: Symbol referencing errors. No output written to ../analog
        collect2: ld returned 1 exit status
        make[1]: *** [analog] Error 1
        make[1]: Leaving directory `/export/home/henrystocker/analog-6.0/src'
        make: *** [analog] Error 2

I soon figured out that I needed to make a small change to one of my Makefiles. I made the change with this perl command, adding the network services library after noting that the man pages for the undefined symbols both referenced -lnsl.

        $ cd src
        $ perl -i -p -e "s/LIBS = -lm/LIBS = -lnsl -lm/" Makefile

My LIBS line then looked like this: 

        LIBS = -lnsl -lm (added -lnsl)

After this change, Analog compiled without a hitch: 

        $ cd ..
        $ make
        cd src && make
        make[1]: Entering directory `/export/home/shs/analog-6.0/src'
        gcc            -O2      -DUNIX          -c alias.c
        gcc            -O2      -DUNIX          -c analog.c
        gcc            -O2      -DUNIX          -c cache.c
        ... omitted output ...
        gcc            -O2     -o ../analog alias.o analog.o cache.o dates.o
        globals.o hash.o init.o init2.o input.o macinput.o macstuff.o output.o
        output2.o outcro.o outhtml.o outlatex.o outplain.o outxhtml.o outxml.o
        process.o settings.o sort.o tree.o utils.o win32.o libgd/gd.o
        libgd/gd_io.o libgd/gd_io_file.o libgd/gd_png.o libgd/gdfontf.o
        libgd/gdfonts.o libgd/gdtables.o libpng/png.o libpng/pngerror.o
        libpng/pngmem.o libpng/pngset.o libpng/pngtrans.o libpng/pngwio.o
        libpng/pngwrite.o libpng/pngwtran.o libpng/pngwutil.o pcre/pcre.o
        zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/gzio.o
        zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o
        zlib/inftrees.o zlib/infutil.o zlib/trees.o zlib/uncompr.o zlib/zutil.o
        unzip/ioapi.o unzip/unzip.o bzip2/bzlib.o bzip2/blocksort.o
        bzip2/compress.o bzip2/crctable.o bzip2/decompress.o bzip2/huffman.o
        bzip2/randtable.o -lnsl -lm
        make[1]: Leaving directory `/export/home/shs/analog-6.0/src'

        $ ls -l analog
        -rwxr-xr-x   1 root     other     577568 Mar 29 19:34 analog

Once Analog was compiled, I moved it into /usr/local/bin (there was no "make install" option) and ran a "make clean" to remove object files. At this point, I had switched over to root.



The next step was setting up a configuration file to give Analog some directions on how I wanted it to work. Analog comes with example configuration files and there are numerous options that can be used to customize your reports, but I wanted to start with something simple, so I set up a handful of options and installed the file as /usr/local/bin/analog.cfg:

        # cat > /usr/local/bin/analog.cfg << EOF
        > LANGFILE usa.lng
        > HOSTNAME boson.particles.org
        > HOSTURL "http://boson.particles.org"
        > DAILYSUM ON
        > DAILYREP ON
        > LOGFILE /opt/apache/logs/access_log
        > OUTFILE /opt/apache/htdocs/webstats.html
        > DOMAINSFILE usdom.tab
        > EOF

I also had to create a directory named /usr/local/bin/lang and copy the usa.lng file and usdom.tab files from my lang directory into it.

        # mkdir /usr/local/bin/lang
        # cp lang/usa.lng /usr/local/bin/lang
        # cp lang/usdom.tab /usr/local/bin/lang

I then ran the report like this:



# analog /opt/apache/logs/access_log



My processed report appeared in my /opt/apache/htdocs directory along with four image files containing pie charts for some of my statistics. You can see a sample Analog report here.

Here's a list of features that you can turn off or on: 
MONTHLY ON       # one line for each month
WEEKLY ON        # one line for each week
DAILYREP ON      # one line for each day
DAILYSUM ON      # one line for each day of the week
HOURLYREP ON     # one line for each hour of the day
GENERAL ON       # the General Summary at the top
REQUEST ON       # which files were requested
FAILURE ON       # which files were not found
DIRECTORY ON     # Directory Report
HOST ON          # which computers requested files
ORGANISATION ON  # which organisations they were from
DOMAIN ON        # which countries they were in
REFERRER ON      # where people followed links from
FAILREF ON       # where people followed broken links from
SEARCHQUERY ON   # the phrases and words they used...
SEARCHWORD ON    # ...to find you from search engines
BROWSERSUM ON    # which browser types people were using
OSREP ON         # and which operating systems
FILETYPE ON      # types of file requested
SIZE ON          # sizes of files requested
STATUS ON        # number of each type of success and failure