Node.js 的 Event Analytics Client¶
简介¶
Event Analytics Service 用于分析事件数据。该服务识别重要的依赖关系,并使用统计分析帮助更好地理解系统的内部流程。更多有关此服务的信息,请参考 Event Analytics。
Event Operations services¶
Event Operations 客户端对事件数据进行统计以识别最频繁的事件。
客户端名称: EventOperationsClient
查找最频繁事件¶
该方法找到 N 个最频繁发生的事件,并按事件数量降序返回它们。
// 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
}
过滤事件¶
该方法应用用户定义的过滤器来基于事件文本简化数据集。
// 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
}
计数事件¶
确定用户定义的时间间隔长度的每个间隔事件数。
// 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
}
移除重复事件¶
该方法移除重复事件。它检测用户定义宽度(例如:5000毫秒)的滑动窗口内的重复事件,并通过聚合重复事件以减少数据集。
// 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¶
Pattern Operations 客户端对事件数据进行统计分析来检测事件模式。
客户端名称: PatternOperationsClient
查找事件模式¶
在事件列表中搜索用户定义的模式,并检测与指定模式匹配的所有事件。
// 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
}
Last update: March 22, 2023