use of org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples in project promregator by promregator.
the class AbstractMetricsEndpoint method waitForMetricsFetchers.
private MergableMetricFamilySamples waitForMetricsFetchers(LinkedList<Future<HashMap<String, MetricFamilySamples>>> futures) {
long starttime = System.currentTimeMillis();
MergableMetricFamilySamples mmfs = new MergableMetricFamilySamples();
for (Future<HashMap<String, MetricFamilySamples>> future : futures) {
long maxWaitTime = starttime + this.maxProcessingTime - System.currentTimeMillis();
try {
if (maxWaitTime < 0 && !future.isDone()) {
// only process those, which are already completed
continue;
}
HashMap<String, MetricFamilySamples> emfs = future.get(maxWaitTime, TimeUnit.MILLISECONDS);
if (emfs != null) {
mmfs.merge(emfs);
}
} catch (InterruptedException e) {
continue;
} catch (ExecutionException e) {
log.warn("Exception thrown while fetching Metrics data from target", e);
continue;
} catch (TimeoutException e) {
log.info("Timeout while fetching metrics data from target", e);
// process the other's as well!
continue;
}
}
return mmfs;
}
use of org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples in project promregator by promregator.
the class AbstractMetricsEndpoint method handleRequest.
public String handleRequest() {
Instant start = Instant.now();
this.up.clear();
List<Instance> instanceList = this.appInstanceScanner.determineInstancesFromTargets(this.promregatorConfiguration.getTargets());
instanceList = this.filterInstanceList(instanceList);
List<MetricsFetcher> callablesPrep = this.createMetricsFetchers(instanceList);
LinkedList<Future<HashMap<String, MetricFamilySamples>>> futures = this.startMetricsFetchers(callablesPrep);
MergableMetricFamilySamples mmfs = waitForMetricsFetchers(futures);
Instant stop = Instant.now();
Duration duration = Duration.between(start, stop);
this.scrape_duration.set(duration.toMillis() / 1000.0);
if (this.isIncludeGlobalMetrics()) {
// also add our own (global) metrics
mmfs.merge(this.gmfspr.determineEnumerationOfMetricFamilySamples(this.collectorRegistry));
}
// add also our own request-specific metrics
mmfs.merge(this.gmfspr.determineEnumerationOfMetricFamilySamples(this.requestRegistry));
return mmfs.toType004String();
}
use of org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples in project promregator by promregator.
the class PromregatorMetricsEndpoint method getMetrics.
@RequestMapping(method = RequestMethod.GET, produces = TextFormat.CONTENT_TYPE_004)
public String getMetrics() {
HashMap<String, MetricFamilySamples> mfsMap = this.gmfspr.determineEnumerationOfMetricFamilySamples(this.collectorRegistry);
MergableMetricFamilySamples mmfs = new MergableMetricFamilySamples();
mmfs.merge(mfsMap);
return mmfs.toType004String();
}
Aggregations