org.apache.flink.runtime.rest.messages.job.metrics.MetricsAggregationParameter Java Examples
The following examples show how to use
org.apache.flink.runtime.rest.messages.job.metrics.MetricsAggregationParameter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAggregatingMetricsHandler.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override protected CompletableFuture<AggregatedMetricsResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, P> request, @Nonnull RestfulGateway gateway) throws RestHandlerException { return CompletableFuture.supplyAsync( () -> { try { fetcher.update(); List<String> requestedMetrics = request.getQueryParameter(MetricsFilterParameter.class); List<MetricsAggregationParameter.AggregationMode> requestedAggregations = request.getQueryParameter(MetricsAggregationParameter.class); MetricStore store = fetcher.getMetricStore(); Collection<? extends MetricStore.ComponentMetricStore> stores = getStores(store, request); if (requestedMetrics.isEmpty()) { Collection<String> list = getAvailableMetrics(stores); return new AggregatedMetricsResponseBody( list.stream() .map(AggregatedMetric::new) .collect(Collectors.toList()) ); } DoubleAccumulator.DoubleMinimumFactory minimumFactory = null; DoubleAccumulator.DoubleMaximumFactory maximumFactory = null; DoubleAccumulator.DoubleAverageFactory averageFactory = null; DoubleAccumulator.DoubleSumFactory sumFactory = null; // by default we return all aggregations if (requestedAggregations.isEmpty()) { minimumFactory = DoubleAccumulator.DoubleMinimumFactory.get(); maximumFactory = DoubleAccumulator.DoubleMaximumFactory.get(); averageFactory = DoubleAccumulator.DoubleAverageFactory.get(); sumFactory = DoubleAccumulator.DoubleSumFactory.get(); } else { for (MetricsAggregationParameter.AggregationMode aggregation : requestedAggregations) { switch (aggregation) { case MIN: minimumFactory = DoubleAccumulator.DoubleMinimumFactory.get(); break; case MAX: maximumFactory = DoubleAccumulator.DoubleMaximumFactory.get(); break; case AVG: averageFactory = DoubleAccumulator.DoubleAverageFactory.get(); break; case SUM: sumFactory = DoubleAccumulator.DoubleSumFactory.get(); break; default: log.warn("Unsupported aggregation specified: {}", aggregation); } } } MetricAccumulatorFactory metricAccumulatorFactory = new MetricAccumulatorFactory(minimumFactory, maximumFactory, averageFactory, sumFactory); return getAggregatedMetricValues(stores, requestedMetrics, metricAccumulatorFactory); } catch (Exception e) { log.warn("Could not retrieve metrics.", e); throw new CompletionException(new RestHandlerException("Could not retrieve metrics.", HttpResponseStatus.INTERNAL_SERVER_ERROR)); } }, executor); }
Example #2
Source File: AbstractAggregatingMetricsHandler.java From flink with Apache License 2.0 | 4 votes |
@Override protected CompletableFuture<AggregatedMetricsResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, P> request, @Nonnull RestfulGateway gateway) throws RestHandlerException { return CompletableFuture.supplyAsync( () -> { try { fetcher.update(); List<String> requestedMetrics = request.getQueryParameter(MetricsFilterParameter.class); List<MetricsAggregationParameter.AggregationMode> requestedAggregations = request.getQueryParameter(MetricsAggregationParameter.class); MetricStore store = fetcher.getMetricStore(); Collection<? extends MetricStore.ComponentMetricStore> stores = getStores(store, request); if (requestedMetrics.isEmpty()) { Collection<String> list = getAvailableMetrics(stores); return new AggregatedMetricsResponseBody( list.stream() .map(AggregatedMetric::new) .collect(Collectors.toList()) ); } DoubleAccumulator.DoubleMinimumFactory minimumFactory = null; DoubleAccumulator.DoubleMaximumFactory maximumFactory = null; DoubleAccumulator.DoubleAverageFactory averageFactory = null; DoubleAccumulator.DoubleSumFactory sumFactory = null; // by default we return all aggregations if (requestedAggregations.isEmpty()) { minimumFactory = DoubleAccumulator.DoubleMinimumFactory.get(); maximumFactory = DoubleAccumulator.DoubleMaximumFactory.get(); averageFactory = DoubleAccumulator.DoubleAverageFactory.get(); sumFactory = DoubleAccumulator.DoubleSumFactory.get(); } else { for (MetricsAggregationParameter.AggregationMode aggregation : requestedAggregations) { switch (aggregation) { case MIN: minimumFactory = DoubleAccumulator.DoubleMinimumFactory.get(); break; case MAX: maximumFactory = DoubleAccumulator.DoubleMaximumFactory.get(); break; case AVG: averageFactory = DoubleAccumulator.DoubleAverageFactory.get(); break; case SUM: sumFactory = DoubleAccumulator.DoubleSumFactory.get(); break; default: log.warn("Unsupported aggregation specified: {}", aggregation); } } } MetricAccumulatorFactory metricAccumulatorFactory = new MetricAccumulatorFactory(minimumFactory, maximumFactory, averageFactory, sumFactory); return getAggregatedMetricValues(stores, requestedMetrics, metricAccumulatorFactory); } catch (Exception e) { log.warn("Could not retrieve metrics.", e); throw new CompletionException(new RestHandlerException("Could not retrieve metrics.", HttpResponseStatus.INTERNAL_SERVER_ERROR)); } }, executor); }
Example #3
Source File: AbstractAggregatingMetricsHandler.java From flink with Apache License 2.0 | 4 votes |
@Override protected CompletableFuture<AggregatedMetricsResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, P> request, @Nonnull RestfulGateway gateway) throws RestHandlerException { return CompletableFuture.supplyAsync( () -> { try { fetcher.update(); List<String> requestedMetrics = request.getQueryParameter(MetricsFilterParameter.class); List<MetricsAggregationParameter.AggregationMode> requestedAggregations = request.getQueryParameter(MetricsAggregationParameter.class); MetricStore store = fetcher.getMetricStore(); Collection<? extends MetricStore.ComponentMetricStore> stores = getStores(store, request); if (requestedMetrics.isEmpty()) { Collection<String> list = getAvailableMetrics(stores); return new AggregatedMetricsResponseBody( list.stream() .map(AggregatedMetric::new) .collect(Collectors.toList()) ); } DoubleAccumulator.DoubleMinimumFactory minimumFactory = null; DoubleAccumulator.DoubleMaximumFactory maximumFactory = null; DoubleAccumulator.DoubleAverageFactory averageFactory = null; DoubleAccumulator.DoubleSumFactory sumFactory = null; // by default we return all aggregations if (requestedAggregations.isEmpty()) { minimumFactory = DoubleAccumulator.DoubleMinimumFactory.get(); maximumFactory = DoubleAccumulator.DoubleMaximumFactory.get(); averageFactory = DoubleAccumulator.DoubleAverageFactory.get(); sumFactory = DoubleAccumulator.DoubleSumFactory.get(); } else { for (MetricsAggregationParameter.AggregationMode aggregation : requestedAggregations) { switch (aggregation) { case MIN: minimumFactory = DoubleAccumulator.DoubleMinimumFactory.get(); break; case MAX: maximumFactory = DoubleAccumulator.DoubleMaximumFactory.get(); break; case AVG: averageFactory = DoubleAccumulator.DoubleAverageFactory.get(); break; case SUM: sumFactory = DoubleAccumulator.DoubleSumFactory.get(); break; default: log.warn("Unsupported aggregation specified: {}", aggregation); } } } MetricAccumulatorFactory metricAccumulatorFactory = new MetricAccumulatorFactory(minimumFactory, maximumFactory, averageFactory, sumFactory); return getAggregatedMetricValues(stores, requestedMetrics, metricAccumulatorFactory); } catch (Exception e) { log.warn("Could not retrieve metrics.", e); throw new CompletionException(new RestHandlerException("Could not retrieve metrics.", HttpResponseStatus.INTERNAL_SERVER_ERROR)); } }, executor); }