io.prometheus.client.Summary Java Examples

The following examples show how to use io.prometheus.client.Summary. 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
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 #2
Source File: TextFormatTest.java    From client_java with Apache License 2.0 6 votes vote down vote up
@Test
public void testSummaryOutputWithQuantiles() throws IOException {
  Summary labelsAndQuantiles = Summary.build()
          .quantile(0.5, 0.05).quantile(0.9, 0.01).quantile(0.99, 0.001)
          .labelNames("l").name("labelsAndQuantiles").help("help").register(registry);
  labelsAndQuantiles.labels("a").observe(2);
  writer = new StringWriter();
  TextFormat.write004(writer, registry.metricFamilySamples());
  assertEquals("# HELP labelsAndQuantiles help\n"
          + "# TYPE labelsAndQuantiles summary\n"
          + "labelsAndQuantiles{l=\"a\",quantile=\"0.5\",} 2.0\n"
          + "labelsAndQuantiles{l=\"a\",quantile=\"0.9\",} 2.0\n"
          + "labelsAndQuantiles{l=\"a\",quantile=\"0.99\",} 2.0\n"
          + "labelsAndQuantiles_count{l=\"a\",} 1.0\n"
          + "labelsAndQuantiles_sum{l=\"a\",} 2.0\n", writer.toString());
}
 
Example #3
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 #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: ContextImpl.java    From pulsar with Apache License 2.0 6 votes vote down vote up
public Map<String, Double> getMetrics() {
    Map<String, Double> metricsMap = new HashMap<>();
    for (Map.Entry<String, String[]> userMetricsLabelsEntry : userMetricsLabels.entrySet()) {
        String metricName = userMetricsLabelsEntry.getKey();
        String[] labels = userMetricsLabelsEntry.getValue();
        Summary.Child.Value summary = userMetricsSummary.labels(labels).get();
        metricsMap.put(String.format("%s%s_sum", USER_METRIC_PREFIX, metricName), summary.sum);
        metricsMap.put(String.format("%s%s_count", USER_METRIC_PREFIX, metricName), summary.count);
        for (Map.Entry<Double, Double> entry : summary.quantiles.entrySet()) {
            Double quantile = entry.getKey();
            Double value = entry.getValue();
            metricsMap.put(String.format("%s%s_%s", USER_METRIC_PREFIX, metricName, quantile), value);
        }
    }
    return metricsMap;
}
 
Example #6
Source File: DimensionStats.java    From pulsar with Apache License 2.0 6 votes vote down vote up
public DimensionStats(String name, long updateDurationInSec) {
    this.name = name;
    this.dimensionSumLabel = name + "_sum";
    this.dimensionCountLabel = name + "_count";
    Builder summaryBuilder = Summary.build().name(name).help("-");
    for (int i = 0; i < QUANTILES.length; i++) {
        summaryBuilder.quantile(QUANTILES[i], 0.01);
    }
    this.summary = summaryBuilder.maxAgeSeconds(updateDurationInSec).create();
    try {
        defaultRegistry.register(summary);
    } catch (IllegalArgumentException ie) {
        // it only happens in test-cases when try to register summary multiple times in registry
        log.warn("{} is already registred {}", name, ie.getMessage());
    }
}
 
Example #7
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 #8
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 #9
Source File: AggregatedTypeUpdater.java    From jmeter-prometheus-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void update(SampleEvent event) {
	try {
		Collector collector = registry.getOrCreateAndRegister(this.config);
		
		String[] labels = this.labelValues(event);
		long measurement = this.measure(event);
		
		if(collector instanceof Histogram) {
			Histogram hist = (Histogram) collector;
			hist.labels(labels).observe(measurement);
			
		}else if(collector instanceof Summary) {
			Summary sum = (Summary) collector;
			sum.labels(labels).observe(measurement);
		}
		
	} catch(Exception e) {
		log.error("Did not update {} because of error: {}", this.config.getMetricName(), e.getMessage());
		log.debug(e.getMessage(), e);
	}

}
 
