Search in sources :

Example 1 with MergableMetricFamilySamples

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;
}
Also used : MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) HashMap(java.util.HashMap) MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with MergableMetricFamilySamples

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();
}
Also used : MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) Instance(org.cloudfoundry.promregator.scanner.Instance) Instant(java.time.Instant) Future(java.util.concurrent.Future) Duration(java.time.Duration) MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) MetricsFetcher(org.cloudfoundry.promregator.fetcher.MetricsFetcher) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)

Example 3 with MergableMetricFamilySamples

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();
}
Also used : MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)3 MergableMetricFamilySamples (org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples)3 Duration (java.time.Duration)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 CFMetricsFetcher (org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)1 MetricsFetcher (org.cloudfoundry.promregator.fetcher.MetricsFetcher)1 Instance (org.cloudfoundry.promregator.scanner.Instance)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1