From 4a54c7687dd609d5add72fdbe1d747fffc20e49e Mon Sep 17 00:00:00 2001 From: Lemon Date: Sat, 2 Mar 2019 09:36:48 +0800 Subject: [PATCH] Add clr metrics scope and oal script (#2297) * Add CLR metric scope and oal_script * Add max indicator * Fix checkstyle --- .../skywalking/oal/tool/grammar/OALLexer.g4 | 3 + .../skywalking/oal/tool/grammar/OALParser.g4 | 3 +- .../main/resources/generator-scope-meta.yml | 30 +++++++ .../src/main/resources/official_analysis.oal | 13 ++- .../core/analysis/indicator/MaxIndicator.java | 56 +++++++++++++ .../core/source/DefaultScopeDefine.java | 3 + .../core/source/ServiceInstanceCLRCPU.java | 44 ++++++++++ .../core/source/ServiceInstanceCLRGC.java | 47 +++++++++++ .../core/source/ServiceInstanceCLRThread.java | 47 +++++++++++ .../analysis/indicator/MaxIndicatorTest.java | 84 +++++++++++++++++++ 10 files changed, 328 insertions(+), 2 deletions(-) create mode 100644 oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/MaxIndicator.java create mode 100644 oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRCPU.java create mode 100644 oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRGC.java create mode 100644 oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRThread.java create mode 100644 oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/indicator/MaxIndicatorTest.java diff --git a/oap-server/generate-tool-grammar/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALLexer.g4 b/oap-server/generate-tool-grammar/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALLexer.g4 index 2e0995e84..9eefd446a 100644 --- a/oap-server/generate-tool-grammar/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALLexer.g4 +++ b/oap-server/generate-tool-grammar/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALLexer.g4 @@ -38,6 +38,9 @@ SRC_SERVICE_INSTANCE_JVM_MEMORY: 'ServiceInstanceJVMMemory'; SRC_SERVICE_INSTANCE_JVM_MEMORY_POOL: 'ServiceInstanceJVMMemoryPool'; SRC_SERVICE_INSTANCE_JVM_GC: 'ServiceInstanceJVMGC'; SRC_DATABASE_ACCESS: 'DatabaseAccess'; +SRC_SERVICE_INSTANCE_CLR_CPU: 'ServiceInstanceCLRCPU'; +SRC_SERVICE_INSTANCE_CLR_GC: 'ServiceInstanceCLRGC'; +SRC_SERVICE_INSTANCE_CLR_THREAD: 'ServiceInstanceCLRThread'; // Literals diff --git a/oap-server/generate-tool-grammar/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALParser.g4 b/oap-server/generate-tool-grammar/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALParser.g4 index 82221c8b9..a94dbe2a7 100644 --- a/oap-server/generate-tool-grammar/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALParser.g4 +++ b/oap-server/generate-tool-grammar/src/main/antlr4/org/apache/skywalking/oal/tool/grammar/OALParser.g4 @@ -48,7 +48,8 @@ filterExpression source : SRC_ALL | SRC_SERVICE | SRC_DATABASE_ACCESS | SRC_SERVICE_INSTANCE | SRC_ENDPOINT | SRC_SERVICE_RELATION | SRC_SERVICE_INSTANCE_RELATION | SRC_ENDPOINT_RELATION | - SRC_SERVICE_INSTANCE_JVM_CPU | SRC_SERVICE_INSTANCE_JVM_MEMORY | SRC_SERVICE_INSTANCE_JVM_MEMORY_POOL | SRC_SERVICE_INSTANCE_JVM_GC// JVM source of service instance + SRC_SERVICE_INSTANCE_JVM_CPU | SRC_SERVICE_INSTANCE_JVM_MEMORY | SRC_SERVICE_INSTANCE_JVM_MEMORY_POOL | SRC_SERVICE_INSTANCE_JVM_GC |// JVM source of service instance + SRC_SERVICE_INSTANCE_CLR_CPU | SRC_SERVICE_INSTANCE_CLR_GC | SRC_SERVICE_INSTANCE_CLR_THREAD ; sourceAttribute diff --git a/oap-server/generated-analysis/src/main/resources/generator-scope-meta.yml b/oap-server/generated-analysis/src/main/resources/generator-scope-meta.yml index 004a400fb..2e2c9f54c 100644 --- a/oap-server/generated-analysis/src/main/resources/generator-scope-meta.yml +++ b/oap-server/generated-analysis/src/main/resources/generator-scope-meta.yml @@ -134,3 +134,33 @@ scopes: columnName: entity_id typeName: java.lang.String ID: true + - name: ServiceInstanceCLRCPU + columns: + - fieldName: entityId + columnName: entity_id + typeName: java.lang.String + ID: true + - fieldName: serviceInstanceId + columnName: service_instance_id + typeName: int + ID: false + - name: ServiceInstanceCLRGC + columns: + - fieldName: entityId + columnName: entity_id + typeName: java.lang.String + ID: true + - fieldName: serviceInstanceId + columnName: service_instance_id + typeName: int + ID: false + - name: ServiceInstanceCLRThread + columns: + - fieldName: entityId + columnName: entity_id + typeName: java.lang.String + ID: true + - fieldName: serviceInstanceId + columnName: service_instance_id + typeName: int + ID: false \ No newline at end of file diff --git a/oap-server/generated-analysis/src/main/resources/official_analysis.oal b/oap-server/generated-analysis/src/main/resources/official_analysis.oal index 57c2abcca..808ce583b 100644 --- a/oap-server/generated-analysis/src/main/resources/official_analysis.oal +++ b/oap-server/generated-analysis/src/main/resources/official_analysis.oal @@ -79,4 +79,15 @@ database_access_p99 = from(DatabaseAccess.latency).p99(10); database_access_p95 = from(DatabaseAccess.latency).p95(10); database_access_p90 = from(DatabaseAccess.latency).p90(10); database_access_p75 = from(DatabaseAccess.latency).p75(10); -database_access_p50 = from(DatabaseAccess.latency).p50(10); \ No newline at end of file +database_access_p50 = from(DatabaseAccess.latency).p50(10); + +// CLR instance metric +instance_clr_cpu = from(ServiceInstanceCLRCPU.usePercent).doubleAvg(); +instance_clr_gen0_collect_count = from(ServiceInstanceCLRGC.gen0CollectCount).sum(); +instance_clr_gen1_collect_count = from(ServiceInstanceCLRGC.gen1CollectCount).sum(); +instance_clr_gen2_collect_count = from(ServiceInstanceCLRGC.gen2CollectCount).sum(); +instance_clr_heap_memory = from(ServiceInstanceCLRGC.heapMemory).longAvg(); +instance_clr_available_completion_port_threads = from(ServiceInstanceCLRThread.availableCompletionPortThreads).max(); +instance_clr_available_worker_threads = from(ServiceInstanceCLRThread.availableWorkerThreads).max(); +instance_clr_max_completion_port_threads = from(ServiceInstanceCLRThread.maxCompletionPortThreads).max(); +instance_clr_max_worker_threads = from(ServiceInstanceCLRThread.maxWorkerThreads).max(); diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/MaxIndicator.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/MaxIndicator.java new file mode 100644 index 000000000..be968d4c7 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/MaxIndicator.java @@ -0,0 +1,56 @@ +/* + * 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.analysis.indicator; + +import lombok.Getter; +import lombok.Setter; +import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.Entrance; +import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorFunction; +import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.SourceFrom; +import org.apache.skywalking.oap.server.core.storage.annotation.Column; + +/** + * @author liuhaoyang + **/ +@IndicatorFunction(functionName = "max") +public abstract class MaxIndicator extends Indicator implements LongValueHolder { + + protected static final String VALUE = "value"; + + @Getter @Setter @Column(columnName = VALUE, isValue = true) private long value; + + @Entrance + public final void combine(@SourceFrom long count) { + if (count > this.value) { + this.value = count; + } + } + + @Override public final void combine(Indicator indicator) { + MaxIndicator countIndicator = (MaxIndicator)indicator; + combine(countIndicator.value); + } + + @Override public void calculate() { + } + + @Override public long getValue() { + return value; + } +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java index 4bf9b6d58..9cccb2e82 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java @@ -50,6 +50,9 @@ public class DefaultScopeDefine { public static final int ENDPOINT_INVENTORY = 16; public static final int DATABASE_ACCESS = 17; public static final int DATABASE_SLOW_STATEMENT = 18; + public static final int SERVICE_INSTANCE_CLR_CPU = 19; + public static final int SERVICE_INSTANCE_CLR_GC = 20; + public static final int SERVICE_INSTANCE_CLR_THREAD = 21; public static class Listener implements AnnotationListener { @Override public Class annotation() { diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRCPU.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRCPU.java new file mode 100644 index 000000000..f5fe55b9e --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRCPU.java @@ -0,0 +1,44 @@ +/* + * 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.source; + +import lombok.Getter; +import lombok.Setter; + +import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CLR_CPU; + +/** + * @author liuhaoyang + **/ +@ScopeDeclaration(id = SERVICE_INSTANCE_CLR_CPU, name = "ServiceInstanceCLRCPU") +public class ServiceInstanceCLRCPU extends Source { + @Override public int scope() { + return DefaultScopeDefine.SERVICE_INSTANCE_CLR_CPU; + } + + @Override public String getEntityId() { + return String.valueOf(id); + } + + @Getter @Setter private int id; + @Getter @Setter private String name; + @Getter @Setter private String serviceName; + @Getter @Setter private int serviceInstanceId; + @Getter @Setter private double usePercent; +} \ No newline at end of file diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRGC.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRGC.java new file mode 100644 index 000000000..d87253b0f --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRGC.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.source; + +import lombok.Getter; +import lombok.Setter; + +import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CLR_GC; + +/** + * @author liuhaoyang + **/ +@ScopeDeclaration(id = SERVICE_INSTANCE_CLR_GC, name = "ServiceInstanceCLRGC") +public class ServiceInstanceCLRGC extends Source { + @Override public int scope() { + return DefaultScopeDefine.SERVICE_INSTANCE_CLR_GC; + } + + @Override public String getEntityId() { + return String.valueOf(id); + } + + @Getter @Setter private int id; + @Getter @Setter private String name; + @Getter @Setter private String serviceName; + @Getter @Setter private int serviceInstanceId; + @Getter @Setter private int gen0CollectCount; + @Getter @Setter private int gen1CollectCount; + @Getter @Setter private int gen2CollectCount; + @Getter @Setter private long heapMemory; +} \ No newline at end of file diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRThread.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRThread.java new file mode 100644 index 000000000..877be5954 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRThread.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.source; + +import lombok.Getter; +import lombok.Setter; + +import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CLR_THREAD; + +/** + * @author liuhaoyang + **/ +@ScopeDeclaration(id = SERVICE_INSTANCE_CLR_THREAD, name = "ServiceInstanceCLRThread") +public class ServiceInstanceCLRThread extends Source { + @Override public int scope() { + return DefaultScopeDefine.SERVICE_INSTANCE_CLR_THREAD; + } + + @Override public String getEntityId() { + return String.valueOf(id); + } + + @Getter @Setter private int id; + @Getter @Setter private String name; + @Getter @Setter private String serviceName; + @Getter @Setter private int serviceInstanceId; + @Getter @Setter private long availableCompletionPortThreads; + @Getter @Setter private long availableWorkerThreads; + @Getter @Setter private long maxCompletionPortThreads; + @Getter @Setter private long maxWorkerThreads; +} \ No newline at end of file diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/indicator/MaxIndicatorTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/indicator/MaxIndicatorTest.java new file mode 100644 index 000000000..0c2ebd602 --- /dev/null +++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/indicator/MaxIndicatorTest.java @@ -0,0 +1,84 @@ +/* + * 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.analysis.indicator; + +import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author liuhaoyang + **/ +public class MaxIndicatorTest { + + @Test + public void testEntranceCombine() { + MaxIndicatorImpl impl = new MaxIndicatorImpl(); + impl.combine(10); + impl.combine(5); + impl.combine(20); + impl.calculate(); + Assert.assertEquals(20, impl.getValue()); + } + + @Test + public void testSelfCombine() { + MaxIndicatorImpl impl = new MaxIndicatorImpl(); + impl.combine(10); + impl.combine(5); + + MaxIndicatorImpl impl2 = new MaxIndicatorImpl(); + impl.combine(2); + impl.combine(6); + + impl.combine(impl2); + Assert.assertEquals(10, impl.getValue()); + } + + public class MaxIndicatorImpl extends MaxIndicator { + + @Override public String id() { + return null; + } + + @Override public Indicator toHour() { + return null; + } + + @Override public Indicator toDay() { + return null; + } + + @Override public Indicator toMonth() { + return null; + } + + @Override public int remoteHashCode() { + return 0; + } + + @Override public void deserialize(RemoteData remoteData) { + + } + + @Override public RemoteData.Builder serialize() { + return null; + } + } +}