-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
924 additions
and
279 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/MetricsConst.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.servicecomb.metrics.core; | ||
|
||
public class MetricsConst { | ||
public static final String CONSUMER_PREFIX_TEMPLATE = "servicecomb.%s.consumer"; | ||
|
||
public static final String PRODUCER_PREFIX_TEMPLATE = "servicecomb.%s.producer"; | ||
|
||
public static final String INSTANCE_CONSUMER_PREFIX = String.format(CONSUMER_PREFIX_TEMPLATE, "instance"); | ||
|
||
public static final String INSTANCE_PRODUCER_PREFIX = String.format(PRODUCER_PREFIX_TEMPLATE, "instance"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.servicecomb.metrics.core.metric; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class CallMetric { | ||
private final String prefix; | ||
|
||
private final long total; | ||
|
||
private final double tps; | ||
|
||
public long getTotal() { | ||
return total; | ||
} | ||
|
||
public double getTps() { | ||
return tps; | ||
} | ||
|
||
public CallMetric(String prefix) { | ||
this(prefix, 0, 0); | ||
} | ||
|
||
public CallMetric(String prefix, long total, double tps) { | ||
this.prefix = prefix; | ||
this.total = total; | ||
this.tps = tps; | ||
} | ||
|
||
public CallMetric merge(CallMetric metric) { | ||
return new CallMetric(this.prefix, this.total + metric.total, this.tps + metric.tps); | ||
} | ||
|
||
public Map<String, Number> toMap() { | ||
Map<String, Number> metrics = new HashMap<>(); | ||
metrics.put(prefix + ".total", total); | ||
metrics.put(prefix + ".tps", tps); | ||
return metrics; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...trics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.servicecomb.metrics.core.metric; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ConsumerInvocationMetric extends InvocationMetric { | ||
private final TimerMetric consumerLatency; | ||
|
||
private final CallMetric consumerCall; | ||
|
||
public TimerMetric getConsumerLatency() { | ||
return consumerLatency; | ||
} | ||
|
||
public CallMetric getConsumerCall() { | ||
return consumerCall; | ||
} | ||
|
||
public ConsumerInvocationMetric(String operationName, String prefix, long waitInQueue, | ||
TimerMetric consumerLatency, CallMetric consumerCall) { | ||
super(operationName, prefix, waitInQueue); | ||
this.consumerLatency = consumerLatency; | ||
this.consumerCall = consumerCall; | ||
} | ||
|
||
@Override | ||
public InstanceCalculationMetric merge(InstanceCalculationMetric metric) { | ||
metric.getConsumerMetrics().put(this.getOperationName(), this); | ||
return new InstanceCalculationMetric(metric.getTotalWaitInQueue(), | ||
metric.getProducerWaitInQueue(), | ||
metric.getConsumerMetrics(), metric.getProducerMetrics(), | ||
metric.getLifeTimeInQueue(), | ||
metric.getExecutionTime(), | ||
metric.getConsumerLatency().merge(consumerLatency), | ||
metric.getProducerLatency(), | ||
metric.getConsumerCall().merge(consumerCall), | ||
metric.getProducerCall()); | ||
} | ||
|
||
public Map<String, Number> toMap() { | ||
Map<String, Number> metrics = new HashMap<>(); | ||
metrics.putAll(consumerLatency.toMap()); | ||
metrics.putAll(consumerCall.toMap()); | ||
return metrics; | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
...rics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceCalculationMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.servicecomb.metrics.core.metric; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.servicecomb.metrics.core.MetricsConst; | ||
|
||
public class InstanceCalculationMetric { | ||
private final Map<String, ConsumerInvocationMetric> consumerMetrics; | ||
|
||
private final Map<String, ProducerInvocationMetric> producerMetrics; | ||
|
||
//TODO:current java chassis unable know invocation type before starting process,totalWaitInQueue = ProducerInvocation + UnknownTypeInvocation | ||
private final long totalWaitInQueue; | ||
|
||
private final long producerWaitInQueue; | ||
|
||
private final TimerMetric lifeTimeInQueue; | ||
|
||
private final TimerMetric executionTime; | ||
|
||
private final TimerMetric consumerLatency; | ||
|
||
private final TimerMetric producerLatency; | ||
|
||
private final CallMetric consumerCall; | ||
|
||
private final CallMetric producerCall; | ||
|
||
public long getTotalWaitInQueue() { | ||
return totalWaitInQueue; | ||
} | ||
|
||
public long getProducerWaitInQueue() { | ||
return producerWaitInQueue; | ||
} | ||
|
||
public Map<String, ConsumerInvocationMetric> getConsumerMetrics() { | ||
return consumerMetrics; | ||
} | ||
|
||
public Map<String, ProducerInvocationMetric> getProducerMetrics() { | ||
return producerMetrics; | ||
} | ||
|
||
public TimerMetric getLifeTimeInQueue() { | ||
return lifeTimeInQueue; | ||
} | ||
|
||
public TimerMetric getExecutionTime() { | ||
return executionTime; | ||
} | ||
|
||
public TimerMetric getConsumerLatency() { | ||
return consumerLatency; | ||
} | ||
|
||
public TimerMetric getProducerLatency() { | ||
return producerLatency; | ||
} | ||
|
||
public CallMetric getConsumerCall() { | ||
return consumerCall; | ||
} | ||
|
||
public CallMetric getProducerCall() { | ||
return producerCall; | ||
} | ||
|
||
public InstanceCalculationMetric() { | ||
this.totalWaitInQueue = 0; | ||
this.producerWaitInQueue = 0; | ||
this.consumerMetrics = new HashMap<>(); | ||
this.producerMetrics = new HashMap<>(); | ||
this.lifeTimeInQueue = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".lifeTimeInQueue"); | ||
this.executionTime = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".executionTime"); | ||
this.consumerLatency = new TimerMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerLatency"); | ||
this.producerLatency = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerLatency"); | ||
this.consumerCall = new CallMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerCall"); | ||
this.producerCall = new CallMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerCall"); | ||
} | ||
|
||
public InstanceCalculationMetric(long totalWaitInQueue, long producerWaitInQueue, | ||
Map<String, ConsumerInvocationMetric> consumerMetrics, | ||
Map<String, ProducerInvocationMetric> producerMetrics, | ||
TimerMetric lifeTimeInQueue, TimerMetric executionTime, | ||
TimerMetric consumerLatency, TimerMetric producerLatency, | ||
CallMetric consumerCall, CallMetric producerCall) { | ||
this.totalWaitInQueue = totalWaitInQueue; | ||
this.producerWaitInQueue = producerWaitInQueue; | ||
this.consumerMetrics = consumerMetrics; | ||
this.producerMetrics = producerMetrics; | ||
this.lifeTimeInQueue = lifeTimeInQueue; | ||
this.executionTime = executionTime; | ||
this.consumerLatency = consumerLatency; | ||
this.producerLatency = producerLatency; | ||
this.consumerCall = consumerCall; | ||
this.producerCall = producerCall; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.