提交 d28cc64f 编写于 作者: G Gao Hongtao 提交者: 彭勇升 pengys

Refactor tps to cpm (#1105)

* Refactor tps to cpm

* Change the implementation for new graphql protocol.

* Add aggregate column named duration in GC metric table.

* getGCTrend query finished.

* Change between seconds to between minutes.
上级 368a5f4b
......@@ -56,7 +56,7 @@ public class AgentDataMock {
Long[] times = TimeBuilder.INSTANCE.generateTimes();
logger.info("times size: {}", times.length);
// segmentMock.mock(upstreamSegments, times, false);
segmentMock.mock(upstreamSegments, times, false);
JVMMetricMock jvmMetricMock = new JVMMetricMock();
jvmMetricMock.mock(channel, times);
......
......@@ -143,11 +143,13 @@ class JVMMetricMock {
GC.Builder newGC = GC.newBuilder();
newGC.setPhrase(GCPhrase.NEW);
newGC.setCount(2);
newGC.setTime(1000);
metricBuilder.addGc(newGC);
GC.Builder oldGC = GC.newBuilder();
oldGC.setPhrase(GCPhrase.OLD);
oldGC.setCount(4);
oldGC.setTime(49);
metricBuilder.addGc(oldGC);
}
......
......@@ -24,5 +24,5 @@ import org.apache.skywalking.apm.collector.core.module.Service;
* @author peng-yongsheng
*/
public interface IGCMetricService extends Service {
void send(int instanceId, long timeBucket, int phraseValue, long count, long time);
void send(int instanceId, long timeBucket, int phraseValue, long count, long duration);
}
......@@ -45,7 +45,7 @@ public class GCMetricService implements IGCMetricService {
return gcMetricGraph;
}
@Override public void send(int instanceId, long timeBucket, int phraseValue, long count, long time) {
@Override public void send(int instanceId, long timeBucket, int phraseValue, long count, long duration) {
String metricId = instanceId + Const.ID_SPLIT + String.valueOf(phraseValue);
String id = timeBucket + Const.ID_SPLIT + metricId;
......@@ -55,6 +55,7 @@ public class GCMetricService implements IGCMetricService {
gcMetric.setInstanceId(instanceId);
gcMetric.setPhrase(phraseValue);
gcMetric.setCount(count);
gcMetric.setDuration(duration);
gcMetric.setTimes(1L);
gcMetric.setTimeBucket(timeBucket);
......
......@@ -32,7 +32,7 @@ import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric;
*/
public class CpuDayMetricPersistenceWorker extends PersistenceWorker<CpuMetric> {
public CpuDayMetricPersistenceWorker(ModuleManager moduleManager) {
private CpuDayMetricPersistenceWorker(ModuleManager moduleManager) {
super(moduleManager);
}
......
......@@ -32,7 +32,7 @@ import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric;
*/
public class CpuHourMetricPersistenceWorker extends PersistenceWorker<CpuMetric> {
public CpuHourMetricPersistenceWorker(ModuleManager moduleManager) {
private CpuHourMetricPersistenceWorker(ModuleManager moduleManager) {
super(moduleManager);
}
......
......@@ -32,7 +32,7 @@ import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric;
*/
public class CpuMinuteMetricPersistenceWorker extends PersistenceWorker<CpuMetric> {
public CpuMinuteMetricPersistenceWorker(ModuleManager moduleManager) {
private CpuMinuteMetricPersistenceWorker(ModuleManager moduleManager) {
super(moduleManager);
}
......
......@@ -32,7 +32,7 @@ import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric;
*/
public class CpuMonthMetricPersistenceWorker extends PersistenceWorker<CpuMetric> {
public CpuMonthMetricPersistenceWorker(ModuleManager moduleManager) {
private CpuMonthMetricPersistenceWorker(ModuleManager moduleManager) {
super(moduleManager);
}
......
......@@ -19,8 +19,7 @@
package org.apache.skywalking.apm.collector.analysis.jvm.provider.worker.gc;
import org.apache.skywalking.apm.collector.analysis.jvm.define.graph.WorkerIdDefine;
import org.apache.skywalking.apm.collector.analysis.worker.model.impl.PersistenceWorker;
import org.apache.skywalking.apm.collector.analysis.worker.model.impl.PersistenceWorkerProvider;
import org.apache.skywalking.apm.collector.analysis.worker.model.impl.*;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
......@@ -32,7 +31,7 @@ import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
*/
public class GCDayMetricPersistenceWorker extends PersistenceWorker<GCMetric> {
public GCDayMetricPersistenceWorker(ModuleManager moduleManager) {
private GCDayMetricPersistenceWorker(ModuleManager moduleManager) {
super(moduleManager);
}
......
......@@ -32,7 +32,7 @@ import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
*/
public class GCHourMetricPersistenceWorker extends PersistenceWorker<GCMetric> {
public GCHourMetricPersistenceWorker(ModuleManager moduleManager) {
private GCHourMetricPersistenceWorker(ModuleManager moduleManager) {
super(moduleManager);
}
......
......@@ -34,6 +34,7 @@ public class GCMetricCopy {
newGCMetric.setPhrase(gcMetric.getPhrase());
newGCMetric.setCount(gcMetric.getCount());
newGCMetric.setDuration(gcMetric.getDuration());
newGCMetric.setTimes(gcMetric.getTimes());
newGCMetric.setTimeBucket(gcMetric.getTimeBucket());
......
......@@ -32,7 +32,7 @@ import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
*/
public class GCMinuteMetricPersistenceWorker extends PersistenceWorker<GCMetric> {
public GCMinuteMetricPersistenceWorker(ModuleManager moduleManager) {
private GCMinuteMetricPersistenceWorker(ModuleManager moduleManager) {
super(moduleManager);
}
......
......@@ -32,7 +32,7 @@ import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
*/
public class GCMonthMetricPersistenceWorker extends PersistenceWorker<GCMetric> {
public GCMonthMetricPersistenceWorker(ModuleManager moduleManager) {
private GCMonthMetricPersistenceWorker(ModuleManager moduleManager) {
super(moduleManager);
}
......
......@@ -22,7 +22,7 @@ import java.util.List;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationThroughput;
/**
* Interface to be implemented for execute database query operation
......@@ -38,7 +38,7 @@ public interface IApplicationMetricUIDAO extends DAO {
* Returns the top n application throughput between start time bucket
* and end time bucket.
*
* <p>SQL as: select APPLICATION_ID, sum(TRANSACTION_CALLS) / betweenSecond as tps
* <p>SQL as: select APPLICATION_ID, sum(TRANSACTION_CALLS) / minutesBetween as tps
* from APPLICATION_METRIC
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource}
......@@ -52,13 +52,13 @@ public interface IApplicationMetricUIDAO extends DAO {
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param betweenSecond the seconds between start time bucket and end time bucket
* @param minutesBetween the minutes between start time bucket and end time bucket
* @param topN how many rows should return
* @param metricSource source of this metric, server side or client side
* @return not nullable result list
*/
List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int betweenSecond, int topN, MetricSource metricSource);
List<ApplicationThroughput> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int minutesBetween, int topN, MetricSource metricSource);
/**
* Returns aggregated application metrics that collected between start time bucket
......
......@@ -37,10 +37,11 @@ public interface IGCMetricUIDAO extends DAO {
/**
* Young GC Trend describes the trend of young generation garbage collection in the given
* duration, which represents by the DurationPoint list in the `step` Unit.
* <p>SQL as: select COUNT, TIMES from GC_METRIC where ID in (durationPoints), rule of
* <p>SQL as: select COUNT, TIMES, DURATION from GC_METRIC where ID in (durationPoints), rule of
* ID generation is "${durationPoint}_${instanceId}_${gcPhrase}",
* {@link org.apache.skywalking.apm.network.proto.GCPhrase#NEW_VALUE}
* <p>The average young generation GC count percent formula is "COUNT / TIMES".
* <p>The average young generation GC average count formula is "COUNT / TIMES".
* <p>The average young generation GC average duration formula is "DURATION / TIMES".
* <p>Every element in return list must match DurationPoint list, which also means that,
* the two list must be in same size, and index match.
* <p>If some element of the return list can't be found, the implementor must set 0 as
......@@ -51,19 +52,20 @@ public interface IGCMetricUIDAO extends DAO {
* @param instanceId the owner id of this GC metrics
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average young generation GC count percent metrics.
* @return every duration points average young generation GC count and duration metrics.
* @see org.apache.skywalking.apm.collector.storage.ui.common.Step
* @see org.apache.skywalking.apm.network.proto.GCPhrase
*/
List<Integer> getYoungGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
List<Trend> getYoungGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
/**
* Old GC Trend describes the trend of old generation garbage collection in the given
* duration, which represents by the DurationPoint list in the `step` Unit.
* <p>SQL as: select COUNT, TIMES from GC_METRIC where ID in (durationPoints), rule of
* <p>SQL as: select COUNT, TIMES, DURATION from GC_METRIC where ID in (durationPoints), rule of
* ID generation is "${durationPoint}_${instanceId}_${gcPhrase}",
* {@link org.apache.skywalking.apm.network.proto.GCPhrase#OLD_VALUE}
* <p>The average old generation GC count percent formula is "COUNT / TIMES".
* <p>The average young generation GC average count formula is "COUNT / TIMES".
* <p>The average young generation GC average duration formula is "DURATION / TIMES".
* <p>Every element in return list must match DurationPoint list, which also means that,
* the two list must be in same size, and index match.
* <p>If some element of the return list can't be found, the implementor must set 0 as
......@@ -74,9 +76,27 @@ public interface IGCMetricUIDAO extends DAO {
* @param instanceId the owner id of this GC metrics
* @param step the step which represent time formats
* @param durationPoints the time points in the time span
* @return every duration points average old generation GC count percent metrics.
* @return every duration points average old generation GC count and duration metrics.
* @see org.apache.skywalking.apm.collector.storage.ui.common.Step
* @see org.apache.skywalking.apm.network.proto.GCPhrase
*/
List<Integer> getOldGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
List<Trend> getOldGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
class Trend {
private int averageCount;
private int averageDuration;
public Trend(int averageCount, int averageDuration) {
this.averageCount = averageCount;
this.averageDuration = averageDuration;
}
public int getAverageCount() {
return averageCount;
}
public int getAverageDuration() {
return averageDuration;
}
}
}
......@@ -39,7 +39,7 @@ public interface IInstanceMetricUIDAO extends DAO {
* Returns the top n instance throughput between start time bucket
* and end time bucket.
*
* <p>SQL as: select APPLICATION_ID, sum(TRANSACTION_CALLS) / ${secondBetween} as tps
* <p>SQL as: select APPLICATION_ID, sum(TRANSACTION_CALLS) / ${minutesBetween} as tps
* from INSTANCE_METRIC
* where TIME_BUCKET ge ${startTimeBucket} and TIME_BUCKET le ${endTimeBucket}
* and SOURCE_VALUE = ${metricSource}
......@@ -55,13 +55,13 @@ public interface IInstanceMetricUIDAO extends DAO {
* @param step the step which represent time formats
* @param startTimeBucket start time bucket
* @param endTimeBucket end time bucket
* @param secondBetween the seconds between start time bucket and end time bucket
* @param minutesBetween the minutes between start time bucket and end time bucket
* @param topN how many rows should return
* @param metricSource source of this metric, server side or client side
* @return not nullable result list
*/
List<AppServerInfo> getServerThroughput(int applicationId, Step step, long startTimeBucket, long endTimeBucket,
int secondBetween, int topN, MetricSource metricSource);
int minutesBetween, int topN, MetricSource metricSource);
/**
* Server TPS Trend describes the trend of instance throughout in the given duration,
......@@ -70,7 +70,7 @@ public interface IInstanceMetricUIDAO extends DAO {
* <p>SQL as: select TRANSACTION_CALLS from INSTANCE_METRIC where ID in (durationPoints),
* rule of ID generation is "${durationPoint}_${instanceId}_${MetricSource.Callee}".
*
* <p>The formula is "TRANSACTION_CALLS * durationPoint#secondsBetween"
* <p>The formula is "TRANSACTION_CALLS * durationPoint#minutesBetween"
*
* <p>Use {@link org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder#build(Step, String)}
* to generate table name which mixed with step name.
......@@ -80,7 +80,7 @@ public interface IInstanceMetricUIDAO extends DAO {
* @param durationPoints the time points in the time span
* @return every duration points average instance throughput metrics.
*/
List<Integer> getServerTPSTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
List<Integer> getServerThroughputTrend(int instanceId, Step step, List<DurationPoint> durationPoints);
/**
* Response time Trend describes the trend of instance average response time in the given duration,
......
......@@ -18,12 +18,10 @@
package org.apache.skywalking.apm.collector.storage.dao.ui;
import java.util.Collection;
import java.util.List;
import java.util.*;
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
......@@ -56,10 +54,10 @@ public interface IServiceMetricUIDAO extends DAO {
List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, List<DurationPoint> durationPoints);
/**
* Service TPS Trend describes the trend of Service metric in the given duration
* Service throughout Trend describes the trend of Service metric in the given duration
* , which represents by the DurationPoint list in the `step` Unit.
*
* <p>SQL as: select TRANSACTION_CALLS / ${durationPoint#secondsBetween} from SERVICE_METRIC
* <p>SQL as: select TRANSACTION_CALLS / ${durationPoint#minutesBetween} from SERVICE_METRIC
* where ID in (${durationPoints})
*
* <p>rule of ID generation is "${durationPoint}_${serviceId}_${MetricSource.Callee}"
......@@ -71,7 +69,7 @@ public interface IServiceMetricUIDAO extends DAO {
* @param durationPoints the time points in the time span
* @return every duration points average throughout metrics.
*/
List<Integer> getServiceTPSTrend(int serviceId, Step step, List<DurationPoint> durationPoints);
List<Integer> getServiceThroughputTrend(int serviceId, Step step, List<DurationPoint> durationPoints);
/**
* Service SLA Trend describes the trend of Service SLA metrics in the given duration
......
......@@ -18,11 +18,8 @@
package org.apache.skywalking.apm.collector.storage.table.jvm;
import org.apache.skywalking.apm.collector.core.data.Column;
import org.apache.skywalking.apm.collector.core.data.StreamData;
import org.apache.skywalking.apm.collector.core.data.operator.AddMergeOperation;
import org.apache.skywalking.apm.collector.core.data.operator.CoverMergeOperation;
import org.apache.skywalking.apm.collector.core.data.operator.NonMergeOperation;
import org.apache.skywalking.apm.collector.core.data.*;
import org.apache.skywalking.apm.collector.core.data.operator.*;
/**
* @author peng-yongsheng
......@@ -38,6 +35,7 @@ public class GCMetric extends StreamData {
new Column(GCMetricTable.COUNT, new AddMergeOperation()),
new Column(GCMetricTable.TIMES, new AddMergeOperation()),
new Column(GCMetricTable.TIME_BUCKET, new CoverMergeOperation()),
new Column(GCMetricTable.DURATION, new AddMergeOperation()),
};
private static final Column[] DOUBLE_COLUMNS = {
......@@ -94,6 +92,14 @@ public class GCMetric extends StreamData {
setDataLong(2, timeBucket);
}
public Long getDuration() {
return getDataLong(3);
}
public void setDuration(Long duration) {
setDataLong(3, duration);
}
public Integer getInstanceId() {
return getDataInteger(0);
}
......
......@@ -30,4 +30,6 @@ public interface GCMetricTable extends InstanceTable {
ColumnName PHRASE = new ColumnName("phrase", "p");
ColumnName COUNT = new ColumnName("count", "c");
ColumnName DURATION = new ColumnName("duration", "d");
}
......@@ -26,7 +26,7 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Node;
public class ApplicationNode extends Node {
private int sla;
private long callsPerSec;
private long cpm;
private long avgResponseTime;
private int apdex;
private boolean isAlarm;
......@@ -42,12 +42,12 @@ public class ApplicationNode extends Node {
this.sla = sla;
}
public long getCallsPerSec() {
return callsPerSec;
public long getCpm() {
return cpm;
}
public void setCallsPerSec(long callsPerSec) {
this.callsPerSec = callsPerSec;
public void setCpm(long cpm) {
this.cpm = cpm;
}
public long getAvgResponseTime() {
......
......@@ -28,7 +28,7 @@ public class Call {
private String targetName;
private boolean isAlert;
private String callType;
private long callsPerSec;
private long cpm;
private long avgResponseTime;
public int getSource() {
......@@ -79,12 +79,12 @@ public class Call {
this.callType = callType;
}
public long getCallsPerSec() {
return callsPerSec;
public long getCpm() {
return cpm;
}
public void setCallsPerSec(long callsPerSec) {
this.callsPerSec = callsPerSec;
public void setCpm(long cpm) {
this.cpm = cpm;
}
public long getAvgResponseTime() {
......
......@@ -21,10 +21,10 @@ package org.apache.skywalking.apm.collector.storage.ui.overview;
/**
* @author peng-yongsheng
*/
public class ApplicationTPS {
public class ApplicationThroughput {
private int applicationId;
private String applicationCode;
private int callsPerSec;
private int cpm;
public int getApplicationId() {
return applicationId;
......@@ -42,11 +42,11 @@ public class ApplicationTPS {
this.applicationCode = applicationCode;
}
public int getCallsPerSec() {
return callsPerSec;
public int getCpm() {
return cpm;
}
public void setCallsPerSec(int callsPerSec) {
this.callsPerSec = callsPerSec;
public void setCpm(int cpm) {
this.cpm = cpm;
}
}
......@@ -30,7 +30,7 @@ public class AppServerInfo {
private String applicationCode;
private String osInfo;
private String osName;
private int callsPerSec;
private int cpm;
private String host;
private int pid;
private List<String> ipv4;
......@@ -75,12 +75,12 @@ public class AppServerInfo {
this.osName = osName;
}
public int getCallsPerSec() {
return callsPerSec;
public int getCpm() {
return cpm;
}
public void setCallsPerSec(int callsPerSec) {
this.callsPerSec = callsPerSec;
public void setCpm(int cpm) {
this.cpm = cpm;
}
public String getHost() {
......
......@@ -18,28 +18,53 @@
package org.apache.skywalking.apm.collector.storage.ui.server;
import java.util.List;
import java.util.*;
/**
* @author peng-yongsheng
*/
public class GCTrend {
private List<Integer> youngGC;
private List<Integer> oldGC;
private List<Integer> youngGCCount;
private List<Integer> oldGCount;
private List<Integer> youngGCTime;
private List<Integer> oldGCTime;
public List<Integer> getYoungGC() {
return youngGC;
public GCTrend() {
this.youngGCCount = new LinkedList<>();
this.oldGCount = new LinkedList<>();
this.youngGCTime = new LinkedList<>();
this.oldGCTime = new LinkedList<>();
}
public void setYoungGC(List<Integer> youngGC) {
this.youngGC = youngGC;
public List<Integer> getYoungGCCount() {
return youngGCCount;
}
public List<Integer> getOldGC() {
return oldGC;
public void setYoungGCCount(List<Integer> youngGCCount) {
this.youngGCCount = youngGCCount;
}
public void setOldGC(List<Integer> oldGC) {
this.oldGC = oldGC;
public List<Integer> getOldGCount() {
return oldGCount;
}
public void setOldGCount(List<Integer> oldGCount) {
this.oldGCount = oldGCount;
}
public List<Integer> getYoungGCTime() {
return youngGCTime;
}
public void setYoungGCTime(List<Integer> youngGCTime) {
this.youngGCTime = youngGCTime;
}
public List<Integer> getOldGCTime() {
return oldGCTime;
}
public void setOldGCTime(List<Integer> oldGCTime) {
this.oldGCTime = oldGCTime;
}
}
......@@ -26,7 +26,7 @@ public class ServiceMetric {
private String name;
private long calls;
private int avgResponseTime;
private int callsPerSec;
private int cpm;
public int getId() {
return id;
......@@ -52,12 +52,12 @@ public class ServiceMetric {
this.avgResponseTime = avgResponseTime;
}
public int getCallsPerSec() {
return callsPerSec;
public int getCpm() {
return cpm;
}
public void setCallsPerSec(int callsPerSec) {
this.callsPerSec = callsPerSec;
public void setCpm(int cpm) {
this.cpm = cpm;
}
public long getCalls() {
......
......@@ -24,10 +24,12 @@ package org.apache.skywalking.apm.collector.storage.utils;
public class DurationPoint {
private long point;
private long secondsBetween;
private long minutesBetween;
public DurationPoint(long point, long secondsBetween) {
public DurationPoint(long point, long secondsBetween, long minutesBetween) {
this.point = point;
this.secondsBetween = secondsBetween;
this.minutesBetween = minutesBetween;
}
public long getPoint() {
......@@ -37,4 +39,8 @@ public class DurationPoint {
public long getSecondsBetween() {
return secondsBetween;
}
public long getMinutesBetween() {
return minutesBetween;
}
}
......@@ -18,13 +18,11 @@
package org.apache.skywalking.apm.collector.storage.es.dao.gc;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.es.base.dao.AbstractPersistenceEsDAO;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
import org.apache.skywalking.apm.collector.storage.table.jvm.*;
/**
* @author peng-yongsheng
......@@ -48,6 +46,7 @@ public abstract class AbstractGCMetricEsPersistenceDAO extends AbstractPersisten
gcMetric.setCount(((Number)source.get(GCMetricTable.COUNT.getName())).longValue());
gcMetric.setTimes(((Number)source.get(GCMetricTable.TIMES.getName())).longValue());
gcMetric.setDuration(((Number)source.get(GCMetricTable.DURATION.getName())).longValue());
gcMetric.setTimeBucket(((Number)source.get(GCMetricTable.TIME_BUCKET.getName())).longValue());
......@@ -63,6 +62,7 @@ public abstract class AbstractGCMetricEsPersistenceDAO extends AbstractPersisten
target.put(GCMetricTable.COUNT.getName(), streamData.getCount());
target.put(GCMetricTable.TIMES.getName(), streamData.getTimes());
target.put(GCMetricTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
target.put(GCMetricTable.DURATION.getName(), streamData.getDuration());
return target;
}
......
......@@ -18,24 +18,19 @@
package org.apache.skywalking.apm.collector.storage.es.dao.ui;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationThroughput;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.action.search.*;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.terms.*;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
/**
......@@ -48,8 +43,8 @@ public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetri
}
@Override
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int betweenSecond, int topN, MetricSource metricSource) {
public List<ApplicationThroughput> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int minutesBetween, int topN, MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
......@@ -69,28 +64,28 @@ public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetri
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<ApplicationTPS> applicationTPSs = new LinkedList<>();
List<ApplicationThroughput> applicationThroughputList = new LinkedList<>();
Terms applicationIdTerms = searchResponse.getAggregations().get(ApplicationMetricTable.APPLICATION_ID.getName());
applicationIdTerms.getBuckets().forEach(applicationIdTerm -> {
int applicationId = applicationIdTerm.getKeyAsNumber().intValue();
Sum callSum = applicationIdTerm.getAggregations().get(ApplicationMetricTable.TRANSACTION_CALLS.getName());
long calls = (long)callSum.getValue();
int callsPerSec = (int)(betweenSecond == 0 ? 0 : calls / betweenSecond);
int callsPerMinute = (int)(minutesBetween == 0 ? 0 : calls / minutesBetween);
ApplicationTPS applicationTPS = new ApplicationTPS();
applicationTPS.setApplicationId(applicationId);
applicationTPS.setCallsPerSec(callsPerSec);
applicationTPSs.add(applicationTPS);
ApplicationThroughput applicationThroughput = new ApplicationThroughput();
applicationThroughput.setApplicationId(applicationId);
applicationThroughput.setCpm(callsPerMinute);
applicationThroughputList.add(applicationThroughput);
});
applicationTPSs.sort((first, second) -> first.getCallsPerSec() > second.getCallsPerSec() ? -1 : 1);
applicationThroughputList.sort((first, second) -> first.getCpm() > second.getCpm() ? -1 : 1);
if (applicationTPSs.size() <= topN) {
return applicationTPSs;
if (applicationThroughputList.size() <= topN) {
return applicationThroughputList;
} else {
List<ApplicationTPS> newCollection = new LinkedList<>();
List<ApplicationThroughput> newCollection = new LinkedList<>();
for (int i = 0; i < topN; i++) {
newCollection.add(applicationTPSs.get(i));
newCollection.add(applicationThroughputList.get(i));
}
return newCollection;
}
......
......@@ -18,21 +18,16 @@
package org.apache.skywalking.apm.collector.storage.es.dao.ui;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.apache.skywalking.apm.collector.storage.utils.*;
import org.apache.skywalking.apm.network.proto.GCPhrase;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetRequestBuilder;
import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.get.*;
/**
* @author peng-yongsheng
......@@ -44,16 +39,16 @@ public class GCMetricEsUIDAO extends EsDAO implements IGCMetricUIDAO {
}
@Override
public List<Integer> getYoungGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
public List<Trend> getYoungGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
return getGCTrend(instanceId, step, durationPoints, GCPhrase.NEW_VALUE);
}
@Override
public List<Integer> getOldGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
public List<Trend> getOldGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
return getGCTrend(instanceId, step, durationPoints, GCPhrase.OLD_VALUE);
}
private List<Integer> getGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints, int gcPhrase) {
private List<Trend> getGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints, int gcPhrase) {
String tableName = TimePyramidTableNameBuilder.build(step, GCMetricTable.TABLE);
MultiGetRequestBuilder youngPrepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {
......@@ -64,15 +59,16 @@ public class GCMetricEsUIDAO extends EsDAO implements IGCMetricUIDAO {
}
});
List<Integer> gcTrends = new LinkedList<>();
List<Trend> gcTrends = new LinkedList<>();
MultiGetResponse multiGetResponse = youngPrepareMultiGet.get();
for (MultiGetItemResponse itemResponse : multiGetResponse.getResponses()) {
if (itemResponse.getResponse().isExists()) {
long count = ((Number) itemResponse.getResponse().getSource().get(GCMetricTable.COUNT.getName())).longValue();
long times = ((Number) itemResponse.getResponse().getSource().get(GCMetricTable.TIMES.getName())).intValue();
gcTrends.add((int) (count / times));
long count = ((Number)itemResponse.getResponse().getSource().get(GCMetricTable.COUNT.getName())).longValue();
long duration = ((Number)itemResponse.getResponse().getSource().get(GCMetricTable.DURATION.getName())).longValue();
long times = ((Number)itemResponse.getResponse().getSource().get(GCMetricTable.TIMES.getName())).intValue();
gcTrends.add(new Trend((int)(count / times), (int)(duration / times)));
} else {
gcTrends.add(0);
gcTrends.add(new Trend(0, 0));
}
}
......
......@@ -18,8 +18,7 @@
package org.apache.skywalking.apm.collector.storage.es.dao.ui;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO;
......@@ -29,19 +28,12 @@ import org.apache.skywalking.apm.collector.storage.table.application.Application
import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetRequestBuilder;
import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.apache.skywalking.apm.collector.storage.utils.*;
import org.elasticsearch.action.get.*;
import org.elasticsearch.action.search.*;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.terms.*;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
/**
......@@ -55,7 +47,7 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
@Override
public List<AppServerInfo> getServerThroughput(int applicationId, Step step, long startTimeBucket,
long endTimeBucket, int secondBetween, int topN, MetricSource metricSource) {
long endTimeBucket, int minutesBetween, int topN, MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
......@@ -78,34 +70,34 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<AppServerInfo> appServerInfos = new LinkedList<>();
List<AppServerInfo> appServerInfoList = new LinkedList<>();
Terms instanceIdTerms = searchResponse.getAggregations().get(InstanceMetricTable.INSTANCE_ID.getName());
instanceIdTerms.getBuckets().forEach(instanceIdTerm -> {
int instanceId = instanceIdTerm.getKeyAsNumber().intValue();
Sum callSum = instanceIdTerm.getAggregations().get(ApplicationMetricTable.TRANSACTION_CALLS.getName());
long calls = (long)callSum.getValue();
int callsPerSec = (int)(secondBetween == 0 ? 0 : calls / secondBetween);
int callsPerMinute = (int)(minutesBetween == 0 ? 0 : calls / minutesBetween);
AppServerInfo appServerInfo = new AppServerInfo();
appServerInfo.setId(instanceId);
appServerInfo.setCallsPerSec(callsPerSec);
appServerInfos.add(appServerInfo);
appServerInfo.setCpm(callsPerMinute);
appServerInfoList.add(appServerInfo);
});
appServerInfos.sort((first, second) -> first.getCallsPerSec() > second.getCallsPerSec() ? -1 : 1);
if (appServerInfos.size() <= topN) {
return appServerInfos;
appServerInfoList.sort((first, second) -> first.getCpm() > second.getCpm() ? -1 : 1);
if (appServerInfoList.size() <= topN) {
return appServerInfoList;
} else {
List<AppServerInfo> newCollection = new LinkedList<>();
for (int i = 0; i < topN; i++) {
newCollection.add(appServerInfos.get(i));
newCollection.add(appServerInfoList.get(i));
}
return newCollection;
}
}
@Override
public List<Integer> getServerTPSTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
public List<Integer> getServerThroughputTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {
@Override
......@@ -122,7 +114,7 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
MultiGetItemResponse response = multiGetResponse.getResponses()[i];
if (response.getResponse().isExists()) {
long callTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.TRANSACTION_CALLS.getName())).longValue();
throughputTrend.add((int)(callTimes / durationPoints.get(i).getSecondsBetween()));
throughputTrend.add((int)(callTimes / durationPoints.get(i).getMinutesBetween()));
} else {
throughputTrend.add(0);
}
......
......@@ -86,7 +86,7 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
}
@Override
public List<Integer> getServiceTPSTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
public List<Integer> getServiceThroughputTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {
@Override
......@@ -103,8 +103,8 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
long calls = ((Number)response.getResponse().getSource().get(ServiceMetricTable.TRANSACTION_CALLS.getName())).longValue();
long secondBetween = durationPoints.get(index).getSecondsBetween();
trends.add((int)(calls / secondBetween));
long minutesBetween = durationPoints.get(index).getMinutesBetween();
trends.add((int)(calls / minutesBetween));
} else {
trends.add(0);
}
......
......@@ -37,6 +37,7 @@ public abstract class AbstractGCMetricEsTableDefine extends ElasticSearchTableDe
addColumn(new ElasticSearchColumnDefine(GCMetricTable.INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.PHRASE, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.COUNT, ElasticSearchColumnDefine.Type.Long.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.DURATION, ElasticSearchColumnDefine.Type.Long.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.TIMES, ElasticSearchColumnDefine.Type.Long.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name()));
}
......
......@@ -179,10 +179,10 @@ import org.apache.skywalking.apm.collector.storage.h2.dao.cpu.CpuDayMetricH2Pers
import org.apache.skywalking.apm.collector.storage.h2.dao.cpu.CpuHourMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.cpu.CpuMinuteMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.cpu.CpuMonthMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.gcmp.GCDayMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.gcmp.GCHourMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.gcmp.GCMinuteMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.gcmp.GCMonthMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.gc.GCDayMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.gc.GCHourMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.gc.GCMinuteMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.gc.GCMonthMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.imp.InstanceDayMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.imp.InstanceHourMetricH2PersistenceDAO;
import org.apache.skywalking.apm.collector.storage.h2.dao.imp.InstanceMinuteMetricH2PersistenceDAO;
......
......@@ -16,16 +16,13 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.dao.gcmp;
package org.apache.skywalking.apm.collector.storage.h2.dao.gc;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.sql.*;
import java.util.*;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.AbstractPersistenceH2DAO;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
import org.apache.skywalking.apm.collector.storage.table.jvm.*;
/**
* @author peng-yongsheng
......@@ -46,6 +43,7 @@ public abstract class AbstractGCMetricH2PersistenceDAO extends AbstractPersisten
gcMetric.setCount(resultSet.getLong(GCMetricTable.COUNT.getName()));
gcMetric.setTimes(resultSet.getLong(GCMetricTable.TIMES.getName()));
gcMetric.setDuration(resultSet.getLong(GCMetricTable.DURATION.getName()));
gcMetric.setTimeBucket(resultSet.getLong(GCMetricTable.TIME_BUCKET.getName()));
......@@ -61,6 +59,7 @@ public abstract class AbstractGCMetricH2PersistenceDAO extends AbstractPersisten
target.put(GCMetricTable.PHRASE.getName(), streamData.getPhrase());
target.put(GCMetricTable.COUNT.getName(), streamData.getCount());
target.put(GCMetricTable.TIMES.getName(), streamData.getTimes());
target.put(GCMetricTable.DURATION.getName(), streamData.getDuration());
target.put(GCMetricTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
return target;
......
......@@ -16,7 +16,7 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.dao.gcmp;
package org.apache.skywalking.apm.collector.storage.h2.dao.gc;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
......
......@@ -16,7 +16,7 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.dao.gcmp;
package org.apache.skywalking.apm.collector.storage.h2.dao.gc;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
......
......@@ -16,7 +16,7 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.dao.gcmp;
package org.apache.skywalking.apm.collector.storage.h2.dao.gc;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
......
......@@ -16,7 +16,7 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.dao.gcmp;
package org.apache.skywalking.apm.collector.storage.h2.dao.gc;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
......
......@@ -24,7 +24,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDA
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationThroughput;
/**
* @author peng-yongsheng
......@@ -36,8 +36,8 @@ public class ApplicationMetricH2UIDAO extends H2DAO implements IApplicationMetri
}
@Override
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int betweenSecond, int topN, MetricSource metricSource) {
public List<ApplicationThroughput> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int minutesBetween, int topN, MetricSource metricSource) {
return null;
}
......
......@@ -18,23 +18,18 @@
package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import java.sql.*;
import java.util.*;
import org.apache.skywalking.apm.collector.client.h2.*;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.apache.skywalking.apm.collector.storage.utils.*;
import org.apache.skywalking.apm.network.proto.GCPhrase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.*;
/**
* @author peng-yongsheng, clevertension
......@@ -48,33 +43,35 @@ public class GCMetricH2UIDAO extends H2DAO implements IGCMetricUIDAO {
super(client);
}
@Override public List<Integer> getYoungGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
@Override public List<Trend> getYoungGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
return getGCTrend(instanceId, step, durationPoints, GCPhrase.NEW_VALUE);
}
@Override public List<Integer> getOldGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
@Override public List<Trend> getOldGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
return getGCTrend(instanceId, step, durationPoints, GCPhrase.OLD_VALUE);
}
private List<Integer> getGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints, int gcPhrase) {
private List<Trend> getGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints, int gcPhrase) {
String tableName = TimePyramidTableNameBuilder.build(step, GCMetricTable.TABLE);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_GC_METRIC_SQL, tableName, GCMetricTable.ID.getName());
List<Integer> gcTrends = new LinkedList<>();
List<Trend> gcTrends = new LinkedList<>();
durationPoints.forEach(durationPoint -> {
String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + gcPhrase;
try (ResultSet rs = client.executeQuery(sql, new String[] {id})) {
if (rs.next()) {
long count = rs.getLong(GCMetricTable.COUNT.getName());
long duration = rs.getLong(GCMetricTable.DURATION.getName());
long times = rs.getLong(GCMetricTable.TIMES.getName());
gcTrends.add((int)(count / times));
gcTrends.add(new Trend((int)(count / times), (int)(duration / times)));
} else {
gcTrends.add(0);
gcTrends.add(new Trend(0, 0));
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
gcTrends.add(new Trend(0, 0));
}
});
......
......@@ -18,12 +18,9 @@
package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import java.sql.*;
import java.util.*;
import org.apache.skywalking.apm.collector.client.h2.*;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO;
......@@ -32,10 +29,8 @@ import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.skywalking.apm.collector.storage.utils.*;
import org.slf4j.*;
/**
* @author peng-yongsheng, clevertension
......@@ -49,12 +44,14 @@ public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO
super(client);
}
@Override public List<AppServerInfo> getServerThroughput(int applicationId, Step step, long startTimeBucket, long endTimeBucket,
int secondBetween, int topN, MetricSource metricSource) {
@Override public List<AppServerInfo> getServerThroughput(int applicationId, Step step, long startTimeBucket,
long endTimeBucket,
int minutesBetween, int topN, MetricSource metricSource) {
return null;
}
@Override public List<Integer> getServerTPSTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
@Override
public List<Integer> getServerThroughputTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
H2Client client = getClient();
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
......@@ -66,7 +63,7 @@ public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO
try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) {
if (rs.next()) {
long callTimes = rs.getLong(InstanceMetricTable.TRANSACTION_CALLS.getName());
throughputTrend.add((int)(callTimes / durationPoint.getSecondsBetween()));
throughputTrend.add((int)(callTimes / durationPoint.getMinutesBetween()));
} else {
throughputTrend.add(0);
}
......@@ -91,7 +88,7 @@ public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO
if (rs.next()) {
long callTimes = rs.getLong(InstanceMetricTable.TRANSACTION_CALLS.getName());
long durationSum = rs.getLong(InstanceMetricTable.TRANSACTION_DURATION_SUM.getName());
responseTimeTrends.add((int) (durationSum / callTimes));
responseTimeTrends.add((int)(durationSum / callTimes));
} else {
responseTimeTrends.add(0);
}
......
......@@ -18,26 +18,19 @@
package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import java.sql.*;
import java.util.*;
import org.apache.skywalking.apm.collector.client.h2.*;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.skywalking.apm.collector.storage.utils.*;
import org.slf4j.*;
/**
* @author peng-yongsheng
......@@ -66,7 +59,7 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
if (rs.next()) {
long calls = rs.getLong(ServiceMetricTable.TRANSACTION_CALLS.getName());
long durationSum = rs.getLong(ServiceMetricTable.TRANSACTION_DURATION_SUM.getName());
trends.add((int) (durationSum / calls));
trends.add((int)(durationSum / calls));
} else {
trends.add(0);
}
......@@ -78,7 +71,8 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
return trends;
}
@Override public List<Integer> getServiceTPSTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
@Override
public List<Integer> getServiceThroughputTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
return null;
}
......@@ -109,12 +103,15 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
return trends;
}
@Override public List<Node> getServicesMetric(Step step, long startTimeBucket, long endTimeBucket, MetricSource metricSource,
@Override
public List<Node> getServicesMetric(Step step, long startTimeBucket, long endTimeBucket, MetricSource metricSource,
Collection<Integer> serviceIds) {
return null;
}
@Override public List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket, Integer topN,
@Override
public List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket,
Integer topN,
MetricSource metricSource) {
return null;
}
......
......@@ -18,8 +18,7 @@
package org.apache.skywalking.apm.collector.storage.h2.define.gc;
import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine;
import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine;
import org.apache.skywalking.apm.collector.storage.h2.base.define.*;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
/**
......@@ -37,6 +36,7 @@ public abstract class AbstractGCMetricH2TableDefine extends H2TableDefine {
addColumn(new H2ColumnDefine(GCMetricTable.INSTANCE_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(GCMetricTable.PHRASE, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(GCMetricTable.COUNT, H2ColumnDefine.Type.Bigint.name()));
addColumn(new H2ColumnDefine(GCMetricTable.DURATION, H2ColumnDefine.Type.Bigint.name()));
addColumn(new H2ColumnDefine(GCMetricTable.TIMES, H2ColumnDefine.Type.Bigint.name()));
addColumn(new H2ColumnDefine(GCMetricTable.TIME_BUCKET, H2ColumnDefine.Type.Bigint.name()));
}
......
......@@ -25,7 +25,7 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.apache.skywalking.apm.collector.storage.ui.common.ValueType;
import org.apache.skywalking.apm.collector.storage.ui.overview.AlarmTrend;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationThroughput;
import org.apache.skywalking.apm.collector.storage.ui.overview.ClusterBrief;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalAppBrief;
import org.apache.skywalking.apm.collector.storage.ui.overview.Thermodynamic;
......@@ -150,7 +150,7 @@ public class OverViewLayerQuery implements Query {
return getServiceNameService().getSlowService(duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket, topN);
}
public List<ApplicationTPS> getTopNApplicationThroughput(Duration duration,
public List<ApplicationThroughput> getTopNApplicationThroughput(Duration duration,
int topN) throws ParseException {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
......
......@@ -18,21 +18,15 @@
package org.apache.skywalking.apm.collector.ui.query;
import java.text.ParseException;
import java.util.List;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.apache.skywalking.apm.collector.storage.ui.server.CPUTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.GCTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.MemoryTrend;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.storage.ui.server.*;
import org.apache.skywalking.apm.collector.ui.graphql.Query;
import org.apache.skywalking.apm.collector.ui.service.ServerService;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import java.text.ParseException;
import java.util.List;
import static java.util.Objects.isNull;
/**
......@@ -54,13 +48,13 @@ public class ServerQuery implements Query {
return serverService;
}
public List<AppServerInfo> searchServer(String keyword, Duration duration) throws ParseException {
public List<AppServerInfo> searchServer(String keyword, Duration duration) {
long startSecondTimeBucket = DurationUtils.INSTANCE.startTimeDurationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endSecondTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getServerService().searchServer(keyword, startSecondTimeBucket, endSecondTimeBucket);
}
public List<AppServerInfo> getAllServer(int applicationId, Duration duration) throws ParseException {
public List<AppServerInfo> getAllServer(int applicationId, Duration duration) {
long startSecondTimeBucket = DurationUtils.INSTANCE.startTimeDurationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endSecondTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getServerService().getAllServer(applicationId, startSecondTimeBucket, endSecondTimeBucket);
......@@ -72,10 +66,10 @@ public class ServerQuery implements Query {
return getServerService().getServerResponseTimeTrend(serverId, duration.getStep(), startTimeBucket, endTimeBucket);
}
public ThroughputTrend getServerTPSTrend(int serverId, Duration duration) throws ParseException {
public ThroughputTrend getServerThroughputTrend(int serverId, Duration duration) throws ParseException {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
return getServerService().getServerTPSTrend(serverId, duration.getStep(), startTimeBucket, endTimeBucket);
return getServerService().getServerThroughputTrend(serverId, duration.getStep(), startTimeBucket, endTimeBucket);
}
public CPUTrend getCPUTrend(int serverId, Duration duration) throws ParseException {
......
......@@ -68,11 +68,11 @@ public class ServiceQuery implements Query {
return getServiceNameService().getServiceResponseTimeTrend(serviceId, duration.getStep(), startTimeBucket, endTimeBucket);
}
public ThroughputTrend getServiceTPSTrend(int serviceId, Duration duration) throws ParseException {
public ThroughputTrend getServiceThroughputTrend(int serviceId, Duration duration) throws ParseException {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
return getServiceNameService().getServiceTPSTrend(serviceId, duration.getStep(), startTimeBucket, endTimeBucket);
return getServiceNameService().getServiceThroughputTrend(serviceId, duration.getStep(), startTimeBucket, endTimeBucket);
}
public SLATrend getServiceSLATrend(int serviceId, Duration duration) throws ParseException {
......
......@@ -21,28 +21,21 @@ package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.util.List;
import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.apache.skywalking.apm.collector.cache.service.*;
import org.apache.skywalking.apm.collector.configuration.ConfigurationModule;
import org.apache.skywalking.apm.collector.configuration.service.IComponentLibraryCatalogService;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
import org.apache.skywalking.apm.collector.storage.ui.application.Application;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalApp;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalAppBrief;
import org.apache.skywalking.apm.collector.storage.ui.overview.*;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.*;
/**
* @author peng-yongsheng
......@@ -57,7 +50,7 @@ public class ApplicationService {
private final INetworkAddressUIDAO networkAddressUIDAO;
private final ApplicationCacheService applicationCacheService;
private final ServiceNameCacheService serviceNameCacheService;
private final SecondBetweenService secondBetweenService;
private final DateBetweenService dateBetweenService;
private final IComponentLibraryCatalogService componentLibraryCatalogService;
public ApplicationService(ModuleManager moduleManager) {
......@@ -68,7 +61,7 @@ public class ApplicationService {
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
this.componentLibraryCatalogService = moduleManager.find(ConfigurationModule.NAME).getService(IComponentLibraryCatalogService.class);
this.secondBetweenService = new SecondBetweenService(moduleManager);
this.dateBetweenService = new DateBetweenService(moduleManager);
}
public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket,
......@@ -90,13 +83,13 @@ public class ApplicationService {
}
public List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket,
long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) throws ParseException {
long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) {
List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(applicationId, step, startTimeBucket, endTimeBucket, topN, MetricSource.Callee);
slowServices.forEach(slowService -> {
ServiceName serviceName = serviceNameCacheService.get(slowService.getId());
try {
slowService.setCallsPerSec((int)(slowService.getCalls() / secondBetweenService.calculate(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
slowService.setCpm((int)(slowService.getCalls() / dateBetweenService.minutesBetween(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
......@@ -105,19 +98,19 @@ public class ApplicationService {
return slowServices;
}
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
public List<ApplicationThroughput> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int topN) throws ParseException {
int secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTimeBucket, endTimeBucket);
List<ApplicationTPS> applicationThroughput = applicationMetricUIDAO.getTopNApplicationThroughput(step, startTimeBucket, endTimeBucket, secondsBetween, topN, MetricSource.Callee);
applicationThroughput.forEach(applicationTPS -> {
String applicationCode = applicationCacheService.getApplicationById(applicationTPS.getApplicationId()).getApplicationCode();
applicationTPS.setApplicationCode(applicationCode);
int minutesBetween = DurationUtils.INSTANCE.minutesBetween(step, startTimeBucket, endTimeBucket);
List<ApplicationThroughput> applicationThroughputList = applicationMetricUIDAO.getTopNApplicationThroughput(step, startTimeBucket, endTimeBucket, minutesBetween, topN, MetricSource.Callee);
applicationThroughputList.forEach(applicationThroughput -> {
String applicationCode = applicationCacheService.getApplicationById(applicationThroughput.getApplicationId()).getApplicationCode();
applicationThroughput.setApplicationCode(applicationCode);
});
return applicationThroughput;
return applicationThroughputList;
}
public ConjecturalAppBrief getConjecturalApps(Step step, long startSecondTimeBucket,
long endSecondTimeBucket) throws ParseException {
long endSecondTimeBucket) {
List<ConjecturalApp> conjecturalApps = networkAddressUIDAO.getConjecturalApps();
conjecturalApps.forEach(conjecturalApp -> {
String serverType = componentLibraryCatalogService.getServerName(conjecturalApp.getId());
......
......@@ -18,23 +18,15 @@
package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import org.apache.skywalking.apm.collector.configuration.ConfigurationModule;
import org.apache.skywalking.apm.collector.configuration.service.IComponentLibraryCatalogService;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.slf4j.*;
/**
* @author peng-yongsheng
......@@ -60,7 +52,7 @@ public class ClusterTopologyService {
}
public Topology getClusterTopology(Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket,
long endSecondTimeBucket) throws ParseException {
long endSecondTimeBucket) {
logger.debug("startTimeBucket: {}, endTimeBucket: {}, startSecondTimeBucket: {}, endSecondTimeBucket: {}", startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTimeBucket, endTimeBucket);
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTimeBucket, endTimeBucket);
......
......@@ -18,27 +18,25 @@
package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.text.*;
import java.util.Date;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.joda.time.DateTime;
import org.joda.time.Seconds;
import org.joda.time.*;
/**
* @author peng-yongsheng
*/
class SecondBetweenService {
class DateBetweenService {
private final IInstanceUIDAO instanceUIDAO;
SecondBetweenService(ModuleManager moduleManager) {
DateBetweenService(ModuleManager moduleManager) {
this.instanceUIDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class);
}
int calculate(int applicationId, long startSecondTimeBucket,
int secondsBetween(int applicationId, long startSecondTimeBucket,
long endSecondTimeBucket) throws ParseException {
long registerTime = instanceUIDAO.getEarliestRegisterTime(applicationId);
if (startSecondTimeBucket < registerTime) {
......@@ -59,4 +57,26 @@ class SecondBetweenService {
}
return seconds;
}
int minutesBetween(int applicationId, long startSecondTimeBucket,
long endSecondTimeBucket) throws ParseException {
long registerTime = instanceUIDAO.getEarliestRegisterTime(applicationId);
if (startSecondTimeBucket < registerTime) {
startSecondTimeBucket = registerTime;
}
long heartBeatTime = instanceUIDAO.getLatestHeartBeatTime(applicationId);
if (endSecondTimeBucket > heartBeatTime) {
endSecondTimeBucket = heartBeatTime;
}
Date startDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(startSecondTimeBucket));
Date endDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(endSecondTimeBucket));
int minutes = Minutes.minutesBetween(new DateTime(startDate), new DateTime(endDate)).getMinutes();
if (minutes == 0) {
minutes = 1;
}
return minutes;
}
}
......@@ -18,33 +18,19 @@
package org.apache.skywalking.apm.collector.ui.service;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.*;
import java.text.ParseException;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService;
import org.apache.skywalking.apm.collector.cache.service.*;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
import org.apache.skywalking.apm.collector.core.util.*;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.register.Instance;
import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.apache.skywalking.apm.collector.storage.ui.server.CPUTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.GCTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.MemoryTrend;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.storage.ui.server.*;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
......@@ -61,7 +47,7 @@ public class ServerService {
private final IMemoryMetricUIDAO memoryMetricUIDAO;
private final ApplicationCacheService applicationCacheService;
private final InstanceCacheService instanceCacheService;
private final SecondBetweenService secondBetweenService;
private final DateBetweenService dateBetweenService;
public ServerService(ModuleManager moduleManager) {
this.instanceUIDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class);
......@@ -71,7 +57,7 @@ public class ServerService {
this.memoryMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IMemoryMetricUIDAO.class);
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
this.instanceCacheService = moduleManager.find(CacheModule.NAME).getService(InstanceCacheService.class);
this.secondBetweenService = new SecondBetweenService(moduleManager);
this.dateBetweenService = new DateBetweenService(moduleManager);
}
public List<AppServerInfo> searchServer(String keyword, long startSecondTimeBucket, long endSecondTimeBucket) {
......@@ -104,9 +90,9 @@ public class ServerService {
public List<AppServerInfo> getServerThroughput(int applicationId, Step step, long startTimeBucket,
long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) throws ParseException {
int secondBetween = secondBetweenService.calculate(applicationId, startSecondTimeBucket, endSecondTimeBucket);
int minutesBetween = dateBetweenService.minutesBetween(applicationId, startSecondTimeBucket, endSecondTimeBucket);
List<AppServerInfo> serverThroughput = instanceMetricUIDAO.getServerThroughput(applicationId, step, startTimeBucket, endTimeBucket, secondBetween, topN, MetricSource.Callee);
List<AppServerInfo> serverThroughput = instanceMetricUIDAO.getServerThroughput(applicationId, step, startTimeBucket, endTimeBucket, minutesBetween, topN, MetricSource.Callee);
serverThroughput.forEach(appServerInfo -> {
appServerInfo.setApplicationId(instanceCacheService.getApplicationId(appServerInfo.getId()));
String applicationCode = applicationCacheService.getApplicationById(appServerInfo.getApplicationId()).getApplicationCode();
......@@ -119,11 +105,11 @@ public class ServerService {
return serverThroughput;
}
public ThroughputTrend getServerTPSTrend(int instanceId, Step step, long startTimeBucket,
public ThroughputTrend getServerThroughputTrend(int instanceId, Step step, long startTimeBucket,
long endTimeBucket) throws ParseException {
ThroughputTrend throughputTrend = new ThroughputTrend();
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, startTimeBucket, endTimeBucket);
List<Integer> trends = instanceMetricUIDAO.getServerTPSTrend(instanceId, step, durationPoints);
List<Integer> trends = instanceMetricUIDAO.getServerThroughputTrend(instanceId, step, durationPoints);
throughputTrend.setTrendList(trends);
return throughputTrend;
}
......@@ -141,10 +127,18 @@ public class ServerService {
long endTimeBucket) throws ParseException {
GCTrend gcTrend = new GCTrend();
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, startTimeBucket, endTimeBucket);
List<Integer> youngGCTrend = gcMetricUIDAO.getYoungGCTrend(instanceId, step, durationPoints);
gcTrend.setYoungGC(youngGCTrend);
List<Integer> oldGCTrend = gcMetricUIDAO.getOldGCTrend(instanceId, step, durationPoints);
gcTrend.setOldGC(oldGCTrend);
List<IGCMetricUIDAO.Trend> youngGCTrend = gcMetricUIDAO.getYoungGCTrend(instanceId, step, durationPoints);
youngGCTrend.forEach(young -> {
gcTrend.getYoungGCCount().add(young.getAverageCount());
gcTrend.getYoungGCTime().add(young.getAverageDuration());
});
List<IGCMetricUIDAO.Trend> oldGCTrend = gcMetricUIDAO.getOldGCTrend(instanceId, step, durationPoints);
oldGCTrend.forEach(old -> {
gcTrend.getOldGCount().add(old.getAverageCount());
gcTrend.getOldGCTime().add(old.getAverageDuration());
});
return gcTrend;
}
......
......@@ -24,20 +24,14 @@ import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
import org.apache.skywalking.apm.collector.storage.ui.common.SLATrend;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.storage.ui.service.*;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.*;
/**
* @author peng-yongsheng
......@@ -49,13 +43,13 @@ public class ServiceNameService {
private final IServiceNameServiceUIDAO serviceNameServiceUIDAO;
private final IServiceMetricUIDAO serviceMetricUIDAO;
private final ServiceNameCacheService serviceNameCacheService;
private final SecondBetweenService secondBetweenService;
private final DateBetweenService dateBetweenService;
public ServiceNameService(ModuleManager moduleManager) {
this.serviceNameServiceUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceNameServiceUIDAO.class);
this.serviceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceMetricUIDAO.class);
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
this.secondBetweenService = new SecondBetweenService(moduleManager);
this.dateBetweenService = new DateBetweenService(moduleManager);
}
public int getCount() {
......@@ -66,11 +60,11 @@ public class ServiceNameService {
return serviceNameServiceUIDAO.searchService(keyword, topN);
}
public ThroughputTrend getServiceTPSTrend(int serviceId, Step step, long startTimeBucket,
public ThroughputTrend getServiceThroughputTrend(int serviceId, Step step, long startTimeBucket,
long endTimeBucket) throws ParseException {
ThroughputTrend throughputTrend = new ThroughputTrend();
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, startTimeBucket, endTimeBucket);
List<Integer> throughputTrends = serviceMetricUIDAO.getServiceTPSTrend(serviceId, step, durationPoints);
List<Integer> throughputTrends = serviceMetricUIDAO.getServiceThroughputTrend(serviceId, step, durationPoints);
throughputTrend.setTrendList(throughputTrends);
return throughputTrend;
}
......@@ -92,14 +86,13 @@ public class ServiceNameService {
}
public List<ServiceMetric> getSlowService(Step step, long startTimeBucket, long endTimeBucket,
long startSecondTimeBucket, long endSecondTimeBucket,
Integer topN) throws ParseException {
long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) {
List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(0, step, startTimeBucket, endTimeBucket, topN, MetricSource.Callee);
slowServices.forEach(slowService -> {
ServiceName serviceName = serviceNameCacheService.get(slowService.getId());
slowService.setName(serviceName.getServiceName());
try {
slowService.setCallsPerSec((int)(slowService.getCalls() / secondBetweenService.calculate(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
slowService.setCpm((int)(slowService.getCalls() / dateBetweenService.minutesBetween(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
......
......@@ -19,12 +19,7 @@
package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.apache.skywalking.apm.collector.configuration.ConfigurationModule;
......@@ -32,18 +27,11 @@ import org.apache.skywalking.apm.collector.configuration.service.IComponentLibra
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
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.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.slf4j.*;
/**
* @author peng-yongsheng
......@@ -56,7 +44,7 @@ public class ServiceTopologyService {
private final IServiceMetricUIDAO serviceMetricUIDAO;
private final IServiceReferenceMetricUIDAO serviceReferenceMetricUIDAO;
private final ServiceNameCacheService serviceNameCacheService;
private final SecondBetweenService secondBetweenService;
private final DateBetweenService dateBetweenService;
private final IComponentLibraryCatalogService componentLibraryCatalogService;
public ServiceTopologyService(ModuleManager moduleManager) {
......@@ -64,12 +52,12 @@ public class ServiceTopologyService {
this.serviceReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceReferenceMetricUIDAO.class);
this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class);
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
this.secondBetweenService = new SecondBetweenService(moduleManager);
this.dateBetweenService = new DateBetweenService(moduleManager);
this.componentLibraryCatalogService = moduleManager.find(ConfigurationModule.NAME).getService(IComponentLibraryCatalogService.class);
}
public Topology getServiceTopology(Step step, int serviceId, long startTimeBucket,
long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) throws ParseException {
long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) {
logger.debug("startTimeBucket: {}, endTimeBucket: {}", startTimeBucket, endTimeBucket);
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTimeBucket, endTimeBucket);
......@@ -93,7 +81,7 @@ public class ServiceTopologyService {
call.setCallType(components.getOrDefault(serviceNameCacheService.get(referenceMetric.getTarget()).getApplicationId(), Const.UNKNOWN));
try {
int applicationId = serviceNameCacheService.get(referenceMetric.getTarget()).getApplicationId();
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(applicationId, startSecondTimeBucket, endSecondTimeBucket));
call.setCpm(referenceMetric.getCalls() / dateBetweenService.minutesBetween(applicationId, startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
......
......@@ -19,36 +19,20 @@
package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.configuration.ConfigurationModule;
import org.apache.skywalking.apm.collector.configuration.service.IComponentLibraryCatalogService;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.core.util.*;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm;
import org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode;
import org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode;
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.Step;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.skywalking.apm.collector.storage.ui.application.*;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.ui.utils.*;
import org.slf4j.*;
/**
* @author peng-yongsheng
......@@ -59,14 +43,14 @@ class TopologyBuilder {
private final ApplicationCacheService applicationCacheService;
private final ServerService serverService;
private final SecondBetweenService secondBetweenService;
private final DateBetweenService dateBetweenService;
private final AlarmService alarmService;
private final IComponentLibraryCatalogService componentLibraryCatalogService;
TopologyBuilder(ModuleManager moduleManager) {
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
this.serverService = new ServerService(moduleManager);
this.secondBetweenService = new SecondBetweenService(moduleManager);
this.dateBetweenService = new DateBetweenService(moduleManager);
this.alarmService = new AlarmService(moduleManager);
this.componentLibraryCatalogService = moduleManager.find(ConfigurationModule.NAME).getService(IComponentLibraryCatalogService.class);
}
......@@ -96,7 +80,7 @@ class TopologyBuilder {
applicationNode.setSla(SLACalculator.INSTANCE.calculate(applicationMetric.getErrorCalls(), applicationMetric.getCalls()));
try {
applicationNode.setCallsPerSec(applicationMetric.getCalls() / secondBetweenService.calculate(applicationId, startSecondTimeBucket, endSecondTimeBucket));
applicationNode.setCpm(applicationMetric.getCalls() / dateBetweenService.minutesBetween(applicationId, startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
......@@ -167,7 +151,7 @@ class TopologyBuilder {
call.setAlert(false);
call.setCallType(components.get(referenceMetric.getTarget()));
try {
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(source.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
call.setCpm(referenceMetric.getCalls() / dateBetweenService.minutesBetween(source.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
......@@ -214,7 +198,7 @@ class TopologyBuilder {
call.setCallType(components.get(referenceMetric.getTarget()));
}
try {
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(target.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
call.setCpm(referenceMetric.getCalls() / dateBetweenService.minutesBetween(target.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
......
......@@ -18,17 +18,13 @@
package org.apache.skywalking.apm.collector.ui.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.text.*;
import java.util.*;
import org.apache.skywalking.apm.collector.core.UnexpectedException;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.joda.time.DateTime;
import org.joda.time.Seconds;
import org.joda.time.*;
/**
* @author peng-yongsheng
......@@ -36,13 +32,13 @@ import org.joda.time.Seconds;
public enum DurationUtils {
INSTANCE;
public long exchangeToTimeBucket(String dateStr) throws ParseException {
public long exchangeToTimeBucket(String dateStr) {
dateStr = dateStr.replaceAll("-", Const.EMPTY_STRING);
dateStr = dateStr.replaceAll(" ", Const.EMPTY_STRING);
return Long.valueOf(dateStr);
}
public long startTimeDurationToSecondTimeBucket(Step step, String dateStr) throws ParseException {
public long startTimeDurationToSecondTimeBucket(Step step, String dateStr) {
long secondTimeBucket = 0;
switch (step) {
case MONTH:
......@@ -64,7 +60,7 @@ public enum DurationUtils {
return secondTimeBucket;
}
public long endTimeDurationToSecondTimeBucket(Step step, String dateStr) throws ParseException {
public long endTimeDurationToSecondTimeBucket(Step step, String dateStr) {
long secondTimeBucket = 0;
switch (step) {
case MONTH:
......@@ -86,36 +82,38 @@ public enum DurationUtils {
return secondTimeBucket;
}
public int secondsBetween(Step step, long startTimeBucket, long endTimeBucket) throws ParseException {
Date startDate = null;
Date endDate = null;
public int minutesBetween(Step step, long startTimeBucket, long endTimeBucket) throws ParseException {
Date startDate = formatDate(step, startTimeBucket);
Date endDate = formatDate(step, endTimeBucket);
return Minutes.minutesBetween(new DateTime(startDate), new DateTime(endDate)).getMinutes();
}
public int minutesBetween(Step step, DateTime dateTime) {
switch (step) {
case MONTH:
startDate = new SimpleDateFormat("yyyyMM").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMM").parse(String.valueOf(endTimeBucket));
break;
return dateTime.dayOfMonth().getMaximumValue() * 24 * 60;
case DAY:
startDate = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(endTimeBucket));
break;
return 24 * 60;
case HOUR:
startDate = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(endTimeBucket));
break;
return 60;
case MINUTE:
startDate = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(endTimeBucket));
break;
return 1;
case SECOND:
startDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(endTimeBucket));
break;
return 1;
default:
return 1;
}
}
public int secondsBetween(Step step, long startTimeBucket, long endTimeBucket) throws ParseException {
Date startDate = formatDate(step, startTimeBucket);
Date endDate = formatDate(step, endTimeBucket);
return Seconds.secondsBetween(new DateTime(startDate), new DateTime(endDate)).getSeconds();
}
public int secondsBetween(Step step, DateTime dateTime) throws ParseException {
public int secondsBetween(Step step, DateTime dateTime) {
switch (step) {
case MONTH:
return dateTime.dayOfMonth().getMaximumValue() * 24 * 60 * 60;
......@@ -132,6 +130,28 @@ public enum DurationUtils {
}
}
private Date formatDate(Step step, long timeBucket) throws ParseException {
Date date = null;
switch (step) {
case MONTH:
date = new SimpleDateFormat("yyyyMM").parse(String.valueOf(timeBucket));
break;
case DAY:
date = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(timeBucket));
break;
case HOUR:
date = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(timeBucket));
break;
case MINUTE:
date = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(timeBucket));
break;
case SECOND:
date = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(timeBucket));
break;
}
return date;
}
public DateTime parseToDateTime(Step step, long time) throws ParseException {
DateTime dateTime = null;
......@@ -166,7 +186,7 @@ public enum DurationUtils {
DateTime dateTime = parseToDateTime(step, startTimeBucket);
List<DurationPoint> durations = new LinkedList<>();
durations.add(new DurationPoint(startTimeBucket, secondsBetween(step, dateTime)));
durations.add(new DurationPoint(startTimeBucket, secondsBetween(step, dateTime), minutesBetween(step, dateTime)));
int i = 0;
do {
......@@ -174,27 +194,27 @@ public enum DurationUtils {
case MONTH:
dateTime = dateTime.plusMonths(1);
String timeBucket = new SimpleDateFormat("yyyyMM").format(dateTime.toDate());
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime), minutesBetween(step, dateTime)));
break;
case DAY:
dateTime = dateTime.plusDays(1);
timeBucket = new SimpleDateFormat("yyyyMMdd").format(dateTime.toDate());
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime), minutesBetween(step, dateTime)));
break;
case HOUR:
dateTime = dateTime.plusHours(1);
timeBucket = new SimpleDateFormat("yyyyMMddHH").format(dateTime.toDate());
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime), minutesBetween(step, dateTime)));
break;
case MINUTE:
dateTime = dateTime.plusMinutes(1);
timeBucket = new SimpleDateFormat("yyyyMMddHHmm").format(dateTime.toDate());
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime), minutesBetween(step, dateTime)));
break;
case SECOND:
dateTime = dateTime.plusSeconds(1);
timeBucket = new SimpleDateFormat("yyyyMMddHHmmss").format(dateTime.toDate());
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime)));
durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime), minutesBetween(step, dateTime)));
break;
}
i++;
......
......@@ -94,8 +94,8 @@ public class ServerQueryTest {
}
@Test
public void getServerTPSTrend() throws ParseException {
Mockito.when(serverService.getServerTPSTrend(Mockito.anyInt(), Mockito.anyObject(), Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
public void getServerThroughputTrend() throws ParseException {
Mockito.when(serverService.getServerThroughputTrend(Mockito.anyInt(), Mockito.anyObject(), Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
......@@ -106,7 +106,7 @@ public class ServerQueryTest {
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serverQuery.getServerTPSTrend(-1, duration);
serverQuery.getServerThroughputTrend(-1, duration);
}
@Test
......
......@@ -72,8 +72,8 @@ public class ServiceQueryTest {
}
@Test
public void getServiceTPSTrend() throws ParseException {
Mockito.when(serviceNameService.getServiceTPSTrend(
public void getServiceThroughputTrend() throws ParseException {
Mockito.when(serviceNameService.getServiceThroughputTrend(
Mockito.anyInt(), Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong())
).then(invocation -> {
......@@ -86,7 +86,7 @@ public class ServiceQueryTest {
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serviceQuery.getServiceTPSTrend(-1, duration);
serviceQuery.getServiceThroughputTrend(-1, duration);
}
@Test
......
......@@ -17,34 +17,21 @@
package org.apache.skywalking.apm.collector.ui.service;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.apache.skywalking.apm.collector.core.module.MockModule;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
import java.text.ParseException;
import java.util.*;
import org.apache.skywalking.apm.collector.cache.service.*;
import org.apache.skywalking.apm.collector.core.module.*;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
import org.apache.skywalking.apm.collector.storage.ui.application.Application;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalApp;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalAppBrief;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.storage.ui.overview.*;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
......@@ -60,11 +47,10 @@ public class ApplicationServiceTest {
private INetworkAddressUIDAO networkAddressUIDAO;
private ApplicationCacheService applicationCacheService;
private ServiceNameCacheService serviceNameCacheService;
private SecondBetweenService secondBetweenService;
private DateBetweenService dateBetweenService;
private ApplicationService applicationService;
private Duration duration;
@Before
public void setUp() throws Exception {
ModuleManager moduleManager = mock(ModuleManager.class);
......@@ -76,14 +62,14 @@ public class ApplicationServiceTest {
networkAddressUIDAO = mock(INetworkAddressUIDAO.class);
applicationCacheService = mock(ApplicationCacheService.class);
serviceNameCacheService = mock(ServiceNameCacheService.class);
secondBetweenService = mock(SecondBetweenService.class);
dateBetweenService = mock(DateBetweenService.class);
Whitebox.setInternalState(applicationService, "instanceDAO", instanceDAO);
Whitebox.setInternalState(applicationService, "serviceMetricUIDAO", serviceMetricUIDAO);
Whitebox.setInternalState(applicationService, "applicationMetricUIDAO", applicationMetricUIDAO);
Whitebox.setInternalState(applicationService, "networkAddressUIDAO", networkAddressUIDAO);
Whitebox.setInternalState(applicationService, "applicationCacheService", applicationCacheService);
Whitebox.setInternalState(applicationService, "serviceNameCacheService", serviceNameCacheService);
Whitebox.setInternalState(applicationService, "secondBetweenService", secondBetweenService);
Whitebox.setInternalState(applicationService, "dateBetweenService", dateBetweenService);
duration = new Duration();
duration.setEnd("2018-02");
duration.setStart("2018-01");
......@@ -139,9 +125,9 @@ public class ApplicationServiceTest {
serviceName.setServiceName("serviceName");
return serviceName;
});
when(secondBetweenService.calculate(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
when(dateBetweenService.minutesBetween(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
List<ServiceMetric> slowService = applicationService.getSlowService(-1, duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket, 10);
Assert.assertTrue(slowService.get(0).getCallsPerSec() > 0);
Assert.assertTrue(slowService.get(0).getCpm() > 0);
}
@Test
......@@ -149,12 +135,12 @@ public class ApplicationServiceTest {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
when(applicationMetricUIDAO.getTopNApplicationThroughput(anyObject(), anyLong(), anyLong(), anyInt(), anyInt(), anyObject())).then(invocation -> {
ApplicationTPS applicationTPS = new ApplicationTPS();
applicationTPS.setApplicationId(-1);
return Collections.singletonList(applicationTPS);
ApplicationThroughput applicationThroughput = new ApplicationThroughput();
applicationThroughput.setApplicationId(-1);
return Collections.singletonList(applicationThroughput);
});
mockCache();
List<ApplicationTPS> topNApplicationThroughput = applicationService.getTopNApplicationThroughput(duration.getStep(), startTimeBucket, endTimeBucket, 10);
List<ApplicationThroughput> topNApplicationThroughput = applicationService.getTopNApplicationThroughput(duration.getStep(), startTimeBucket, endTimeBucket, 10);
Assert.assertTrue(topNApplicationThroughput.size() > 0);
}
......
......@@ -38,9 +38,9 @@ import static org.powermock.api.mockito.PowerMockito.when;
/**
* @author lican
*/
public class SecondBetweenServiceTest {
public class DateBetweenServiceTest {
private SecondBetweenService secondBetweenService;
private DateBetweenService dateBetweenService;
private IInstanceUIDAO instanceUIDAO;
......@@ -50,9 +50,9 @@ public class SecondBetweenServiceTest {
public void setUp() throws Exception {
ModuleManager moduleManager = mock(ModuleManager.class);
when(moduleManager.find(anyString())).then(invocation -> new MockModule());
secondBetweenService = new SecondBetweenService(moduleManager);
dateBetweenService = new DateBetweenService(moduleManager);
instanceUIDAO = mock(IInstanceUIDAO.class);
Whitebox.setInternalState(secondBetweenService, "instanceUIDAO", instanceUIDAO);
Whitebox.setInternalState(dateBetweenService, "instanceUIDAO", instanceUIDAO);
duration = new Duration();
duration.setEnd("2018-02");
duration.setStart("2018-01");
......@@ -60,11 +60,11 @@ public class SecondBetweenServiceTest {
}
@Test
public void calculate() throws ParseException {
public void secondsBetween() throws ParseException {
long startSecondTimeBucket = DurationUtils.INSTANCE.startTimeDurationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endSecondTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(duration.getStep(), duration.getEnd());
when(instanceUIDAO.getLatestHeartBeatTime(anyInt())).then(invocation -> endSecondTimeBucket);
int seconds = secondBetweenService.calculate(1, startSecondTimeBucket, endSecondTimeBucket);
int seconds = dateBetweenService.secondsBetween(1, startSecondTimeBucket, endSecondTimeBucket);
Assert.assertTrue(seconds > 0);
}
}
\ No newline at end of file
......@@ -17,43 +17,21 @@
package org.apache.skywalking.apm.collector.ui.service;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.*;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService;
import org.apache.skywalking.apm.collector.core.module.MockModule;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.table.register.Instance;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo;
import org.apache.skywalking.apm.collector.storage.ui.server.CPUTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.GCTrend;
import org.apache.skywalking.apm.collector.storage.ui.server.MemoryTrend;
import java.util.*;
import org.apache.skywalking.apm.collector.cache.service.*;
import org.apache.skywalking.apm.collector.core.module.*;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.register.*;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.storage.ui.server.*;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
......@@ -69,7 +47,7 @@ public class ServerServiceTest {
private IMemoryMetricUIDAO memoryMetricUIDAO;
private ApplicationCacheService applicationCacheService;
private InstanceCacheService instanceCacheService;
private SecondBetweenService secondBetweenService;
private DateBetweenService dateBetweenService;
private ServerService serverService;
private Duration duration;
private long startSecondTimeBucket;
......@@ -89,7 +67,7 @@ public class ServerServiceTest {
memoryMetricUIDAO = mock(IMemoryMetricUIDAO.class);
applicationCacheService = mock(ApplicationCacheService.class);
instanceCacheService = mock(InstanceCacheService.class);
secondBetweenService = mock(SecondBetweenService.class);
dateBetweenService = mock(DateBetweenService.class);
Whitebox.setInternalState(serverService, "instanceUIDAO", instanceUIDAO);
Whitebox.setInternalState(serverService, "instanceMetricUIDAO", instanceMetricUIDAO);
Whitebox.setInternalState(serverService, "cpuMetricUIDAO", cpuMetricUIDAO);
......@@ -97,7 +75,7 @@ public class ServerServiceTest {
Whitebox.setInternalState(serverService, "memoryMetricUIDAO", memoryMetricUIDAO);
Whitebox.setInternalState(serverService, "applicationCacheService", applicationCacheService);
Whitebox.setInternalState(serverService, "instanceCacheService", instanceCacheService);
Whitebox.setInternalState(serverService, "secondBetweenService", secondBetweenService);
Whitebox.setInternalState(serverService, "dateBetweenService", dateBetweenService);
duration = new Duration();
duration.setEnd("2018-02");
duration.setStart("2018-01");
......@@ -176,8 +154,8 @@ public class ServerServiceTest {
}
@Test
public void getServerTPSTrend() throws ParseException {
ThroughputTrend serverTPSTrend = serverService.getServerTPSTrend(1, duration.getStep(), startTimeBucket, endTimeBucket);
public void getServerThroughputTrend() throws ParseException {
ThroughputTrend serverTPSTrend = serverService.getServerThroughputTrend(1, duration.getStep(), startTimeBucket, endTimeBucket);
Assert.assertNotNull(serverTPSTrend);
}
......
......@@ -17,26 +17,19 @@
package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.util.*;
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.apache.skywalking.apm.collector.core.module.MockModule;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO;
import org.apache.skywalking.apm.collector.core.module.*;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.storage.ui.service.*;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
import java.util.Collections;
import java.util.List;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
......@@ -49,7 +42,7 @@ public class ServiceNameServiceTest {
private IServiceNameServiceUIDAO serviceNameServiceUIDAO;
private IServiceMetricUIDAO serviceMetricUIDAO;
private ServiceNameCacheService serviceNameCacheService;
private SecondBetweenService secondBetweenService;
private DateBetweenService dateBetweenService;
private ServiceNameService serverNameService;
private Duration duration;
private long startSecondTimeBucket;
......@@ -64,10 +57,10 @@ public class ServiceNameServiceTest {
serverNameService = new ServiceNameService(moduleManager);
serviceNameCacheService = mock(ServiceNameCacheService.class);
serviceMetricUIDAO = mock(IServiceMetricUIDAO.class);
secondBetweenService = mock(SecondBetweenService.class);
dateBetweenService = mock(DateBetweenService.class);
Whitebox.setInternalState(serverNameService, "serviceNameCacheService", serviceNameCacheService);
Whitebox.setInternalState(serverNameService, "serviceMetricUIDAO", serviceMetricUIDAO);
Whitebox.setInternalState(serverNameService, "secondBetweenService", secondBetweenService);
Whitebox.setInternalState(serverNameService, "dateBetweenService", dateBetweenService);
duration = new Duration();
duration.setEnd("2018-02");
duration.setStart("2018-01");
......@@ -91,8 +84,8 @@ public class ServiceNameServiceTest {
}
@Test
public void getServiceTPSTrend() throws ParseException {
ThroughputTrend serviceTPSTrend = serverNameService.getServiceTPSTrend(1, duration.getStep(), startTimeBucket, endTimeBucket);
public void getServiceThroughputTrend() throws ParseException {
ThroughputTrend serviceTPSTrend = serverNameService.getServiceThroughputTrend(1, duration.getStep(), startTimeBucket, endTimeBucket);
Assert.assertNotNull(serviceTPSTrend);
}
......@@ -118,7 +111,7 @@ public class ServiceNameServiceTest {
serviceMetric.setId(1);
return Collections.singletonList(serviceMetric);
});
when(secondBetweenService.calculate(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
when(dateBetweenService.minutesBetween(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
mockCache();
List<ServiceMetric> slowService = serverNameService.getSlowService(duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket, 10);
Assert.assertTrue(slowService.size() > 0);
......
......@@ -17,30 +17,19 @@
package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.util.*;
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.apache.skywalking.apm.collector.core.module.MockModule;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.core.module.*;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
......@@ -54,7 +43,7 @@ public class ServiceTopologyServiceTest {
private IServiceMetricUIDAO serviceMetricUIDAO;
private IServiceReferenceMetricUIDAO serviceReferenceMetricUIDAO;
private ServiceNameCacheService serviceNameCacheService;
private SecondBetweenService secondBetweenService;
private DateBetweenService dateBetweenService;
private ServiceTopologyService serviceTopologyService;
private Duration duration;
private long startSecondTimeBucket;
......@@ -71,12 +60,12 @@ public class ServiceTopologyServiceTest {
serviceMetricUIDAO = mock(IServiceMetricUIDAO.class);
serviceReferenceMetricUIDAO = mock(IServiceReferenceMetricUIDAO.class);
serviceNameCacheService = mock(ServiceNameCacheService.class);
secondBetweenService = mock(SecondBetweenService.class);
dateBetweenService = mock(DateBetweenService.class);
Whitebox.setInternalState(serviceTopologyService, "applicationComponentUIDAO", applicationComponentUIDAO);
Whitebox.setInternalState(serviceTopologyService, "serviceMetricUIDAO", serviceMetricUIDAO);
Whitebox.setInternalState(serviceTopologyService, "serviceReferenceMetricUIDAO", serviceReferenceMetricUIDAO);
Whitebox.setInternalState(serviceTopologyService, "serviceNameCacheService", serviceNameCacheService);
Whitebox.setInternalState(serviceTopologyService, "secondBetweenService", secondBetweenService);
Whitebox.setInternalState(serviceTopologyService, "dateBetweenService", dateBetweenService);
duration = new Duration();
duration.setEnd("2018-02");
duration.setStart("2018-01");
......@@ -113,7 +102,7 @@ public class ServiceTopologyServiceTest {
});
mockCache();
when(secondBetweenService.calculate(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
when(dateBetweenService.minutesBetween(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
when(serviceMetricUIDAO.getServicesMetric(anyObject(), anyLong(), anyLong(), anyObject(), anyObject())).then(invocation -> {
List<Node> nodes = new LinkedList<>();
ServiceNode serviceNode = new ServiceNode();
......
......@@ -17,31 +17,19 @@
package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.util.*;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.core.module.MockModule;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.core.module.*;
import org.apache.skywalking.apm.collector.storage.dao.ui.*;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm;
import org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmItem;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.apache.skywalking.apm.collector.storage.ui.alarm.*;
import org.apache.skywalking.apm.collector.storage.ui.common.*;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
......@@ -53,7 +41,7 @@ public class TopologyBuilderTest {
private ApplicationCacheService applicationCacheService;
private ServerService serverService;
private SecondBetweenService secondBetweenService;
private DateBetweenService dateBetweenService;
private AlarmService alarmService;
private TopologyBuilder topologyBuilder;
private Duration duration;
......@@ -69,10 +57,10 @@ public class TopologyBuilderTest {
topologyBuilder = new TopologyBuilder(moduleManager);
applicationCacheService = mock(ApplicationCacheService.class);
alarmService = mock(AlarmService.class);
secondBetweenService = mock(SecondBetweenService.class);
dateBetweenService = mock(DateBetweenService.class);
Whitebox.setInternalState(topologyBuilder, "applicationCacheService", applicationCacheService);
Whitebox.setInternalState(topologyBuilder, "alarmService", alarmService);
Whitebox.setInternalState(topologyBuilder, "secondBetweenService", secondBetweenService);
Whitebox.setInternalState(topologyBuilder, "dateBetweenService", dateBetweenService);
duration = new Duration();
duration.setEnd("2018-02");
duration.setStart("2018-01");
......@@ -140,7 +128,7 @@ public class TopologyBuilderTest {
alarm.setItems(Collections.singletonList(new AlarmItem()));
return alarm;
});
when(secondBetweenService.calculate(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
when(dateBetweenService.minutesBetween(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
Topology topology = topologyBuilder.build(applicationComponents, applicationMappings, applicationMetrics, callerReferenceMetric, calleeReferenceMetric, duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
Assert.assertNotNull(topology);
}
......
......@@ -24,7 +24,7 @@ type ApplicationNode implements Node {
# 2 Digits after floating point in UI, need to division by 100. 10000 -> 100.00
sla: Int!
# The number of incoming calls
callsPerSec: Long!
cpm: Long!
# Unit: millisecond
avgResponseTime: Long!
# ref: http://www.apdex.org/
......
......@@ -120,7 +120,7 @@ type Call {
isAlert: Boolean
# The protocol and tech stack used in this distributed call
callType: String!
callsPerSec: Long!
cpm: Long!
# Unit: millisecond
avgResponseTime: Long!
}
......
......@@ -43,10 +43,10 @@ type ConjecturalApp {
num: Int!
}
type ApplicationTPS {
type ApplicationThroughput {
applicationId: Int!
applicationCode: String
callsPerSec: Int!
cpm: Int!
}
type Thermodynamic {
......@@ -71,6 +71,6 @@ extend type Query {
getAlarmTrend(duration: Duration!): AlarmTrend
getConjecturalApps(duration: Duration!): ConjecturalAppBrief
getTopNSlowService(duration: Duration!, topN: Int!): [ServiceMetric!]!
getTopNApplicationThroughput(duration: Duration!, topN: Int!): [ApplicationTPS!]!
getTopNApplicationThroughput(duration: Duration!, topN: Int!): [ApplicationThroughput!]!
getThermodynamic(duration: Duration!, type: ValueType!): Thermodynamic!
}
......@@ -24,7 +24,7 @@ type AppServerInfo {
osName: String!
applicationId: Int!
applicationCode: String
callsPerSec: Int!
cpm: Int!
host: String
pid: Int
ipv4: [String!]!
......@@ -34,10 +34,12 @@ type CPUTrend {
cost: [Int!]!
}
# The gc trend represents the numbers of Garbage Collector execution
# The gc trend represents the numbers and time of Garbage Collector execution
type GCTrend {
youngGC: [Int!]!
oldGC: [Int!]!
youngGCCount: [Int!]!
oldGCount: [Int!]!
youngGCTime: [Int!]!
oldGCTime: [Int!]!
}
# The memory used and max limit in heap and noheap space.
......@@ -52,7 +54,7 @@ extend type Query {
searchServer(keyword: String!, duration: Duration!): [AppServerInfo!]!
getAllServer(applicationId: ID!, duration: Duration!): [AppServerInfo!]!
getServerResponseTimeTrend(serverId: ID!, duration: Duration!): ResponseTimeTrend
getServerTPSTrend(serverId: ID!, duration: Duration!): ThroughputTrend
getServerThroughputTrend(serverId: ID!, duration: Duration!): ThroughputTrend
getCPUTrend(serverId: ID!, duration: Duration!): CPUTrend
getGCTrend(serverId: ID!, duration: Duration!): GCTrend
getMemoryTrend(serverId: ID!, duration: Duration!): MemoryTrend
......
......@@ -37,7 +37,7 @@ type ServiceMetric {
name: String
# The unit is millisecond.
avgResponseTime: Int!
callsPerSec: Int!
cpm: Int!
}
type TraceItem {
......@@ -49,7 +49,7 @@ type TraceItem {
extend type Query {
searchService(keyword: String!, topN: Int!): [ServiceInfo!]!
getServiceResponseTimeTrend(serviceId: ID!, duration: Duration!): ResponseTimeTrend
getServiceTPSTrend(serviceId: ID!, duration: Duration!): ThroughputTrend
getServiceThroughputTrend(serviceId: ID!, duration: Duration!): ThroughputTrend
getServiceSLATrend(serviceId: ID!, duration: Duration!): SLATrend
getServiceTopology(serviceId: ID!, duration: Duration!): Topology
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册