Search in sources :

Example 1 with DistributionResult

use of org.apache.beam.sdk.metrics.DistributionResult in project flink by apache.

the class FlinkMetricContainerTest method testDistributionMonitoringInfoUpdate.

@Test
public void testDistributionMonitoringInfoUpdate() {
    MonitoringInfo userMonitoringInfo = new SimpleMonitoringInfoBuilder().setUrn(MonitoringInfoConstants.Urns.USER_DISTRIBUTION_INT64).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, DEFAULT_NAMESPACE).setLabel(MonitoringInfoConstants.Labels.NAME, "myDistribution").setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "anyPTransform").setInt64DistributionValue(DistributionData.create(30, 10, 1, 5)).build();
    container.updateMetrics("step", ImmutableList.of(userMonitoringInfo));
    // The one Flink distribution that gets created is a FlinkDistributionGauge; here we verify
    // its initial (and in this test, final) value
    verify(metricGroup).gauge(eq("myDistribution"), argThat((ArgumentMatcher<FlinkMetricContainer.FlinkDistributionGauge>) argument -> {
        DistributionResult actual = argument.getValue();
        DistributionResult expected = DistributionResult.create(30, 10, 1, 5);
        return actual.equals(expected);
    }));
}
Also used : DistributionResult(org.apache.beam.sdk.metrics.DistributionResult) MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) SimpleMonitoringInfoBuilder(org.apache.beam.runners.core.metrics.SimpleMonitoringInfoBuilder) ArgumentMatcher(org.mockito.ArgumentMatcher) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) Test(org.junit.Test)

Example 2 with DistributionResult

use of org.apache.beam.sdk.metrics.DistributionResult in project beam by apache.

the class SparkBeamMetric method renderAll.

Map<String, ?> renderAll() {
    Map<String, Object> metrics = new HashMap<>();
    MetricResults metricResults = asAttemptedOnlyMetricResults(MetricsAccumulator.getInstance().value());
    MetricQueryResults metricQueryResults = metricResults.allMetrics();
    for (MetricResult<Long> metricResult : metricQueryResults.getCounters()) {
        metrics.put(renderName(metricResult), metricResult.getAttempted());
    }
    for (MetricResult<DistributionResult> metricResult : metricQueryResults.getDistributions()) {
        DistributionResult result = metricResult.getAttempted();
        metrics.put(renderName(metricResult) + ".count", result.getCount());
        metrics.put(renderName(metricResult) + ".sum", result.getSum());
        metrics.put(renderName(metricResult) + ".min", result.getMin());
        metrics.put(renderName(metricResult) + ".max", result.getMax());
        metrics.put(renderName(metricResult) + ".mean", result.getMean());
    }
    for (MetricResult<GaugeResult> metricResult : metricQueryResults.getGauges()) {
        metrics.put(renderName(metricResult), metricResult.getAttempted().getValue());
    }
    return metrics;
}
Also used : DistributionResult(org.apache.beam.sdk.metrics.DistributionResult) HashMap(java.util.HashMap) MetricsContainerStepMap.asAttemptedOnlyMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults) MetricResults(org.apache.beam.sdk.metrics.MetricResults) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) GaugeResult(org.apache.beam.sdk.metrics.GaugeResult)

Example 3 with DistributionResult

use of org.apache.beam.sdk.metrics.DistributionResult in project beam by apache.

the class SparkBeamMetric method renderAll.

static Map<String, ?> renderAll(MetricResults metricResults) {
    Map<String, Object> metrics = new HashMap<>();
    MetricQueryResults metricQueryResults = metricResults.allMetrics();
    for (MetricResult<Long> metricResult : metricQueryResults.getCounters()) {
        metrics.put(renderName(metricResult), metricResult.getAttempted());
    }
    for (MetricResult<DistributionResult> metricResult : metricQueryResults.getDistributions()) {
        DistributionResult result = metricResult.getAttempted();
        metrics.put(renderName(metricResult) + ".count", result.getCount());
        metrics.put(renderName(metricResult) + ".sum", result.getSum());
        metrics.put(renderName(metricResult) + ".min", result.getMin());
        metrics.put(renderName(metricResult) + ".max", result.getMax());
        metrics.put(renderName(metricResult) + ".mean", result.getMean());
    }
    for (MetricResult<GaugeResult> metricResult : metricQueryResults.getGauges()) {
        metrics.put(renderName(metricResult), metricResult.getAttempted().getValue());
    }
    return metrics;
}
Also used : DistributionResult(org.apache.beam.sdk.metrics.DistributionResult) HashMap(java.util.HashMap) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) GaugeResult(org.apache.beam.sdk.metrics.GaugeResult)

