use of org.apache.skywalking.apm.network.language.agent.v3.MeterData in project skywalking-java by apache.
the class MeterSender method send.
public void send(Map<MeterId, BaseMeter> meterMap, MeterService meterService) {
if (status == GRPCChannelStatus.CONNECTED) {
StreamObserver<MeterData> reportStreamObserver = null;
final GRPCStreamServiceStatus status = new GRPCStreamServiceStatus(false);
try {
reportStreamObserver = meterReportServiceStub.withDeadlineAfter(GRPC_UPSTREAM_TIMEOUT, TimeUnit.SECONDS).collect(new StreamObserver<Commands>() {
@Override
public void onNext(Commands commands) {
}
@Override
public void onError(Throwable throwable) {
status.finished();
if (LOGGER.isErrorEnable()) {
LOGGER.error(throwable, "Send meters to collector fail with a grpc internal exception.");
}
ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(throwable);
}
@Override
public void onCompleted() {
status.finished();
}
});
final StreamObserver<MeterData> reporter = reportStreamObserver;
transform(meterMap, meterData -> reporter.onNext(meterData));
} catch (Throwable e) {
if (!(e instanceof StatusRuntimeException)) {
LOGGER.error(e, "Report meters to backend fail.");
return;
}
final StatusRuntimeException statusRuntimeException = (StatusRuntimeException) e;
if (statusRuntimeException.getStatus().getCode() == Status.Code.UNIMPLEMENTED) {
LOGGER.warn("Backend doesn't support meter, it will be disabled");
meterService.shutdown();
}
} finally {
if (reportStreamObserver != null) {
reportStreamObserver.onCompleted();
}
status.wait4Finish();
}
}
}
use of org.apache.skywalking.apm.network.language.agent.v3.MeterData in project skywalking-java by apache.
the class MeterServiceTest method isSameWithCounter.
/**
* Check counter message
*/
private void isSameWithCounter(MeterData meterData, boolean firstData, MeterId meterId, long count) {
Assert.assertNotNull(meterData);
if (firstData) {
Assert.assertEquals(meterData.getService(), "testService");
Assert.assertEquals(meterData.getServiceInstance(), "testServiceInstance");
Assert.assertTrue(meterData.getTimestamp() > 0);
} else {
Assert.assertEquals(meterData.getService(), "");
Assert.assertEquals(meterData.getServiceInstance(), "");
Assert.assertTrue(meterData.getTimestamp() == 0L);
}
Assert.assertEquals(meterData.getMetricCase(), MeterData.MetricCase.SINGLEVALUE);
Assert.assertNotNull(meterData.getSingleValue());
final MeterSingleValue singleValue = meterData.getSingleValue();
Assert.assertEquals(singleValue.getName(), meterId.getName());
Assert.assertEquals(singleValue.getLabelsList(), meterId.transformTags());
Assert.assertEquals(singleValue.getValue(), count, 0.0);
}
use of org.apache.skywalking.apm.network.language.agent.v3.MeterData in project incubator-skywalking by apache.
the class MeterServiceHandler method handle.
@Override
public void handle(final ConsumerRecord<String, Bytes> record) {
try (HistogramMetrics.Timer ignored = histogramBatch.createTimer()) {
MeterDataCollection meterDataCollection = MeterDataCollection.parseFrom(record.value().get());
MeterProcessor processor = processService.createProcessor();
meterDataCollection.getMeterDataList().forEach(meterData -> {
try (HistogramMetrics.Timer ignored2 = histogram.createTimer()) {
processor.read(meterData);
} catch (Exception e) {
errorCounter.inc();
log.error(e.getMessage(), e);
}
});
processor.process();
} catch (Exception e) {
log.error("handle record failed", e);
}
}
use of org.apache.skywalking.apm.network.language.agent.v3.MeterData in project skywalking by apache.
the class MeterServiceHandler method handle.
@Override
public void handle(final ConsumerRecord<String, Bytes> record) {
try (HistogramMetrics.Timer ignored = histogramBatch.createTimer()) {
MeterDataCollection meterDataCollection = MeterDataCollection.parseFrom(record.value().get());
MeterProcessor processor = processService.createProcessor();
meterDataCollection.getMeterDataList().forEach(meterData -> {
try (HistogramMetrics.Timer ignored2 = histogram.createTimer()) {
processor.read(meterData);
} catch (Exception e) {
errorCounter.inc();
log.error(e.getMessage(), e);
}
});
processor.process();
} catch (Exception e) {
log.error("handle record failed", e);
}
}
use of org.apache.skywalking.apm.network.language.agent.v3.MeterData in project skywalking by apache.
the class MeterProcessor method read.
public void read(MeterData data) {
// Parse and save meter
switch(data.getMetricCase()) {
case SINGLEVALUE:
MeterSingleValue single = data.getSingleValue();
meters.computeIfAbsent(single.getName(), k -> new ArrayList<>()).add(SampleBuilder.builder().name(single.getName()).labels(single.getLabelsList().stream().collect(toImmutableMap(Label::getName, Label::getValue))).value(single.getValue()).build());
break;
case HISTOGRAM:
MeterHistogram histogram = data.getHistogram();
Map<String, String> baseLabel = histogram.getLabelsList().stream().collect(Collectors.toMap(Label::getName, Label::getValue));
meters.computeIfAbsent(histogram.getName(), k -> new ArrayList<>()).addAll(histogram.getValuesList().stream().map(v -> SampleBuilder.builder().name(histogram.getName()).labels(ImmutableMap.<String, String>builder().putAll(baseLabel).put("le", parseHistogramBucket(v)).build()).value(v.getCount()).build()).collect(Collectors.toList()));
break;
default:
return;
}
// Agent info
if (StringUtil.isNotEmpty(data.getService())) {
service = data.getService();
}
if (StringUtil.isNotEmpty(data.getServiceInstance())) {
serviceInstance = data.getServiceInstance();
}
if (data.getTimestamp() > 0) {
timestamp = data.getTimestamp();
}
}
Aggregations