Java Code Examples for io.prometheus.client.Summary#Timer

The following examples show how to use io.prometheus.client.Summary#Timer . 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: FsImageUpdateHandler.java    From hadoop-hdfs-fsimage-exporter with Apache License 2.0 6 votes vote down vote up
void onFsImageChange(File fsImageFile) {
    try {
        lock.lock();

        // Load new fsimage ...
        FSImageLoader loader = loadFsImage(fsImageFile);

        // ... compute stats
        try (Summary.Timer timer = metricVisitDuration.startTimer()) {
            report = FsImageReporter.computeStatsReport(loader, config);
        }
        reportUpdated.signalAll(); // Notify any waits
    } catch (Exception e) {
        LOGGER.error("Can not load FSImage", e);
        report.error = true;
    } finally {
        lock.unlock();
    }
}
 
Example 2
Source File: FsImageUpdateHandler.java    From hadoop-hdfs-fsimage-exporter with Apache License 2.0 6 votes vote down vote up
private FSImageLoader loadFsImage(File fsImageFile) throws IOException {
    metricLoadSize.set(fsImageFile.length());

    try (RandomAccessFile raFile = new RandomAccessFile(fsImageFile, "r")) {
        long time = System.currentTimeMillis();
        try (Summary.Timer timer = metricLoadDuration.startTimer()) {
            final FSImageLoader loader = FSImageLoader.load(raFile);
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Loaded {} with {}MiB in {}ms", fsImageFile.getAbsoluteFile(),
                        String.format("%.1f", fsImageFile.length() / 1024.0 / 1024.0),
                        System.currentTimeMillis() - time);
            }
            return loader;
        }
    }
}
 
Example 3
Source File: PrometheusMetricsCollector.java    From elasticsearch-prometheus-exporter with Apache License 2.0 6 votes vote down vote up
public void updateMetrics(ClusterHealthResponse clusterHealthResponse, NodeStats nodeStats,
                          IndicesStatsResponse indicesStats, ClusterStatsData clusterStatsData) {
    Summary.Timer timer = catalog.startSummaryTimer("metrics_generate_time_seconds");

    updateClusterMetrics(clusterHealthResponse);
    updateNodeMetrics(nodeStats);
    updateIndicesMetrics(nodeStats.getIndices());
    if (isPrometheusIndices) {
        updatePerIndexMetrics(clusterHealthResponse, indicesStats);
    }
    updateTransportMetrics(nodeStats.getTransport());
    updateHTTPMetrics(nodeStats.getHttp());
    updateThreadPoolMetrics(nodeStats.getThreadPool());
    updateIngestMetrics(nodeStats.getIngestStats());
    updateCircuitBreakersMetrics(nodeStats.getBreaker());
    updateScriptMetrics(nodeStats.getScriptStats());
    updateProcessMetrics(nodeStats.getProcess());
    updateJVMMetrics(nodeStats.getJvm());
    updateOsMetrics(nodeStats.getOs());
    updateFsMetrics(nodeStats.getFs());
    if (isPrometheusClusterSettings) {
        updateESSettings(clusterStatsData);
    }

    timer.observeDuration();
}
 
Example 4
Source File: TupleStoreManager.java    From bboxdb with Apache License 2.0 6 votes vote down vote up
/**
 * Search for the most recent version of the tuple
 * @param key
 * @return The tuple or null
 * @throws StorageManagerException
 */
public List<Tuple> get(final String key) throws StorageManagerException {

	if(! serviceState.isInRunningState()) {
		throw new StorageManagerException("Storage manager is not ready: "
				+ tupleStoreName.getFullname() + " state: " + serviceState);
	}

	final Summary.Timer requestTimer = getRequestLatency.startTimer();

	final List<Tuple> tupleList = new ArrayList<>();

	try(final TupleStoreAquirer tupleStoreAquirer = new TupleStoreAquirer(this)) {
		for(final ReadOnlyTupleStore tupleStorage : tupleStoreAquirer.getTupleStores()) {
			final List<Tuple> resultTuples = tupleStorage.get(key);
			tupleList.addAll(resultTuples);
		}
	} finally {
		requestTimer.observeDuration();
	}

	final DuplicateResolver<Tuple> resolver = TupleDuplicateResolverFactory.build(tupleStoreConfiguration);
	resolver.removeDuplicates(tupleList);

	return tupleList;
}
 
Example 5
Source File: MethodTimer.java    From client_java with Apache License 2.0 6 votes vote down vote up
@Around("timeable()")
public Object timeMethod(ProceedingJoinPoint pjp) throws Throwable {
    String key = pjp.getSignature().toLongString();

    Summary summary;
    final Lock r = summaryLock.readLock();
    r.lock();
    try {
        summary = summaries.get(key);
    } finally {
        r.unlock();
    }

    if (summary == null) {
        summary = ensureSummary(pjp, key);
    }

    final Summary.Timer t = summary.startTimer();

    try {
        return pjp.proceed();
    } finally {
        t.observeDuration();
    }
}
 
Example 6
Source File: PrometheusMetric.java    From athenz with Apache License 2.0 5 votes vote down vote up
@Override
public void stopTiming(Object timerObj) {
    if (timerObj == null) {
        return;
    }
    Summary.Timer timer = (Summary.Timer) timerObj;
    timer.observeDuration();
}
 
Example 7
Source File: PrometheusMetricTest.java    From athenz with Apache License 2.0 5 votes vote down vote up
@Test
public void testStopTiming() {
    Summary.Timer timer = mock(Summary.Timer.class);
    PrometheusMetric metric = new PrometheusMetric(null, null, null, "", false, false);

    metric.stopTiming(timer);
    // assertions
    verify(timer, times(1)).observeDuration();

    // different signature
    metric.stopTiming(timer, "request_domain", "principal_domain");
    // assertions
    verify(timer, times(2)).observeDuration();
}
 
Example 8
Source File: RequestLatencySummaryMetricsTracker.java    From soul with Apache License 2.0 4 votes vote down vote up
@Override
public SummaryMetricsTrackerDelegate startTimer(final String... labelValues) {
    Summary.Timer timer = REQUEST_LATENCY.startTimer();
    return new PrometheusSummaryMetricsTrackerDelegate(timer);
}
 
Example 9
Source File: PrometheusMetricsCatalog.java    From elasticsearch-prometheus-exporter with Apache License 2.0 4 votes vote down vote up
public Summary.Timer startSummaryTimer(String metric, String... labelValues) {
    Summary summary = (Summary) metrics.get(metric);
    return summary.labels(getExtendedNodeLabelValues(labelValues)).startTimer();
}
 
Example 10
Source File: RequestLatencySummaryMetricsTracker.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Override
public SummaryMetricsTrackerDelegate startTimer(final String... labelValues) {
    Summary.Timer timer = REQUEST_LATENCY.startTimer();
    return new PrometheusSummaryMetricsTrackerDelegate(timer);
}