Skip to content

Commit

Permalink
Merge dafe6fb into dcee409
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyangyong committed Dec 23, 2017
2 parents dcee409 + dafe6fb commit 7c9ff40
Show file tree
Hide file tree
Showing 24 changed files with 924 additions and 279 deletions.
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");
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ public Class<? extends Event> getConcernedEvent() {
public void process(Event data) {
InvocationStartProcessingEvent event = (InvocationStartProcessingEvent) data;
InvocationMonitor monitor = registryMonitor.getInvocationMonitor(event.getOperationName());
//TODO:current java chassis unable know invocation type before starting process,so all type WaitInQueue increment(-1) (decrement)
monitor.getWaitInQueue().increment(-1);
monitor.setInvocationMonitorType(event.getInvocationType());
if (InvocationType.PRODUCER.equals(event.getInvocationType())) {
monitor.getLifeTimeInQueue().update(event.getInQueueNanoTime());
monitor.getProducerCall().increment();
} else {
monitor.getConsumerCall().increment();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public Class<? extends Event> getConcernedEvent() {
@Override
public void process(Event data) {
InvocationStartedEvent event = (InvocationStartedEvent) data;
//TODO:current java chassis unable know invocation type before starting process,so all type WaitInQueue increment
registryMonitor.getInvocationMonitor(event.getOperationName()).getWaitInQueue().increment();
}
}
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;
}
}
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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,37 @@

package io.servicecomb.metrics.core.metric;

public class InstanceMetric extends ModelMetric {
public class InstanceMetric {
private final long waitInQueue;

private final SystemMetric systemMetric;

private final ConsumerInvocationMetric consumerMetric;

private final ProducerInvocationMetric producerMetric;

public long getWaitInQueue() {
return waitInQueue;
}

public SystemMetric getSystemMetric() {
return systemMetric;
}

public ConsumerInvocationMetric getConsumerMetric() {
return consumerMetric;
}

public ProducerInvocationMetric getProducerMetric() {
return producerMetric;
}

public InstanceMetric(long waitInQueue, SystemMetric systemMetric,
TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric consumerLatency,
TimerMetric producerLatency) {
super(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency);
ConsumerInvocationMetric consumerMetric,
ProducerInvocationMetric producerMetric) {
this.waitInQueue = waitInQueue;
this.systemMetric = systemMetric;
this.consumerMetric = consumerMetric;
this.producerMetric = producerMetric;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,40 @@

package io.servicecomb.metrics.core.metric;

public class InvocationMetric extends ModelMetric {
public class InvocationMetric {
private final String operationName;

private final String prefix;

private final long waitInQueue;

public String getOperationName() {
return operationName;
}

public InvocationMetric(String operationName, long waitInQueue,
TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric consumerLatency,
TimerMetric producerLatency) {
super(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency);
public String getPrefix() {
return prefix;
}

public long getWaitInQueue() {
return waitInQueue;
}

public InvocationMetric(String operationName, String prefix, long waitInQueue) {
this.operationName = operationName;
this.prefix = prefix;
this.waitInQueue = waitInQueue;
}

public InstanceCalculationMetric merge(InstanceCalculationMetric metric) {
return new InstanceCalculationMetric(metric.getTotalWaitInQueue() + waitInQueue,
metric.getProducerWaitInQueue(),
metric.getConsumerMetrics(), metric.getProducerMetrics(),
metric.getLifeTimeInQueue(),
metric.getExecutionTime(),
metric.getConsumerLatency(),
metric.getProducerLatency(),
metric.getConsumerCall(),
metric.getProducerCall());
}
}

0 comments on commit 7c9ff40

Please sign in to comment.