Example 4 with DistributionResult

use of org.apache.beam.sdk.metrics.DistributionResult in project beam by apache.

the class MetricsGraphiteSink method writeMetrics.

@Override
public void writeMetrics(MetricQueryResults metricQueryResults) throws Exception {
    final long metricTimestamp = System.currentTimeMillis() / 1000L;
    Socket socket = new Socket(InetAddress.getByName(address), port);
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset));
    StringBuilder messagePayload = new StringBuilder();
    Iterable<MetricResult<Long>> counters = metricQueryResults.getCounters();
    Iterable<MetricResult<GaugeResult>> gauges = metricQueryResults.getGauges();
    Iterable<MetricResult<DistributionResult>> distributions = metricQueryResults.getDistributions();
    for (MetricResult<Long> counter : counters) {
        messagePayload.append(new CounterMetricMessage(counter, "value", metricTimestamp).toString());
    }
    for (MetricResult<GaugeResult> gauge : gauges) {
        messagePayload.append(new GaugeMetricMessage(gauge, "value").toString());
    }
    for (MetricResult<DistributionResult> distribution : distributions) {
        messagePayload.append(new DistributionMetricMessage(distribution, "min", metricTimestamp).toString());
        messagePayload.append(new DistributionMetricMessage(distribution, "max", metricTimestamp).toString());
        messagePayload.append(new DistributionMetricMessage(distribution, "count", metricTimestamp).toString());
        messagePayload.append(new DistributionMetricMessage(distribution, "sum", metricTimestamp).toString());
        messagePayload.append(new DistributionMetricMessage(distribution, "mean", metricTimestamp).toString());
    }
    writer.write(messagePayload.toString());
    writer.flush();
    writer.close();
    socket.close();
}
Also used : DistributionResult(org.apache.beam.sdk.metrics.DistributionResult) MetricResult(org.apache.beam.sdk.metrics.MetricResult) BufferedWriter(java.io.BufferedWriter) OutputStreamWriter(java.io.OutputStreamWriter) Socket(java.net.Socket) GaugeResult(org.apache.beam.sdk.metrics.GaugeResult)

Example 5 with DistributionResult

use of org.apache.beam.sdk.metrics.DistributionResult in project beam by apache.

the class PortableMetrics method convertDistributionMonitoringInfoToDistribution.

private static MetricResult<DistributionResult> convertDistributionMonitoringInfoToDistribution(MetricsApi.MonitoringInfo monitoringInfo) {
    Map<String, String> labelsMap = monitoringInfo.getLabelsMap();
    MetricKey key = MetricKey.create(labelsMap.get(STEP_NAME_LABEL), MetricName.named(labelsMap.get(NAMESPACE_LABEL), labelsMap.get(METRIC_NAME_LABEL)));
    DistributionData data = decodeInt64Distribution(monitoringInfo.getPayload());
    DistributionResult result = DistributionResult.create(data.sum(), data.count(), data.min(), data.max());
    return MetricResult.create(key, false, result);
}
Also used : MetricKey(org.apache.beam.sdk.metrics.MetricKey) DistributionResult(org.apache.beam.sdk.metrics.DistributionResult) DistributionData(org.apache.beam.runners.core.metrics.DistributionData)

Aggregations

DistributionResult (org.apache.beam.sdk.metrics.DistributionResult)9 GaugeResult (org.apache.beam.sdk.metrics.GaugeResult)4 HashMap (java.util.HashMap)3 MetricQueryResults (org.apache.beam.sdk.metrics.MetricQueryResults)3 MonitoringInfo (org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo)2 DistributionData (org.apache.beam.runners.core.metrics.DistributionData)2 MetricsContainerStepMap.asAttemptedOnlyMetricResults (org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults)2 SimpleMonitoringInfoBuilder (org.apache.beam.runners.core.metrics.SimpleMonitoringInfoBuilder)2 MetricResults (org.apache.beam.sdk.metrics.MetricResults)2 Test (org.junit.Test)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Socket (java.net.Socket)1 CounterCell (org.apache.beam.runners.core.metrics.CounterCell)1 DistributionCell (org.apache.beam.runners.core.metrics.DistributionCell)1 MetricsContainerImpl (org.apache.beam.runners.core.metrics.MetricsContainerImpl)1 FlinkDistributionGauge (org.apache.beam.runners.flink.metrics.FlinkMetricContainer.FlinkDistributionGauge)1 MetricKey (org.apache.beam.sdk.metrics.MetricKey)1 MetricResult (org.apache.beam.sdk.metrics.MetricResult)1