Custom Database monitors Logging

Hello,

I am developping a new Custom Database monitors and this is my first time. The documentation and examples state that in order to enable debugging and writing to a log, I have to declare a variable:

var logger = myContext.getMonitorLog();

then I write to the log using:

logger.info("Processing the query");

so the log <SiteScope>\logs\custom_monitors\custom_monitor.log should have the entry: "Processing the query" 

but it doesnt. Is this the right process? am I missing a step somewhere? the log exists but it has nothing in it.

Thanks,

 

 

Parents
  • Hi Nabil,

    I assume that the log4j.properties file is not setup as required.
    While INFO level messages should always be logged, you might wanna change it (for a test) to
     logger.debug("Processing the query");

    and then modify the file (as outlined in "Custom Monitor Troubleshooting")
    ..
    To change the log level to DEBUG mode, in <SiteScope root
    directory>\conf\core\Tools\log4j\PlainJava\log4j.properties, change ${loglevel} to DEBUG in the
    following paragraph:
    # Custom monitors category
    log4j.category.CustomMonitor=${loglevel},custom.monitor.appender
    log4j.additivity.CustomMonitor=false
    save the file, wait two minutes, and then execute the monitor again.

    The messages can be found in the file <SiteScope root directory>\logs\custom_monitors\custom_monitor.log.
    Unfortunately the plain existance of the file doesn't mean that all works as expected ...

    Greetings
    Siggi

Reply
  • Hi Nabil,

    I assume that the log4j.properties file is not setup as required.
    While INFO level messages should always be logged, you might wanna change it (for a test) to
     logger.debug("Processing the query");

    and then modify the file (as outlined in "Custom Monitor Troubleshooting")
    ..
    To change the log level to DEBUG mode, in <SiteScope root
    directory>\conf\core\Tools\log4j\PlainJava\log4j.properties, change ${loglevel} to DEBUG in the
    following paragraph:
    # Custom monitors category
    log4j.category.CustomMonitor=${loglevel},custom.monitor.appender
    log4j.additivity.CustomMonitor=false
    save the file, wait two minutes, and then execute the monitor again.

    The messages can be found in the file <SiteScope root directory>\logs\custom_monitors\custom_monitor.log.
    Unfortunately the plain existance of the file doesn't mean that all works as expected ...

    Greetings
    Siggi

Children
  • Hi Nabil,

    I made some tests,
    and in fact
     logger.info("any text");
    doesn't work,
    but
     logger.error("any text");
    works by not changing any settings in the <SiteScope root directory>\conf\core\Tools\log4j\PlainJava\log4j.properties file,
    which by default are
    # Custom monitors category
    log4j.category.CustomMonitor=${loglevel}, custom.monitor.appender
    log4j.additivity.CustomMonitor=false

    2016-12-13 16:59:27 - Error  - Hallo - 1
    2016-12-13 16:59:27 - Error  - Hallo - 2

    When changing this to
    # Custom monitors category
    log4j.category.CustomMonitor=INFO, custom.monitor.appender
    log4j.additivity.CustomMonitor=false

     logger.info("any text");
    also works.

    2016-12-13 16:59:27 - Info   - Hallo - 1
    2016-12-13 16:59:27 - Result size = 1
    2016-12-13 16:59:27 - Info   - Hallo - 2

    Here is the sample code, I simply used the Custom Log File Monitor Script Example provided as part of the SiteScope installation:

     // Java imports                                             
     importPackage(java.lang);
     // Logger for debug messages. The logger writes messages to <SiteScope>\logs\custom_monitors\custom_monitor.log
     var logger = myContext.getMonitorLog();
                                     
     logger.info( "Info   - Hallo - 1");
     logger.error("Error  - Hallo - 1");
                                     
     // Returns string data from a monitor storage, and saves it to memory from the previous monitor run
     var storedString = myContext.getMonitorStorage().get("StoredString_1");
     
     // Returns  object data that was saved in memory in the monitor storage during the previous monitor run
     var storedObject = myContext.getObjectMonitorStorage().get("StoredObject_1");
     
     // Returns  monitor properties from the script, for example, monitor name
     var monitorName = myContext.getInputData().getConfigurationParameter("monitorName");
     
     // Returns the size of the data returned from a match or a query
     // First parameter is a query index; for Custom Log File monitor, this parameter is always "0"
     // Second parameter is a name of a "match value label"
     var size = myContext.getInputData().getQueryColumnResultSize(0 , "Used Memory");
     
     // Writes the result info to the log
     logger.info("Result size = " size);

     var summary = 0;

     // Returns a result after a run of match or a query
     for (i = 0; i < size ; i ) {
      // First parameter is a query index; for Custom Log File monitor, this parameter is always "0"
      // Second parameter is a record index
      // Third parameter is a name of a "match value label"
      if (! myContext.getInputData().getValueAt(0 , i , "Used Memory").isEmpty() ) {

       var value = new Integer(myContext.getInputData().getValueAt(0 , i , "Used Memory")).intValue();
       summary = summary value;

      }
     }

     if(size!=0){
      // Creates a metric
       myContext.getScriptResult().setValue("Average of Used Memory" , summary/size);
     }

     // Adds a string to the monitor storage for the next run
     myContext.getMonitorStorage().add("StoredString_1" , storedString);

     // Adds an object to the monitor storage for the next run
     myContext.getObjectMonitorStorage().add("StoredObject_1" , storedObject);

     // Sets the a monitor summary string                                                                                                                                             
     myContext.getScriptResult().setSummary("summary of the script");

     // Sets monitor availability
     myContext.getScriptResult().setAvailability(true);
                                           
     logger.info( "Info   - Hallo - 2");
     logger.error("Error  - Hallo - 2");

    Greetings
    Siggi