A Web/CGI Interface to the ONSTAT Utility

Published on April 1, 1997 by Lester Knutsen

First published in the Washington Area Informix User Group Newsletter
Volume 7, No. 2 - April 1997

 

This is one of the scripts I presented at the WAIUG Training Day. The purpose is to provide a web interface to the INFORMIX-OnLine ONSTAT Utility. There are two parts to this interface: the first is a web page from which the user selects which onstat option is to be executed, and the second is a CGI script that runs onstat with the requested option. Figure 1 is an example of what the web page would look like. The user is presented with a scrolling list of options to select. Onstat has may more options than I use in this example. After the user selects an option, a CGI script is executed which runs onstat and generates a web page displaying the output.

 

Figure 1: A Web/CGI Interface to the ONSTAT Utility

A Web/CGI Interface to the ONSTAT Utility

Figure 1: A Web/CGI Interface to the ONSTAT Utility

First we will take a look at the web page that created the screen shown above. The HTML code is show in Figure 2. This is very basic HTML that can be created in any text editor or using the Netscape Editor. HTML is a markup language that uses tags within angle brackets <> to tell the web browser how to display the page. There are three parts to this web page: a header, a title, and the form with the list of options. The first part of our example document is a header that is not displayed by the browser. Next we display a title, centered in a larger font saying "Informix OnLine ONSTAT Utility Web Interface".

The next action is to display a form on the browser. The tag <FORM method=post action="cgi-bin/wonstat.sh" instructs the server create a form on the browser's screen, and then to execute the CGI script wonstat.sh when the user presses the execute button. The rest of the tags within the form tag list the options to display in the pop-up scrolling list.

Figure 2: onstat.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Informix Onstat Options</TITLE>
<META NAME="GENERATOR" CONTENT="Mozilla/3.0Gold (X11; I; SunOS 5.5 sun4m)
[Netscape]">
</HEAD>
<BODY BGCOLOR="#FFFFFF">

<CENTER><P><FONT COLOR="#003388"><FONT SIZE=+2>Informix OnLine Onstat Utility
Web Interface</FONT></FONT>
<HR></P></CENTER>

<CENTER><P><FORM method=post action="cgi-bin/wonstat.sh"

<table><B>Choose one Onstat Option :<SELECT name=o_command>
<OPTION></B>Profile 
<OPTION>Users
<OPTION>DBspaces 
<OPTION>Configuration
<OPTION>Logging
<OPTION>Messages
<OPTION>Chunk_IO_Stats 
<OPTION>Page_Flushers
<OPTION>LRU_Queues
<OPTION>VP_Statistics
<OPTION>Memory_Grant_Manager
<OPTION>SQL_Sessions
</SELECT>
</P>

<P>
<INPUT type=submit value="Execute Command"></FORM></P></CENTER>

</BODY>
</HTML>



When the user presses the execute button, the web server runs the CGI script wonstat.sh. This is really a unix shell script. The web server must have a location in its configuration for CGI scripts, and must be configured to execute CGI scripts. This script must be located in the specified directory. There are a number of security considerations with CGI scripts that are beyond the scope of this article.

There are four parts to the script, and Figure 3 lists the full shell script. The first part of the script reads from standard input into a shell variable o_command, the option the user selected from the web page. Next the Informix environment variables INFORMIXDIR, PATH, INFORMIXSERVER, and ONCONFIG must be set. Most web servers run as the user "nobody" with a very limited environment to prevent executing most programs that you do not specify on your system. Therefore, to run an Informix script you need to specify all the environment information the user will need. The third part of the script is a case statement to determine what options to execute with onstat. The final part of the script is the onstat command.

Figure 3: wonstat.sh

 

#!/bin/sh
#############################################################################
# Module:       @(#)wonstat.sh    1.1   Date: 97/03/25
# Author:       Lester B. Knutsen         email: lester@advancedatatools.com
#               Advanced DataTools Corporation
# Description:  Web Page to display the output of onstat -p
#############################################################################

#############################################################################
# Get STDIN from Web Server
#############################################################################
read o_command

#############################################################################
# Set-up the Informix environment
#############################################################################
## Set the location of Informix Programs
INFORMIXDIR=/u3/informix7
export INFORMIXDIR

## Add the Informix Programs to your PATH
PATH=$INFORMIXDIR/bin:$PATH:
export PATH

## Set the Default Database Server
INFORMIXSERVER=train1
export INFORMIXSERVER

## Set the Informix Configuration File
ONCONFIG=onconfig.train1
export ONCONFIG

#############################################################################
# Script to generate web page
#############################################################################

echo Content-type: text/html
echo
echo "<TITLE>DB Server Status</TITLE>
<BODY>
<H1>Informix OnLine Server Status for: $INFORMIXSERVER</H1>
Option: $o_command
<PRE>
"
case $o_command in
        o_command=Profile)          o_command="-p";;
        o_command=Users)            o_command="-u";;
        o_command=DBspaces)         o_command="-d";;
        o_command=Configuration)    o_command="-c";;
        o_command=Logging)          o_command="-l";;
        o_command=Messages)         o_command="-m";;
        o_command=Chunk_IO_Stats).  o_command="-D";;
        o_command=Page_Flushers)    o_command="-F";;
        o_command=LRU_Queues)       o_command="-R";;
        o_command=VP_Statistics)    o_command="-g sch";;
        o_command=Memory_Grant_Manager) o_command="-g mgm";;
        o_command=SQL_Sessions)      o_command="-g sql";;
esac


onstat $o_command

echo "</PRE>
</BODY>"
#############################################################################