Quantcast
Channel: Siggi Gladitsch Tracker
Viewing all articles
Browse latest Browse all 426

Re: Custom Database monitors Logging

$
0
0

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


Viewing all articles
Browse latest Browse all 426

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>