Example #10
Source File: ServletHook.java    From promagent with Apache License 2.0 6 votes vote down vote up
public ServletHook(MetricsStore metricsStore) {

        httpRequestsTotal = metricsStore.createOrGet(new MetricDef<>(
                "http_requests_total",
                (name, registry) -> Counter.build()
                        .name(name)
                        .labelNames("method", "path", "status")
                        .help("Total number of http requests.")
                        .register(registry)
        ));

        httpRequestsDuration = metricsStore.createOrGet(new MetricDef<>(
                "http_request_duration",
                (name, registry) -> Summary.build()
                        .quantile(0.5, 0.05)   // Add 50th percentile (= median) with 5% tolerated error
                        .quantile(0.9, 0.01)   // Add 90th percentile with 1% tolerated error
                        .quantile(0.99, 0.001) // Add 99th percentile with 0.1% tolerated error
                        .name(name)
                        .labelNames("method", "path", "status")
                        .help("Duration for serving the http requests in seconds.")
                        .register(registry)
        ));
    }
 
Example #11
Source File: JdbcHook.java    From promagent with Apache License 2.0 6 votes vote down vote up
public JdbcHook(MetricsStore metricsStore) {

        sqlQueriesTotal = metricsStore.createOrGet(new MetricDef<>(
                "sql_queries_total",
                (name, registry) -> Counter.build()
                        .name(name)
                        .labelNames("method", "path", "query")
                        .help("Total number of sql queries.")
                        .register(registry)
        ));

        sqlQueriesDuration = metricsStore.createOrGet(new MetricDef<>(
                "sql_query_duration",
                (name, registry) -> Summary.build()
                        .quantile(0.5, 0.05)   // Add 50th percentile (= median) with 5% tolerated error
                        .quantile(0.9, 0.01)   // Add 90th percentile with 1% tolerated error
                        .quantile(0.99, 0.001) // Add 99th percentile with 0.1% tolerated error
                        .name(name)
                        .labelNames("method", "path", "query")
                        .help("Duration for serving the sql queries in seconds.")
                        .register(registry)
        ));
    }
 
Example #12
Source File: TextFormatTest.java    From client_java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSummaryOutput() throws IOException {
  Summary noLabels = Summary.build().name("nolabels").help("help").register(registry);
  noLabels.observe(2);
  TextFormat.write004(writer, registry.metricFamilySamples());
  assertEquals("# HELP nolabels help\n"
               + "# TYPE nolabels summary\n"
               + "nolabels_count 1.0\n"
               + "nolabels_sum 2.0\n", writer.toString());
}
 
Example #13
Source File: PrometheusMetricsSystem.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public LabelledMetric<OperationTimer> createLabelledTimer(
    final MetricCategory category,
    final String name,
    final String help,
    final String... labelNames) {
  final String metricName = convertToPrometheusName(category, name);
  return cachedTimers.computeIfAbsent(
      metricName,
      (k) -> {
        if (timersEnabled && isCategoryEnabled(category)) {
          final Summary summary =
              Summary.build(metricName, help)
                  .quantile(0.2, 0.02)
                  .quantile(0.5, 0.05)
                  .quantile(0.8, 0.02)
                  .quantile(0.95, 0.005)
                  .quantile(0.99, 0.001)
                  .quantile(1.0, 0)
                  .labelNames(labelNames)
                  .create();
          addCollectorUnchecked(category, summary);
          return new PrometheusTimer(summary);
        } else {
          return NoOpMetricsSystem.getOperationTimerLabelledMetric(labelNames.length);
        }
      });
}
 
