HDI: Monitor your 4D application activity
You can specify the kind of activity you want to monitor:
- 4D data activity: operations involving the 4D data itself,
- Network activity: you’ll get the same information as in the 4DRequestsLog file (*),
- Language execution: you’ll get the same information as in the 4DDebugLog file (*).
(*) There’s no need to activate the corresponding log files, so no space on the disk is used.
START MONITORING ACTIVITY command
The START MONITORING ACTIVITY command takes the duration threshold and the type of operations to monitor as parameters. For this, the following new constants can be used to monitor:
- Activity operations: operations in the 4D data
- Activity network: operations of the network activity
- Activity language: operations of the language execution
Get Monitored Activity command
When you want to get all the recorded activity, just call the new Get Monitored Activity() command!
It returns a collection of objects with the relevant information that you can use as you wish (generate a file, display an interface for the administrator, etc.).
STOP MONITORING ACTIVITY command
When you want to stop recording your 4D application activity or to empty the memory, just call the STOP MONITORING ACTIVITY command.
concrete EXAMPLE
In most cases, your need will be:
Every 10 minutes, I want to check if some operations have lasted more than 10 seconds on my 4D Server. If yes, I want to send an email to the administrator (or take another action).
The following is some code to do just that.
ON server startup method
C_LONGINT($monitorProcessId)
STOP MONITORING ACTIVITY
// Detect 4D data operations which lasted more than 10s
START MONITORING ACTIVITY(10;Activity operations)
//Run a monitoring process
$monitorProcessId:=New process("monitorOperations";0;"Monitor operations")
monitoring process (to be run on the server)
C_COLLECTION($activities)
While(Not(Process aborted))
// Inspect 4D data activity every 10 minutes
DELAY PROCESS(Current process;36000)
// Get the long operations and exclude backup operations
$activities:=Get Monitored Activity().query("Not(activityData.message IN :1)";New collection("@backup@"))
If ($activities.length#0)
// Send an email to the administrator with $activities details
// Empty the memory and restart the monitoring
STOP MONITORING ACTIVITY
START MONITORING ACTIVITY(10;Activity operations)
End if
End while
on server shutdown method
C_COLLECTION($activities)
$activities:=Get Monitored Activity().query("Not(activityData.message IN :1)";New collection("@backup@"))
If ($activities.length#0)
// Send an email to the administrator with $activities details
End if