Unit 4: Configuring Alert¶
To monitor the performance of your devices, you can define customized alert severities, alert types, alert content, and alert rules for any device anomaly. This unit shows how to enable alerts to monitor the data of the water meter. Refer to the steps below.
Step 1: Creating Alert Source¶
As the data from the water meter is of non-EnOS standard data format, this step creates an alert source to monitor the Kafka message and customize the conversion method to construct the alert metric using a data mapping JAR package.
For more information, see Alert Sources.
Data Mapping JAR Package¶
The JAR package will implement the StandardMetricResolver
method which will be defined when creating the alert source later to take out the flow value in the Kafka message and convert it to alert data.
Include the dependency by adding the following code snippet.
<dependency> <groupId>com.envisioniot.enos</groupId> <artifactId>alert-engine-share</artifactId> <version>0.1.10-SNAPSHOT</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency>
Use the example code below to create a parsing class that implements
StandardMetricResolver
.package com.example.alertsource; import com.envisioniot.enos.alert_engine.core.share.datasource.dto.codec.StandardMetricResolver; import com.envisioniot.enos.alert_engine.core.share.metric.dto.Metric; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import lombok.extern.slf4j.Slf4j; import java.util.Map; @Slf4j public class CodecAlertData implements StandardMetricResolver { private static final String METRIC = "flow"; private static final String ORG_ID = "yourOrgId"; private static final String INSTANCE = "XolflP2C"; private static final String TIMEZONE = "+08:00"; private static final Gson GSON = new Gson(); @Override public void init() { // do nothing } @Override public Metric decode(String msg, Map<String, String> context) { log.info("consume msg: {}, context: {}", msg, context); Metric metric = new Metric(); try { Map<String, Object> inputData = GSON.fromJson(msg, new TypeToken<Map<String, Object>>() {}.getType()); final long timestamp = System.currentTimeMillis(); metric.setMetric(METRIC); metric.setOrgId(ORG_ID); metric.setInstance(INSTANCE); metric.setTimezone(TIMEZONE); metric.setTimestamp(timestamp); metric.setValue(String.valueOf(inputData.get(METRIC))); log.info("output metric: {}", metric); return metric; } catch (Throwable t) { log.error("process data error, ", t); return metric; } } }
Create a JAR file from the above.
Alert Source¶
In EnOS Management Console, select Alert Engine > Alert Sources.
Click New Alert Source, and enter the following in the Source page.
Name: Water Meter Alert Source
Type: Kafka Client
Topic: Enter the topic given in the Kafka Pub node in the routing rule created in Unit 3.
Click Next, and enter the following in the Data Mapping page.
Method: JAR
Class Name: com.example.alertsource.CodecAlertData
File: Upload the JAR file created above.
Click Save to save the configuration.
At the Alert Source page, enable the alert source.
Step 2: Creating Alert Severity¶
In EnOS Management Console, select Alert Engine > Alert Severities.
Click New Severity, and enter the following in the New Severity window.
Severity ID: WaterMeterWarning
Severity Description: Warning
Click Confirm to save the configuration.
For more information, see Alert Severities.
Step 3: Creating Alert Type¶
In EnOS Management Console, select Alert Engine > Alert Types.
Click New Type, and enter the following in the New Type window.
Type ID: FlowOverThreshold
Type Description: Flow over threshold
Click Confirm to save the configuration.
For more information, see Alert Types.
Step 4: Creating Alert Rule¶
In EnOS Management Console, select Alert Engine > Alert Rules.
Click New Rule, enter the following in the Add Alert Rule window, and click Confirm when done.
For more information, see Alert Rules.
Basic Information¶
Rule Name: Water Meter Rule
Rule ID: RuleForWaterMeter
Trigger¶
Specify the trigger metric.
Trigger Source: Others
Alert Source: Select the alert source created in step 1 above (Water Meter Alert Source)
Metric: flow
Data Type: Number
Alert Condition¶
Set the alert condition to trigger the alert if the value of flow equals to or exceeds 10000.
Alert Condition: Threshold
Trigger: flow
Operator: >=
Type: Value
Value: 10000
Alert Details¶
Alert Content: Flow is over 10000
Alert Severity: Select the alert severity created in step 2 (Warning).
Alert Type: Select the alert type created in step 3 (Flow over threshold).