Friday, September 12, 2008

awstats web site statistics for glassfish

awstats is a open source web server log analyzer. Glassfish is an open source java-based web-server. Click here to check out the statistics on my two glassfish domain servers: domain1 domain2. Of course you will restrict access when you deploy this.

To get the awstats package to work with glassfish:
  1. Download and untar awstats (to /usr/local/awstats)
  2. Follow the instructions for installing awstats and run the configuration utility.
    Remember to create the /etc/awstats/ and /var/lib/awstats/ directories and set write permission.
    Edit the config file (/etc/awstats/yourconfigfilename) and change the LogFile property to:
    LogFile="sed -e 's/"\([0-9\.]*\)"/\1 - -/g' -e 's/"\([^"]*-0800\)"/[\1]/g' /usr/local/java/web/glassfish/domains/domain1/logs/access/server_access_log.%YYYY-0-%MM-0-%DD-0.txt |"
    where "/usr/local/java/web/glassfish" is the location of your glassfish server. Also remember to change the time zone offset (mine is -0800) to your timezome offset.
    Change the DirIcons property to:
    DirIcons="icon"
    You will probably want to change your SiteDomain and HostAliases properties to match your domain name.
    I got this info from Glen Smith's blog, Thanks!
  3. Open your glassfish admin page (http://www.yourserver.com:4848), go to configuration -> http service and click the Access Logging enabled box.
    Click on the Access Log Tab and enter:
    %client.name% %datetime% %request% %status% %response.length% %header.referer% %header.user-agent%
    in the Format text box.
    This makes your log format similar to the apache log format
  4. Go you your awstats/wwwroot directory and create a sub-directory WEB-INF
    Create a web.xml file in this directory that contains:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <servlet>
    <servlet-name>cgi</servlet-name>
    <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
    <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
    </init-param>
    <init-param>
    <param-name>cgiPathPrefix</param-name>
    <param-value>cgi-bin</param-value>
    </init-param>
    <load-on-startup>5</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>cgi</servlet-name>
    <url-pattern>/awstats.pl</url-pattern>
    </servlet-mapping>
    </web-app>
    Afterwards, cd to the wwwroot/cgi-bin directory type chmod a-w *.pl just to be careful.
  5. Now, install this as a web server in the glassfish admin screen (http://www.yourserver.com:4848)
    Applications -> Web Applications -> Deploy
    And deploy the web server directory: /usr/local/awstats/wwwroot. Make sure your context root is awstats.


  6. Try to invoke the servlet as it's described in the awstats documentation:
    http://www.yourdomain.com/awstats/awstats.pl?config=yourconfigfilename
    You should see the awstat config data. Cool!

1 comment:

r2 said...

In the 5th step, I couldn't deploy and I got this error:

Deploying application in domain failed; Error loading deployment descriptors for module [wwwroot]
Line 7 Column 16 -- Deployment descriptor file WEB-INF/web.xml in archive [wwwroot]. cvc-complex-
type.2.4.a: Invalid content was found starting with element 'servlet-class'. One of
'{"http://java.sun.com/xml/ns/j2ee":description, "http://java.sun.com/xml/ns/j2ee":display-name,
"http://java.sun.com/xml/ns/j2ee":icon, "http://java.sun.com/xml/ns/j2ee":servlet-name}' is expected.
Error loading deploy...

Do you know why it happened?

Thanks,