-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathevent_handler_publisher_delay_logging.js
More file actions
59 lines (54 loc) · 2.31 KB
/
event_handler_publisher_delay_logging.js
File metadata and controls
59 lines (54 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* This event handler can be used in conjunction with a "Point value update"
* detector to log the difference between the point value timestamp from the
* edge and the actual time the value was received & processed in the cloud.
*/
const Common = Java.type('com.serotonin.m2m2.Common');
const tagNamesToLog = ['site', 'deviceId'];
/*
* Called when the Mango event is raised.
* You must implement this method.
*
* @param event
*/
function eventRaised(event) {
try{
//Confirm this eventType is a data point
const currEventType = event.getEventType();
if (currEventType.toString().substring(0,18) === 'DataPointEventType') {
//Get the event context so we can access the triggering data point
const context = event.getContext();
const eventPoint = context.get('point');
const rt = Common.runtimeManager.getDataPoint(eventPoint.getId());
//Loop through the list of tags that should be logged with the data point information
//This can be useful when identifying patterns for publishing delays
let tagLogs = '';
tagNamesToLog.forEach(function(tagKey) {
tagLogs = tagLogs + tagKey + 'Tag: ' + eventPoint.getTags().get(tagKey) + ', '
});
log.debug('Publisher Delay Check: pointName: {}, pointXid: {}, {} value: {}, valueTimeStamp: {}, currentTimeStamp: {}, publishDelayDelta: {}',eventPoint.getName(), eventPoint.getXid(), tagLogs, rt.getPointValue().getValue(), rt.getPointValue().getTime(), Common.timer.currentTimeMillis(), (Common.timer.currentTimeMillis()-rt.getPointValue().getTime()));
}
}
catch (outerEx) {
log.error('Publisher Delay Check:Unhandled exception', outerEx);
return;
}
}
/*
* Called when the Mango event is acknowledged (the event may still be active).
* Supported as of Mango v4.0.0-beta.14, you are not required to implement this method.
*
* @param event
*/
function eventAcknowledged(event) {
//console.log('Acknowledged', event);
}
/*
* Called when the Mango event returns to normal or is deactivated (e.g. on shutdown).
* You must implement this method.
*
* @param event
*/
function eventInactive(event) {
//console.log('Inactive', event);
}