You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2018/11/30 13:28:12 UTC

[incubator-skywalking] 01/01: Support alarm in service instance and endpoint.

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch endpoint-and-instance-alarm
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git

commit 47a38254ac5f871d3138c109e773e37f81e715e0
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Fri Nov 30 21:27:57 2018 +0800

    Support alarm in service instance and endpoint.
---
 .../oap/server/core/alarm/AlarmEntrance.java       | 32 +++++++++++++++
 .../oap/server/core/alarm/EndpointMetaInAlarm.java | 47 ++++++++++++++++++++++
 .../core/alarm/ServiceInstanceMetaInAlarm.java     | 47 ++++++++++++++++++++++
 .../src/main/assembly/alarm-settings.yml           | 25 +++++++++---
 4 files changed, 146 insertions(+), 5 deletions(-)

diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmEntrance.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmEntrance.java
index 3992841..5490a17 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmEntrance.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmEntrance.java
@@ -21,7 +21,11 @@ package org.apache.skywalking.oap.server.core.alarm;
 import java.util.concurrent.locks.ReentrantLock;
 import org.apache.skywalking.oap.server.core.CoreModule;
 import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
+import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
+import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
 import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
+import org.apache.skywalking.oap.server.core.register.EndpointInventory;
+import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
 import org.apache.skywalking.oap.server.core.register.ServiceInventory;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
 
@@ -31,6 +35,8 @@ import org.apache.skywalking.oap.server.library.module.ModuleManager;
 public class AlarmEntrance {
     private ModuleManager moduleManager;
     private ServiceInventoryCache serviceInventoryCache;
+    private ServiceInstanceInventoryCache serviceInstanceInventoryCache;
+    private EndpointInventoryCache endpointInventoryCache;
     private IndicatorNotify indicatorNotify;
     private ReentrantLock initLock;
 
@@ -59,6 +65,30 @@ public class AlarmEntrance {
                 serviceMetaInAlarm.setName(serviceInventory.getName());
                 metaInAlarm = serviceMetaInAlarm;
                 break;
+            case ServiceInstance:
+                int serviceInstanceId = Integer.parseInt(alarmMeta.getId());
+                ServiceInstanceInventory serviceInstanceInventory = serviceInstanceInventoryCache.get(serviceInstanceId);
+                ServiceInstanceMetaInAlarm instanceMetaInAlarm = new ServiceInstanceMetaInAlarm();
+                instanceMetaInAlarm.setIndicatorName(alarmMeta.getIndicatorName());
+                instanceMetaInAlarm.setId(serviceInstanceId);
+                instanceMetaInAlarm.setName(serviceInstanceInventory.getName());
+                metaInAlarm = instanceMetaInAlarm;
+                break;
+            case Endpoint:
+                int endpointId = Integer.parseInt(alarmMeta.getId());
+                EndpointInventory endpointInventory = endpointInventoryCache.get(endpointId);
+                EndpointMetaInAlarm endpointMetaInAlarm = new EndpointMetaInAlarm();
+                endpointMetaInAlarm.setIndicatorName(alarmMeta.getIndicatorName());
+                endpointMetaInAlarm.setId(endpointId);
+
+                serviceId = endpointInventory.getServiceId();
+                serviceInventory = serviceInventoryCache.get(serviceId);
+
+                String textName = endpointInventory.getName() + " in " + serviceInventory.getName();
+
+                endpointMetaInAlarm.setName(textName);
+                metaInAlarm = endpointMetaInAlarm;
+                break;
             default:
                 return;
         }
@@ -72,6 +102,8 @@ public class AlarmEntrance {
             try {
                 if (serviceInventoryCache == null) {
                     serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
+                    serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
+                    endpointInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
                     indicatorNotify = moduleManager.find(AlarmModule.NAME).provider().getService(IndicatorNotify.class);
                     indicatorNotify.init(new AlarmStandardPersistence());
                 }
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/EndpointMetaInAlarm.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/EndpointMetaInAlarm.java
new file mode 100644
index 0000000..10b859f
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/EndpointMetaInAlarm.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.core.alarm;
+
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.skywalking.oap.server.core.source.Scope;
+
+@Getter(AccessLevel.PUBLIC)
+@Setter(AccessLevel.PUBLIC)
+public class EndpointMetaInAlarm extends MetaInAlarm {
+    private String indicatorName;
+
+    private int id;
+    private String name;
+    private String[] tags;
+    private String[] properties;
+
+    @Override public Scope getScope() {
+        return Scope.Endpoint;
+    }
+
+    @Override public int getId0() {
+        return id;
+    }
+
+    @Override public int getId1() {
+        return 0;
+    }
+}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/ServiceInstanceMetaInAlarm.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/ServiceInstanceMetaInAlarm.java
new file mode 100644
index 0000000..4c8862a
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/ServiceInstanceMetaInAlarm.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.core.alarm;
+
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.skywalking.oap.server.core.source.Scope;
+
+@Getter(AccessLevel.PUBLIC)
+@Setter(AccessLevel.PUBLIC)
+public class ServiceInstanceMetaInAlarm extends MetaInAlarm {
+    private String indicatorName;
+
+    private int id;
+    private String name;
+    private String[] tags;
+    private String[] properties;
+
+    @Override public Scope getScope() {
+        return Scope.ServiceInstance;
+    }
+
+    @Override public int getId0() {
+        return id;
+    }
+
+    @Override public int getId1() {
+        return 0;
+    }
+}
diff --git a/oap-server/server-starter/src/main/assembly/alarm-settings.yml b/oap-server/server-starter/src/main/assembly/alarm-settings.yml
index 5b839fb..5fdaa7b 100644
--- a/oap-server/server-starter/src/main/assembly/alarm-settings.yml
+++ b/oap-server/server-starter/src/main/assembly/alarm-settings.yml
@@ -24,28 +24,43 @@ rules:
     period: 10
     count: 3
     silence-period: 5
-    message: Response time of service {name} is more than 2000ms.
+    message: Response time of service {name} is more than 1000ms in last 3 minutes.
   service_sla_rule:
     # Indicator value need to be long, double or int
     indicator-name: service_sla
     op: "<"
-    threshold: 80
+    threshold: 8000
     # The length of time to evaluate the metric
     period: 10
     # How many times after the metric match the condition, will trigger alarm
     count: 2
     # How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.
     silence-period: 3
-    message: Successful rate of service {name} is lower than 80%
+    message: Successful rate of service {name} is lower than 80% in last 2 minuts.
   service_p90_sla_rule:
     # Indicator value need to be long, double or int
-    indicator-name: service_sla
+    indicator-name: service_p90
     op: ">"
     threshold: 1000
     period: 10
     count: 3
     silence-period: 5
-    message: 90% response time of service {name} is lower than 80%
+    message: 90% response time of service {name} is lower than 1000ms in last 3 minutes
+  service_instance_resp_time_rule:
+    indicator-name: service_instance_resp_time
+    op: ">"
+    period: 10
+    count: 3
+    silence-period: 5
+    message: Response time of service instance {name} is more than 1000ms in last 3 minutes.
+  endpoint_sla_rule:
+    indicator-name: endpoint_sla
+    op: "<"
+    threshold: 8000
+    period: 10
+    count: 2
+    silence-period: 3
+    message: Successful rate of endpoint {name} is lower than 80% in last 2 minuts.
 
 webhooks:
 #  - http://127.0.0.1/notify/