Search in sources :

Example 1 with MeterHistogram

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();
    }
}
Also used : SampleFamilyBuilder(org.apache.skywalking.oap.meter.analyzer.dsl.SampleFamilyBuilder) MeterSingleValue(org.apache.skywalking.apm.network.language.agent.v3.MeterSingleValue) Label(org.apache.skywalking.apm.network.language.agent.v3.Label) CollectionUtils(org.apache.skywalking.oap.server.library.util.CollectionUtils) ImmutableMap(com.google.common.collect.ImmutableMap) MeterBucketValue(org.apache.skywalking.apm.network.language.agent.v3.MeterBucketValue) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) HistogramType(org.apache.skywalking.oap.meter.analyzer.dsl.HistogramType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) MeterHistogram(org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram) MetricConvert(org.apache.skywalking.oap.meter.analyzer.MetricConvert) MeterData(org.apache.skywalking.apm.network.language.agent.v3.MeterData) Sample(org.apache.skywalking.oap.meter.analyzer.dsl.Sample) Map(java.util.Map) StringUtil(org.apache.skywalking.oap.server.library.util.StringUtil) MeterHistogram(org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram) MeterSingleValue(org.apache.skywalking.apm.network.language.agent.v3.MeterSingleValue) ArrayList(java.util.ArrayList)

Example 2 with MeterHistogram

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();
    }
}
Also used : SampleFamilyBuilder(org.apache.skywalking.oap.meter.analyzer.dsl.SampleFamilyBuilder) MeterSingleValue(org.apache.skywalking.apm.network.language.agent.v3.MeterSingleValue) Label(org.apache.skywalking.apm.network.language.agent.v3.Label) CollectionUtils(org.apache.skywalking.oap.server.library.util.CollectionUtils) ImmutableMap(com.google.common.collect.ImmutableMap) MeterBucketValue(org.apache.skywalking.apm.network.language.agent.v3.MeterBucketValue) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) HistogramType(org.apache.skywalking.oap.meter.analyzer.dsl.HistogramType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) MeterHistogram(org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram) MetricConvert(org.apache.skywalking.oap.meter.analyzer.MetricConvert) MeterData(org.apache.skywalking.apm.network.language.agent.v3.MeterData) Sample(org.apache.skywalking.oap.meter.analyzer.dsl.Sample) Map(java.util.Map) StringUtil(org.apache.skywalking.oap.server.library.util.StringUtil) MeterHistogram(org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram) MeterSingleValue(org.apache.skywalking.apm.network.language.agent.v3.MeterSingleValue) ArrayList(java.util.ArrayList)

Example 3 with MeterHistogram

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]);
    }
}
Also used : MeterHistogram(org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram) MeterBucketValue(org.apache.skywalking.apm.network.language.agent.v3.MeterBucketValue)

Example 4 with MeterHistogram

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());
    }
}
Also used : MeterHistogram(org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram)

Aggregations

MeterHistogram (org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram)4 MeterBucketValue (org.apache.skywalking.apm.network.language.agent.v3.MeterBucketValue)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Label (org.apache.skywalking.apm.network.language.agent.v3.Label)2 MeterData (org.apache.skywalking.apm.network.language.agent.v3.MeterData)2 MeterSingleValue (org.apache.skywalking.apm.network.language.agent.v3.MeterSingleValue)2 MetricConvert (org.apache.skywalking.oap.meter.analyzer.MetricConvert)2 HistogramType (org.apache.skywalking.oap.meter.analyzer.dsl.HistogramType)2 Sample (org.apache.skywalking.oap.meter.analyzer.dsl.Sample)2 SampleFamilyBuilder (org.apache.skywalking.oap.meter.analyzer.dsl.SampleFamilyBuilder)2 CollectionUtils (org.apache.skywalking.oap.server.library.util.CollectionUtils)2