Calculate SLA and APDEX metric.

This commit is contained in:
peng-yongsheng 2018-02-27 16:22:22 +08:00
parent 1cca13df32
commit fc86ef66ff
5 changed files with 100 additions and 2 deletions

View File

@ -40,6 +40,9 @@ public interface IApplicationMetricUIDAO extends DAO {
private long errorCalls;
private long durations;
private long errorDurations;
private long satisfiedCount;
private long toleratingCount;
private long frustratedCount;
public void setId(int id) {
this.id = id;
@ -80,5 +83,29 @@ public interface IApplicationMetricUIDAO extends DAO {
public long getErrorDurations() {
return errorDurations;
}
public long getSatisfiedCount() {
return satisfiedCount;
}
public void setSatisfiedCount(long satisfiedCount) {
this.satisfiedCount = satisfiedCount;
}
public long getToleratingCount() {
return toleratingCount;
}
public void setToleratingCount(long toleratingCount) {
this.toleratingCount = toleratingCount;
}
public long getFrustratedCount() {
return frustratedCount;
}
public void setFrustratedCount(long frustratedCount) {
this.frustratedCount = frustratedCount;
}
}
}

View File

@ -124,6 +124,9 @@ public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetri
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_SATISFIED_COUNT).field(ApplicationMetricTable.COLUMN_SATISFIED_COUNT));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TOLERATING_COUNT).field(ApplicationMetricTable.COLUMN_TOLERATING_COUNT));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_FRUSTRATED_COUNT).field(ApplicationMetricTable.COLUMN_FRUSTRATED_COUNT));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
@ -137,6 +140,9 @@ public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetri
Sum errorCalls = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
Sum durations = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
Sum errorDurations = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
Sum satisfiedCount = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_SATISFIED_COUNT);
Sum toleratingCount = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TOLERATING_COUNT);
Sum frustratedCount = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_FRUSTRATED_COUNT);
ApplicationMetric applicationMetric = new ApplicationMetric();
applicationMetric.setId(applicationId);
@ -144,6 +150,9 @@ public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetri
applicationMetric.setErrorCalls((long)errorCalls.getValue());
applicationMetric.setDurations((long)durations.getValue());
applicationMetric.setErrorDurations((long)errorDurations.getValue());
applicationMetric.setSatisfiedCount((long)satisfiedCount.getValue());
applicationMetric.setToleratingCount((long)toleratingCount.getValue());
applicationMetric.setToleratingCount((long)frustratedCount.getValue());
applicationMetrics.add(applicationMetric);
});
return applicationMetrics;

View File

@ -38,6 +38,8 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Call;
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode;
import org.apache.skywalking.apm.collector.ui.utils.ApdexCalculator;
import org.apache.skywalking.apm.collector.ui.utils.SLACalculator;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
/**
@ -70,10 +72,10 @@ class TopologyBuilder {
applicationNode.setName(application.getApplicationCode());
applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
applicationNode.setSla(10);
applicationNode.setSla(SLACalculator.INSTANCE.calculate(applicationMetric.getErrorCalls(), applicationMetric.getCalls()));
applicationNode.setCallsPerSec(100L);
applicationNode.setAvgResponseTime((applicationMetric.getDurations() - applicationMetric.getErrorDurations()) / (applicationMetric.getCalls() - applicationMetric.getErrorCalls()));
applicationNode.setApdex(10);
applicationNode.setApdex(ApdexCalculator.INSTANCE.calculate(applicationMetric.getSatisfiedCount(), applicationMetric.getToleratingCount(), applicationMetric.getFrustratedCount()));
applicationNode.setAlarm(false);
applicationNode.setNumOfServer(1);
applicationNode.setNumOfServerAlarm(1);

View File

@ -0,0 +1,30 @@
/*
* 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.apm.collector.ui.utils;
/**
* @author peng-yongsheng
*/
public enum ApdexCalculator {
INSTANCE;
public int calculate(long satisfiedCount, long toleratingCount, long frustratedCount) {
return (int)(((satisfiedCount + toleratingCount / 2) * 100) / (satisfiedCount + toleratingCount + frustratedCount));
}
}

View File

@ -0,0 +1,30 @@
/*
* 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.apm.collector.ui.utils;
/**
* @author peng-yongsheng
*/
public enum SLACalculator {
INSTANCE;
public int calculate(long errorCalls, long calls) {
return (int)(((calls - errorCalls) * 100) / calls);
}
}