Tech Tip: Generate Activity Monitor Logs
PRODUCT: 4D | VERSION: 18 R | PLATFORM: Mac & Win
Published On: April 5, 2021
4D v18R3 introduces a new feature that allows activities to be monitored and recorded if the activity takes longer than a specified threshold.
Below is a utility method to save activity logs to the disk in a at a specified frequency.
// Util_ActivityMonitorLogging: C_REAL($1;$thresh_r) C_LONGINT($2;$frequency_l) C_LONGINT($3;$source_l) C_COLLECTION($activities_c) If (Count parameters>0) $thresh_r := $1 $frequency_l:=$2*60 If (Count parameters>2) $source_l:=$2 Else $source_l:=-1 End if START MONITORING ACTIVITY($thresh_r;$source_l) While(Not(Process aborted)) $activities:=Get Monitored Activity $text:=JSON Stringify($activities.orderBy("startTime");*) TEXT TO DOCUMENT("activity_log.txt";$text) DELAY PROCESS(Current process;$frequency_l) End while End if |
The first parameter is the threshold in seconds. This is the minimum time that is needed for an activity to be logged.
The second paramter is the frequncy, in minutes, that the on disk activities log should be updated. The feature stores the activites in an object accessable by the Get Monitored Activity command and does not generate an on disk log.
The last and optional parameter is the type of activites to monitor. The following are the possible activities selectors:
It is also possible to specifiy two out of three selectors by summing them. For example the following three are all valid and the same:
- 1+4
- Activity language + Activity operations
- 5
Below is an example of starting the store procedure:
C_LONGINT($proc_l) $proc_l:=New process("Util_ActivityMonitorLogging"; 0; 2.5; 5; Activity all) |
The example will monitor all activities and record any activities that take longer than 2.5 seconds. A log will be generated and updated every 5 minutes.