Example #14
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 #15
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 #16
Source File: PrometheusMetric.java    From athenz with Apache License 2.0 5 votes vote down vote up
@Override
public Object startTiming(String metricName, String requestDomainName, String principalDomainName) {
    // prometheus does not allow null labels
    requestDomainName = (this.isLabelRequestDomainNameEnable) ? Objects.toString(requestDomainName, "") : "";
    principalDomainName = (this.isLabelPrincipalDomainNameEnable) ? Objects.toString(principalDomainName, "") : "";

    metricName = this.normalizeTimerMetricName(metricName);
    Summary summary = (Summary) createOrGetCollector(metricName, Summary.build()
    // .quantile(0.5, 0.05)
    // .quantile(0.9, 0.01)
    );
    return summary.labels(requestDomainName, principalDomainName).startTimer();
}
 
Example #17
Source File: BigDecimalHandler.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private Summary initializeCounter(String dmnType, CollectorRegistry registry) {
    Summary.Builder builder = Summary.build() // Calculate quantiles over a sliding window of time - default = 10 minutes
            .quantile(0.1, 0.01)   // Add 10th percentile with 1% tolerated error
            .quantile(0.25, 0.05)
            .quantile(0.50, 0.05)   // Add 50th percentile (= median) with 5% tolerated error
            .quantile(0.75, 0.05)
            .quantile(0.9, 0.05)
            .quantile(0.99, 0.01)
            .name(dmnType + DecisionConstants.DECISIONS_NAME_SUFFIX)
            .help(DecisionConstants.DECISIONS_HELP)
            .labelNames(DecisionConstants.DECISION_ENDPOINT_LABELS);

    return registry == null ? builder.register(CollectorRegistry.defaultRegistry) : builder.register(registry);
}
 
Example #18
Source File: PrometheusMetricsCatalog.java    From elasticsearch-prometheus-exporter with Apache License 2.0 5 votes vote down vote up
public void registerSummaryTimer(String metric, String help, String... labels) {
    Summary summary = Summary.build().
            name(metricPrefix + metric).
            help(help).
            labelNames(getExtendedNodeLabelNames(labels)).
            register(registry);

    metrics.put(metric, summary);

    logger.debug(String.format(Locale.ENGLISH, "Registered new summary %s", metric));
}
 
Example #19
Source File: PrometheusExtractionTaskMonitor.java    From cineast with MIT License 5 votes vote down vote up
public static void init() {
  if (initalized) {
    LOGGER.info("Already initalized, Returning");
    return;
  }
  if (!Config.sharedConfig().getMonitoring().enablePrometheus) {
    LOGGER.warn("Prometheus not enabled, returning");
    return;
  }
  LOGGER.info("Initalizing Prometheus Extraction Task Monitor");
  extractionTime = Summary.build().name("cineast_feature_process_time")
      .help("Time for an ExtractionTask to process the Shot")
      .labelNames("Extractor").quantile(0.5, 0.05).quantile(0.9, 0.01).register();
}
 
Example #20
Source File: RetrievalTaskMonitor.java    From cineast with MIT License 5 votes vote down vote up
public static void init() {
  if (initalized) {
    LOGGER.info("Already initalized, Returning");
    return;
  }
  if (!Config.sharedConfig().getMonitoring().enablePrometheus) {
    LOGGER.warn("Prometheus not enabled, returning");
    return;
  }
  LOGGER.info("Initalizing Prometheus Retrieval Task Monitor");
  executionTime = Summary.build().name("cineast_retrievaltask")
      .help("Time for one query item")
      .labelNames("Retriever").quantile(0.5, 0.05).quantile(0.9, 0.01).register();
}
 
Example #21
Source File: ImportTaskMonitor.java    From cineast with MIT License 5 votes vote down vote up
public static void init() {
  if (initalized) {
    LOGGER.info("Already initalized, Returning");
    return;
  }
  if (!Config.sharedConfig().getMonitoring().enablePrometheus) {
    LOGGER.warn("Prometheus not enabled, returning");
    return;
  }
  LOGGER.info("Initalizing Prometheus Extraction Task Monitor");
  executionTime = Summary.build().name("cineast_importtask")
      .help("Time for import of 1 item")
      .labelNames("Taskname").quantile(0.5, 0.05).quantile(0.9, 0.01).register();
}
 
