use of org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram 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();
}
}
use of org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram in project incubator-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();
}
}
use of org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram in project skywalking-java by apache.
the class MeterServiceTest method isSameWithHistogram.
/**
* Check histogram message
*/
public void isSameWithHistogram(MeterData meterData, boolean firstData, MeterId meterId, Object... values) {
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.HISTOGRAM);
Assert.assertNotNull(meterData.getSingleValue());
final MeterHistogram histogram = meterData.getHistogram();
Assert.assertEquals(histogram.getName(), meterId.getName());
Assert.assertEquals(histogram.getLabelsList(), meterId.transformTags());
for (int i = 0; i < values.length; i += 2) {
final MeterBucketValue bucketValue = histogram.getValues(i);
Assert.assertNotNull(bucketValue);
Assert.assertEquals(bucketValue.getBucket(), (double) values[i], 0.0);
Assert.assertEquals(bucketValue.getCount(), values[i + 1]);
}
}
use of org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram in project skywalking-java by apache.
the class HistogramTest method verifyHistogram.
/**
* Check histogram message
*/
public static void verifyHistogram(String name, List<Label> labels, List<Double> buckets, List<Long> bucketValues, MeterData.Builder validate) {
Assert.assertNotNull(validate);
Assert.assertEquals(validate.getMetricCase().getNumber(), MeterData.HISTOGRAM_FIELD_NUMBER);
MeterHistogram histogram = validate.getHistogram();
Assert.assertNotNull(histogram);
Assert.assertEquals(histogram.getName(), name);
Assert.assertEquals(histogram.getLabelsList(), labels);
Assert.assertNotNull(histogram.getValuesList());
Assert.assertEquals(histogram.getValuesCount(), bucketValues.size());
for (int i = 0; i < bucketValues.size(); i++) {
Assert.assertNotNull(histogram.getValues(i));
Assert.assertEquals(histogram.getValues(i).getBucket(), buckets.get(i).doubleValue(), 0.0);
Assert.assertEquals(histogram.getValues(i).getCount(), bucketValues.get(i).longValue());
}
}
Aggregations