Event Analytics Client for Node.js¶
Introduction¶
The Event Analytics Service is used for analyzing event data. The service identifies significant dependencies and helps to get a better understanding of the system's internal processes using statistical analysis.
Further implementation of the EventAnalytics SDK library has been shown in a sample project that you can download and test in local or on Insights Hub application. Please refer to this repository: industrial-iot-node-sdk-examples
Event Operations services¶
The event operations client analyzes event data statistically to identify the most frequent events.
Client name: EventOperationsClient
Find Top Events¶
This method finds the N most frequently occurring events and returns them sorted by the number of occurrences in descending order.
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require EventOperationsClient from eventanalytics-sdk module
const EventOperationsClient = require('eventanalytics-sdk').EventOperationsClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the EventOperationsClient object
let event_operations_client = new EventOperationsClient(config, credentials);
let events_data = {
"numberOfTopPositionsRequired": 5,
"eventsMetadata": {
"eventTextPropertyName": "text"
},
"events": [
{
"_time": "2017-10-01T12:00:00.001Z",
"text": "INTRODUCING FUEL",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:01.001Z",
"text": "Status@Flame On",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:02.001Z",
"text": "Status@Flame On",
"text_qc": 0
}
]
};
try {
let response = await event_operations_client.topEvents({ data : events_data });
} catch (ex) {
// Exception handling
}
Filter Events¶
This method applies user defined filters to simplify the dataset based on the event text.
// Construct the EventOperationsClient object as shown above
let events_data = {
"eventsMetadata": {
"eventTextPropertyName": "text"
},
"events": [
{
"_time": "2017-10-01T12:00:00.001Z",
"text": "INTRODUCING FUEL",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:01.001Z",
"text": "Status@Flame On",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:02.001Z",
"text": "Status@Flame Off",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:03.001Z",
"text": "Error code: 340",
"text_qc": 0
}
],
"filterList": [
"INTRODUCING FUEL",
"MEANINGLESS ALARM",
"Status@Flame On"
]
};
try {
let response = await event_operations_client.filterEvents({ data : events_data });
} catch (ex) {
// Exception handling
}
Count Events¶
Determines the number of events per time interval for a user defined interval length.
// Construct the EventOperationsClient object as shown above
let events_data = {
"eventsMetadata": {
"eventTextPropertyName": "text",
"splitInterval": 5000
},
"events": [
{
"_time": "2017-10-01T12:00:06.001Z",
"text": "INTRODUCING FUEL",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:08.001Z",
"text": "Status@Flame On",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:09.001Z",
"text": "Status@Flame Off",
"text_qc": 0
}
]
};
try {
let response = await event_operations_client.countEvents({ data : events_data });
} catch (ex) {
// Exception handling
}
Remove Duplicate Events¶
This method removes duplicate events. It detects duplicate events within sliding window of user defined width (example 5,000Â ms) and reduces the data set by aggregating duplicate events.
// Construct the EventOperationsClient object as shown above
let events_data = {
"eventsMetadata": {
"eventTextPropertyName": "text",
"splitInterval": 5000
},
"events": [
{
"_time": "2017-10-01T12:00:00.001Z",
"text": "INTRODUCING FUEL",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:01.001Z",
"text": "Status@Flame On",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:02.001Z",
"text": "Status@Flame Off",
"text_qc": 0
}
]
}
try {
let response = await event_operations_client.removeDuplicateEvents({ data : events_data });
} catch (ex) {
// Exception handling
}
Pattern Operations Services¶
The Pattern Operations client analyzes the event data statistically to detect event patterns.
Client name: PatternOperationsClient
Find Event Patterns¶
Searches for user defined patterns in a list of events and detects all events matching the specified pattern(s).
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require PatternOperationsClient from eventanalytics-sdk module
const PatternOperationsClient = require('eventanalytics-sdk').PatternOperationsClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the PatternOperationsClient object
let pattern_operations_client = new PatternOperationsClient(config, credentials);
let event_pattern_input = {
"maxPatternInterval": 200000,
"patternsList": [
{
"pattern": [
{
"eventText": "INTRODUCING FUEL",
"minRepetitions": 1,
"maxRepetitions": 2
},
{
"eventText": "Status@Flame On",
"minRepetitions": 0,
"maxRepetitions": 1
}
]
},
{
"pattern": [
{
"eventText": "Downloading the module database causes module .. restart",
"minRepetitions": 1,
"maxRepetitions": 1
},
{
"eventText": "The SIMATIC mode was selected for time-of-day synchronization of the module with Id: ..",
"minRepetitions": 1,
"maxRepetitions": 1
}
]
}
],
"nonEvents": [
"Error 2.. occurred",
"STOPPING ENGINE"
],
"eventsInput": {
"eventsMetadata": {
"eventTextPropertyName": "text"
},
"events": [
{
"_time": "2017-10-01T12:00:00.001Z",
"text": "Downloading the module database causes module 11 restart",
"text_qc": 0
},
{
"_time": "2017-10-01T12:00:01.001Z",
"text": "The direction for forwarding the time of day is recognized automatically by the module",
"text_qc": 0
}
]
}
};
try {
let response = await pattern_operations_client.matchPatternsOverEvents({ data : event_pattern_input });
} catch (ex) {
// Exception handling
}