Sw4   >   Web   >   SW Web App Monitoring

SW Web App Monitoring

The web monitor created by the Omnis Studio Class Wizard is a visual web monitor. The problem with the visual web monitor is that you must be at the web server to watch it and if you close the web monitor window you will lose all of the history.

A non-visual web monitor is available in StudioWorks. The non-visual web monitor object, oWebMonitor, inserts a record for each web app request into a Webappstat table in the database. Summary reports can be generated and emails with the summary web app stats can be sent using a timer object.

This section explains how to set up the oWebMonitor object class for your StudioWorks web app.

Startup Task

We instantiate the oWebMonitor object class with a task variable of the main library Startup_Task.

  1. Add the task var, webmon, Object type, to the main library Startup_Task
  2. Point webmon to the oWebMonitor in the swWeb4 library.
  3. Add a private method, initializeWebMonitor, to the Startup_Task methods.
  4. Add the following code to the method:

    ; Get the email address of the person to receive web app stats emails.
    Calculate EmailAddr as cn.$:WebAppStatsEmailAddr

    ; Get the interval the web stats are to be sent. (kDay, kWeek, kMonth, kYear)
    Calculate kInterval as cn.$:WebAppStatsInterval

    ; Initialize the oWebMonitor object.
    Do webmon.$initialize(EmailAddr,kInterval) Returns FlagOK
    Quit method FlagOK

  5. Add the following code near the end of the $signinOKContinue method.

    If FlagOK
       Do method initializeWebAppMonitor Returns FlagOK
    End If
    If not(FlagOK)
       Do errhndlr.$promptonceLastError()
    End If
    Quit method FlagOK

Startup Settings File

If you want web stats to be emailed to yourself or someone else will need to add constants values to the startupsettings.txt file.

  1. Open the startupsettings.txt file located inside the startupitems folder of your StudioWorks app.
  2. Add a constants properties section if one doesn't already exist and add the following constants values to be set during startup.

    constants {

    webappstatsemailaddr = youremail@yourdomain ;
    webappstatsinterval = kDay ;

    }



    You can set the webappstatsinterval to kDay, kWeek, kMonth, or kYear.

How SW Web Monitoring Works

When an HTTP request is received by the Omnis Web App Server the specified remote task is instantiated. After the request is completed the following sequence occurs:

  1. A $destruct message is sent to the remote task by Omnis Studio
  2. The $destruct method sends a $destructMethod message to oRemoteTaskMethods
  3. oRemoteTaskMethods sends an $addConnection($ctask,pEventCode) message to oWebMonitor.
  4. oWebMonitor inserts a record into the Webappstat table in the database. The record includes: the date/time the connection was opened, the IP address of the client making the request, the number of seconds to complete the request, the remote task which was instantiated.

A similar thing happens with the $event method of the remote task which sends a $eventMethod message to oRemoteTask methods. If the event code is evBusy or evRejected an $addConnection($ctask,pEventCode) message is sent to oWebMonitor. The event code is included in the Webappstat record that is inserted into the database.

Reports can then be generated from records in the Webappstat table.

If you provided a webappstatsemailaddr in the startupsettings.txt file, then the oWebStatsEmailTimer object will automatically send an email with the web stats shortly after the last day of the specified webappstatsinterval. The web stats report is generated by sending a $retWebStatsList message to oWebMonitor and then a $convertWebStatsListToText message. The text is then put into the body of an email and sent to the the specified webappstatsemailaddr.

You can generate web stats reports from your code as follows:

Do webmon.$retWebStatsList() Returns List
If List.$linecount
   Do webmon.$convertWebStatsListToText(List) Returns Text
End If