Add clr metrics scope and oal script (#2297)

* Add CLR metric scope and oal_script

* Add max indicator

* Fix checkstyle
This commit is contained in:
Lemon 2019-03-02 09:36:48 +08:00 committed by 吴晟 Wu Sheng
parent b8a414edf5
commit 4a54c7687d
10 changed files with 328 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);
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();

View File

@ -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;
}
}

View File

@ -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<? extends Annotation> annotation() {

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}
}