Example #22
Source File: PrometheusBistouryTimer.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
public PrometheusBistouryTimer(final Summary summary, final String[] labels) {
    this.summary = summary.labels(labels);
}
 
Example #23
Source File: PrometheusQmqMeter.java    From qmq with Apache License 2.0 4 votes vote down vote up
public PrometheusQmqMeter(final Summary summary, final String[] labels) {
    this.summary = summary.labels(labels);
}
 
Example #24
Source File: PrometheusTimer.java    From besu with Apache License 2.0 4 votes vote down vote up
public PrometheusTimer(final Summary summary) {
  this.summary = summary;
}
 
Example #25
Source File: ContextImpl.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public ContextImpl(InstanceConfig config, Logger logger, PulsarClient client,
                   SecretsProvider secretsProvider, CollectorRegistry collectorRegistry, String[] metricsLabels,
                   Function.FunctionDetails.ComponentType componentType, ComponentStatsManager statsManager,
                   Table<ByteBuf, ByteBuf> stateTable) {
    this.config = config;
    this.logger = logger;
    this.client = client;
    this.publishProducers = new HashMap<>();
    this.topicSchema = new TopicSchema(client);
    this.statsManager = statsManager;

    this.producerBuilder = (ProducerBuilderImpl<?>) client.newProducer().blockIfQueueFull(true).enableBatching(true)
            .batchingMaxPublishDelay(1, TimeUnit.MILLISECONDS);

    if (config.getFunctionDetails().getUserConfig().isEmpty()) {
        userConfigs = new HashMap<>();
    } else {
        userConfigs = new Gson().fromJson(config.getFunctionDetails().getUserConfig(),
                new TypeToken<Map<String, Object>>() {
                }.getType());
    }
    this.secretsProvider = secretsProvider;
    if (!StringUtils.isEmpty(config.getFunctionDetails().getSecretsMap())) {
        secretsMap = new Gson().fromJson(config.getFunctionDetails().getSecretsMap(),
                new TypeToken<Map<String, Object>>() {
                }.getType());
    } else {
        secretsMap = new HashMap<>();
    }

    this.metricsLabels = metricsLabels;
    String prefix;
    switch (componentType) {
        case FUNCTION:
            prefix = FunctionStatsManager.PULSAR_FUNCTION_METRICS_PREFIX;
            break;
        case SINK:
            prefix = SinkStatsManager.PULSAR_SINK_METRICS_PREFIX;
            break;
        case SOURCE:
            prefix = SourceStatsManager.PULSAR_SOURCE_METRICS_PREFIX;
            break;
        default:
            throw new RuntimeException("Unknown component type: " + componentType);
    }
    this.userMetricsSummary = Summary.build()
            .name(prefix + ComponentStatsManager.USER_METRIC_PREFIX)
            .help("User defined metric.")
            .labelNames(userMetricsLabelNames)
            .quantile(0.5, 0.01)
            .quantile(0.9, 0.01)
            .quantile(0.99, 0.01)
            .quantile(0.999, 0.01)
            .register(collectorRegistry);
    this.componentType = componentType;

    if (null != stateTable) {
        this.stateContext = new StateContextImpl(stateTable);
    }
}
 
Example #26
Source File: PrometheusQConfigMeter.java    From qconfig with MIT License 4 votes vote down vote up
public PrometheusQConfigMeter(final Summary summary, final String[] labels) {
    this.summary = summary.labels(labels);
}
 
Example #27
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);
}
 
Example #28
Source File: PrometheusQConfigTimer.java    From qconfig with MIT License 4 votes vote down vote up
public PrometheusQConfigTimer(final Summary summary, final String[] labels) {
    this.summary = summary.labels(labels);
}
 
Example #29
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 #30
Source File: PrometheusHandler.java    From light-4j with Apache License 2.0 4 votes vote down vote up
private Summary summary(String name, List<String> labels) {
    String key = sanitizeName(name);
    return response_times.computeIfAbsent(key, k-> Summary.build().name(k).help(k).labelNames(labels.stream().toArray(String[]::new)).register(registry));
}