Search in sources :

Example 1 with MetricsFetcher

use of org.cloudfoundry.promregator.fetcher.MetricsFetcher 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 2 with MetricsFetcher

use of org.cloudfoundry.promregator.fetcher.MetricsFetcher in project promregator by promregator.

the class AbstractMetricsEndpoint method createMetricsFetchers.

protected List<MetricsFetcher> createMetricsFetchers(List<Instance> instanceList) {
    List<MetricsFetcher> callablesList = new LinkedList<>();
    for (Instance instance : instanceList) {
        log.info(String.format("Instance %s", instance.getInstanceId()));
        Target target = instance.getTarget();
        String orgName = target.getOrgName();
        String spaceName = target.getSpaceName();
        String appName = target.getApplicationName();
        String accessURL = instance.getAccessUrl();
        if (accessURL == null) {
            log.warn(String.format("Unable to retrieve hostname for %s/%s/%s; skipping", orgName, spaceName, appName));
            continue;
        }
        AbstractMetricFamilySamplesEnricher mfse = new CFMetricFamilySamplesEnricher(orgName, spaceName, appName, instance.getInstanceId());
        MetricsFetcherMetrics mfm = new MetricsFetcherMetrics(mfse, up);
        MetricsFetcher mf = null;
        if (this.proxyHost != null && this.proxyPort != 0) {
            mf = new CFMetricsFetcher(accessURL, instance.getInstanceId(), this.ae, mfse, this.proxyHost, this.proxyPort, mfm);
        } else {
            mf = new CFMetricsFetcher(accessURL, instance.getInstanceId(), this.ae, mfse, mfm);
        }
        callablesList.add(mf);
    }
    return callablesList;
}
Also used : MetricsFetcherMetrics(org.cloudfoundry.promregator.fetcher.MetricsFetcherMetrics) CFMetricFamilySamplesEnricher(org.cloudfoundry.promregator.rewrite.CFMetricFamilySamplesEnricher) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher) Target(org.cloudfoundry.promregator.config.Target) Instance(org.cloudfoundry.promregator.scanner.Instance) AbstractMetricFamilySamplesEnricher(org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher) MetricsFetcher(org.cloudfoundry.promregator.fetcher.MetricsFetcher) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher) LinkedList(java.util.LinkedList)

Example 3 with MetricsFetcher

use of org.cloudfoundry.promregator.fetcher.MetricsFetcher in project promregator by promregator.

the class TestableMetricsEndpoint method createMetricsFetchers.

@Override
protected List<MetricsFetcher> createMetricsFetchers(List<Instance> instanceList) {
    List<MetricsFetcher> list = new LinkedList<>();
    for (Instance instance : instanceList) {
        MockedMetricsFetcher mf = new MockedMetricsFetcher(instance);
        list.add(mf);
    }
    return list;
}
Also used : Instance(org.cloudfoundry.promregator.scanner.Instance) MetricsFetcher(org.cloudfoundry.promregator.fetcher.MetricsFetcher) LinkedList(java.util.LinkedList)

Example 4 with MetricsFetcher

use of org.cloudfoundry.promregator.fetcher.MetricsFetcher in project promregator by promregator.

the class AbstractMetricsEndpoint method startMetricsFetchers.

private LinkedList<Future<HashMap<String, MetricFamilySamples>>> startMetricsFetchers(List<MetricsFetcher> callablesPrep) {
    LinkedList<Future<HashMap<String, MetricFamilySamples>>> futures = new LinkedList<>();
    for (MetricsFetcher mf : callablesPrep) {
        Future<HashMap<String, MetricFamilySamples>> future = this.metricsFetcherPool.submit(mf);
        futures.add(future);
    }
    return futures;
}
Also used : HashMap(java.util.HashMap) Future(java.util.concurrent.Future) MergableMetricFamilySamples(org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricsFetcher(org.cloudfoundry.promregator.fetcher.MetricsFetcher) CFMetricsFetcher(org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)

Aggregations

MetricsFetcher (org.cloudfoundry.promregator.fetcher.MetricsFetcher)4 LinkedList (java.util.LinkedList)3 CFMetricsFetcher (org.cloudfoundry.promregator.fetcher.CFMetricsFetcher)3 Instance (org.cloudfoundry.promregator.scanner.Instance)3 MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)2 Future (java.util.concurrent.Future)2 MergableMetricFamilySamples (org.cloudfoundry.promregator.rewrite.MergableMetricFamilySamples)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 Target (org.cloudfoundry.promregator.config.Target)1 MetricsFetcherMetrics (org.cloudfoundry.promregator.fetcher.MetricsFetcherMetrics)1 AbstractMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher)1 CFMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.CFMetricFamilySamplesEnricher)1