io.prometheus.client.Counter Java Examples

The following examples show how to use io.prometheus.client.Counter. 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: SuccessRatioCollector.java    From jmeter-prometheus-plugin with Apache License 2.0 8 votes vote down vote up
public SuccessRatioCollector(BaseCollectorConfig config) {
	this.success = new Counter.Builder()
			.help(config.getHelp())
			.name(extendedName(config.getMetricName(), "success"))
			.labelNames(config.getLabels())
			.create();
	
	this.failure = new Counter.Builder()
			.help(config.getHelp())
			.name(extendedName(config.getMetricName(), "failure"))
			.labelNames(config.getLabels())
			.create();
	
	this.total = new Counter.Builder()
			.help(config.getHelp())
			.name(extendedName(config.getMetricName(), "total"))
			.labelNames(config.getLabels())
			.create();
	
}
 
Example #2
Source File: PrometheusReporter.java    From micro-integrator with Apache License 2.0 7 votes vote down vote up
@Override
public void initErrorMetrics(String serviceType, String type, String metricName, String metricHelp,
        String[] properties) {

    String[] labels = properties;

    if (serviceType.equals(SERVICE.PROXY.name())) {
        ERROR_REQUESTS_RECEIVED_PROXY_SERVICE = Counter.build(MetricConstants.PROXY_REQUEST_COUNT_ERROR_TOTAL,
                metricHelp).
                labelNames(labels).register();
        metricMap.put(metricName, ERROR_REQUESTS_RECEIVED_PROXY_SERVICE);
    } else if (serviceType.equals(SERVICE.API.name())) {
        ERROR_REQUESTS_RECEIVED_API = Counter.build(MetricConstants.API_REQUEST_COUNT_ERROR_TOTAL, metricHelp).
                labelNames(labels).register();
        metricMap.put(metricName, ERROR_REQUESTS_RECEIVED_API);
    } else if (serviceType.equals(SERVICE.INBOUND_ENDPOINT.name())) {
        ERROR_REQUESTS_RECEIVED_INBOUND_ENDPOINT = Counter.
                build(MetricConstants.INBOUND_ENDPOINT_REQUEST_COUNT_ERROR_TOTAL, metricHelp).labelNames(labels).
                register();
        metricMap.put(metricName, ERROR_REQUESTS_RECEIVED_INBOUND_ENDPOINT);

    }
}
 
Example #3
Source File: PrometheusMetricsSystem.java    From besu with Apache License 2.0 6 votes vote down vote up
@Override
public LabelledMetric<org.hyperledger.besu.plugin.services.metrics.Counter> createLabelledCounter(
    final MetricCategory category,
    final String name,
    final String help,
    final String... labelNames) {
  final String metricName = convertToPrometheusName(category, name);
  return cachedCounters.computeIfAbsent(
      metricName,
      (k) -> {
        if (isCategoryEnabled(category)) {
          final Counter counter = Counter.build(metricName, help).labelNames(labelNames).create();
          addCollectorUnchecked(category, counter);
          return new PrometheusCounter(counter);
        } else {
          return NoOpMetricsSystem.getCounterLabelledMetric(labelNames.length);
        }
      });
}
 
Example #4
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 #5
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 #6
Source File: PushDemo.java    From sofa-lookout with Apache License 2.0 6 votes vote down vote up
static void executeBatchJob() throws Exception {
    CollectorRegistry registry = CollectorRegistry.defaultRegistry;
    Counter requests = Counter.build()
            .name("my_library_requests_total").help("Total requests.")
            .labelNames("method").register();
    requests.labels("get").inc();


    PushGateway pushgateway = new PushGateway("127.0.0.1:7200/prom");
    // pushgateway.setConnectionFactory(new BasicAuthHttpConnectionFactory("my_user", "my_password"));
    Map<String, String> groupingkeys = new HashMap<>();
    groupingkeys.put("app", "xx");
    pushgateway.pushAdd(registry, "my_batch_job", groupingkeys);
    //  pushgateway.pushAdd(registry, "my_batch_job");
}
 
Example #7
Source File: ReaderFactory.java    From garmadon with Apache License 2.0 6 votes vote down vote up
private GarmadonReader.GarmadonMessageHandler buildGarmadonMessageHandler(PartitionedWriter<Message> writer,
                                                                          String eventName) {
    return msg -> {
        final CommittableOffset offset = msg.getCommittableOffset();
        final Counter.Child messagesWritingFailures = PrometheusMetrics.messageWritingFailuresCounter(eventName, offset.getPartition());
        final Counter.Child messagesWritten = PrometheusMetrics.messageWrittenCounter(eventName, offset.getPartition());

        Gauge.Child gauge = PrometheusMetrics.currentRunningOffsetsGauge(eventName, offset.getPartition());
        gauge.set(offset.getOffset());

        try {
            writer.write(Instant.ofEpochMilli(msg.getTimestamp()), offset, msg.toProto());

            messagesWritten.inc();
        } catch (IOException e) {
            // We accept losing messages every now and then, but still log failures
            messagesWritingFailures.inc();
            LOGGER.warn("Couldn't write a message", e);
        }
    };
}
 
Example #8
Source File: PrometheusMetricTest.java    From athenz with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateOrGetCollector() throws NoSuchMethodException, SecurityException, IllegalAccessException,
        IllegalArgumentException, InvocationTargetException {
    CollectorRegistry registry = new CollectorRegistry();
    ConcurrentHashMap<String, Collector> namesToCollectors = new ConcurrentHashMap<>();
    PrometheusMetric metric = new PrometheusMetric(registry, namesToCollectors, null, "");
    Method createOrGetCollector = metric.getClass().getDeclaredMethod("createOrGetCollector", String.class, SimpleCollector.Builder.class);
    createOrGetCollector.setAccessible(true);

    // test create
    String metricName = "metric_test";
    Counter.Builder builder = Counter.build();
    double countValue = 110.110d;
    Counter counter = (Counter) createOrGetCollector.invoke(metric, metricName, builder);
    counter.labels("", "").inc(countValue);
    // assertions
    Assert.assertSame(counter, namesToCollectors.get(metricName));
    Assert.assertEquals(registry.getSampleValue(metricName, this.labelNames, new String[]{"", ""}), countValue);

    // test get
    Counter counter_2 = (Counter) createOrGetCollector.invoke(metric, metricName, builder);
    // assertions
    Assert.assertSame(counter_2, namesToCollectors.get(metricName));
    Assert.assertSame(counter_2, counter);
}
 
Example #9
Source File: HystrixMetricsCollector.java    From prometheus-hystrix with Apache License 2.0 6 votes vote down vote up
public Counter.Child addCounter(String subsystem, String metric, String helpDoc, SortedMap<String, String> labels) {
    lock.writeLock().lock();
    try {
        String name = name(subsystem, metric);
        Counter counter = counters.get(name);
        if (counter == null) {
            counter = Counter.build().name(name(subsystem, metric)).help(helpDoc).
                    labelNames(labels.keySet().toArray(new String[]{})).create();
            counter.register(registry);
            counters.put(name, counter);
        }
        return counter.labels(labels.values().toArray(new String[]{}));
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example #10
Source File: ClientMetrics.java    From java-grpc-prometheus with Apache License 2.0 5 votes vote down vote up
private ClientMetrics(
    GrpcMethod method,
    Counter rpcStarted,
    Counter rpcCompleted,
    Counter streamMessagesReceived,
    Counter streamMessagesSent,
    Optional<Histogram> completedLatencySeconds) {
  this.method = method;
  this.rpcStarted = rpcStarted;
  this.rpcCompleted = rpcCompleted;
  this.streamMessagesReceived = streamMessagesReceived;
  this.streamMessagesSent = streamMessagesSent;
  this.completedLatencySeconds = completedLatencySeconds;
}
 
Example #11
Source File: PrometheusScrapeMetrics.java    From apiman with Apache License 2.0 5 votes vote down vote up
protected void doRequestsCtr(Counter ctr, RequestMetric metric) {
    ctr.labels(nullToEmpty(metric.getMethod(),
            Integer.toString(metric.getResponseCode()),
            metric.getApiId(),
            metric.getApiVersion(),
            metric.getClientId())).inc();
}
 
Example #12
Source File: PrometheusClientInstanceProfiler.java    From canal with Apache License 2.0 5 votes vote down vote up
private PrometheusClientInstanceProfiler() {
    this.outboundCounter = Counter.build()
            .labelNames(DEST_LABELS)
            .name(OUTBOUND_BYTES)
            .help("Total bytes sent to client.")
            .create();
    this.packetsCounter = Counter.build()
            .labelNames(new String[]{DEST, "packetType"})
            .name(PACKET_TYPE)
            .help("Total packets sent to client.")
            .create();
    this.emptyBatchesCounter = Counter.build()
            .labelNames(DEST_LABELS)
            .name(EMPTY_BATCHES)
            .help("Total empty batches sent to client.")
            .create();
    this.errorsCounter = Counter.build()
            .labelNames(new String[]{DEST, "errorCode"})
            .name(ERRORS)
            .help("Total client request errors.")
            .create();
    this.responseLatency = Histogram.build()
            .labelNames(DEST_LABELS)
            .name(LATENCY)
            .help("Client request latency.")
            // buckets in milliseconds
            .buckets(2.5, 10.0, 25.0, 100.0)
            .create();
}
 
Example #13
Source File: PrometheusEndpointTest.java    From client_java with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetricsExportedThroughPrometheusEndpoint() {
  // given:
  final Counter promCounter = Counter.build("foo_bar", "test counter")
          .labelNames("label1", "label2")
          .register();
  final Counter filteredCounter = Counter.build("filtered_foo_bar", "test counter")
          .labelNames("label1", "label2")
          .register();

  // when:
  promCounter.labels("val1", "val2").inc(3);
  filteredCounter.labels("val1", "val2").inc(6);

  HttpHeaders headers = new HttpHeaders();
  headers.set("Accept", "text/plain");

  ResponseEntity<String> metricsResponse = template.exchange(getBaseUrl() + "/prometheus?name[]=foo_bar", HttpMethod.GET, new HttpEntity(headers), String.class);

  // then:
  assertEquals(HttpStatus.OK, metricsResponse.getStatusCode());
  assertEquals(StringUtils.deleteWhitespace(TextFormat.CONTENT_TYPE_004), metricsResponse.getHeaders().getContentType().toString().toLowerCase());

  List<String> responseLines = Arrays.asList(metricsResponse.getBody().split("\n"));
  assertThat(responseLines, CustomMatchers.<String>exactlyNItems(1,
          matchesPattern("foo_bar\\{label1=\"val1\",label2=\"val2\",?\\} 3.0")));
}
 
Example #14
Source File: CountTypeUpdaterTest.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailureAssertions() {
	ListenerCollectorConfig cfg = TestUtilities.listenerCounterCfg(
			"count_assertion_failure_test",
			Measurable.FailureTotal,
			ListenerCollectorConfig.ASSERTIONS);
	
	Counter c = (Counter) reg.getOrCreateAndRegister(cfg);
	CountTypeUpdater u = new CountTypeUpdater(cfg);
	
	SampleResult result = newSampleResultWithAssertion(false);
	u.update(new SampleEvent(result,"tg1", vars()));	// #1
	double shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
	
	
	result = newSampleResultWithAssertion(true);
	u.update(new SampleEvent(result,"tg1", vars()));	// #could be 2, but should be 1
	shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
	
	// now update 2 assertions
	result = newSampleResultWithAssertion(false);
	result.addAssertionResult(altAssertion(false));
	u.update(new SampleEvent(result,"tg1", vars()));	// #now should be 2
	double shouldBeTwo = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(2.0, shouldBeTwo, 0.1);
	shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS_ALT).get();	//but alt is just 1
	Assert.assertEquals(1.0, shouldBeOne, 0.1);		
}
 
Example #15
Source File: CountTypeUpdaterTest.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testTotalAssertions() {
	ListenerCollectorConfig cfg = TestUtilities.listenerCounterCfg(
			"count_assertion_total_test",
			Measurable.CountTotal,
			ListenerCollectorConfig.ASSERTIONS);
	
	Counter c = (Counter) reg.getOrCreateAndRegister(cfg);
	CountTypeUpdater u = new CountTypeUpdater(cfg);
	
	SampleResult result = newSampleResultWithAssertion(false);
	u.update(new SampleEvent(result,"tg1", vars()));	// #1
	double shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
	
	
	result = newSampleResultWithAssertion(true);
	u.update(new SampleEvent(result,"tg1", vars()));	// #2
	double shouldBeTwo = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(2.0, shouldBeTwo, 0.1);
	
	// now update 2 assertions
	result = newSampleResultWithAssertion(false);
	result.addAssertionResult(altAssertion(false));
	u.update(new SampleEvent(result,"tg1", vars()));	// #3
	double shouldBeThree = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS).get();
	Assert.assertEquals(3.0, shouldBeThree, 0.1);
	shouldBeOne = c.labels(TestUtilities.EXPECTED_ASSERTION_LABELS_ALT).get();	//but alt is just 1
	Assert.assertEquals(1.0, shouldBeOne, 0.1);
}
 
Example #16
Source File: ManufacturingStatistics.java    From Architecting-Modern-Java-EE-Applications with MIT License 5 votes vote down vote up
@PostConstruct
private void initMetrics() {
    createdCars = Counter.build("cars_manufactured_total",
            "Total number of manufactured cars")
            .labelNames("color", "engine")
            .register();
}
 
Example #17
Source File: MemoryAllocationExportsTest.java    From client_java with Apache License 2.0 5 votes vote down vote up
@Test
public void testListenerLogic() {
  Counter counter = Counter.build("test", "test").labelNames("pool").create();
  MemoryAllocationExports.AllocationCountingNotificationListener listener =
          new MemoryAllocationExports.AllocationCountingNotificationListener(counter);

  // Increase by 123
  listener.handleMemoryPool("TestPool", 0, 123);
  Counter.Child child = counter.labels("TestPool");
  assertEquals(123, child.get(), 0.001);

  // No increase
  listener.handleMemoryPool("TestPool", 123, 123);
  assertEquals(123, child.get(), 0.001);

  // No increase, then decrease to 0
  listener.handleMemoryPool("TestPool", 123, 0);
  assertEquals(123, child.get(), 0.001);

  // No increase, then increase by 7
  listener.handleMemoryPool("TestPool", 0, 7);
  assertEquals(130, child.get(), 0.001);

  // Increase by 10, then decrease to 10
  listener.handleMemoryPool("TestPool", 17, 10);
  assertEquals(140, child.get(), 0.001);

  // Increase by 7, then increase by 3
  listener.handleMemoryPool("TestPool", 17, 20);
  assertEquals(150, child.get(), 0.001);

  // Decrease to 17, then increase by 3
  listener.handleMemoryPool("TestPool", 17, 20);
  assertEquals(153, child.get(), 0.001);
}
 
Example #18
Source File: TextFormatTest.java    From client_java with Apache License 2.0 5 votes vote down vote up
@Test
public void testCounterOutput() throws IOException {
  Counter noLabels = Counter.build().name("nolabels").help("help").register(registry);
  noLabels.inc();
  TextFormat.write004(writer, registry.metricFamilySamples());
  assertEquals("# HELP nolabels help\n"
               + "# TYPE nolabels counter\n"
               + "nolabels 1.0\n", writer.toString());
}
 
Example #19
Source File: SessionExtractionContainer.java    From cineast with MIT License 5 votes vote down vote up
/**
 * @param configFile where the config is located
 */
public static synchronized void open(File configFile) {
  if (open) {
    LOGGER.error("Already initialized...");
    return;
  }
  SessionExtractionContainer.configFile = configFile;
  initalizeExtraction();
  if (Config.sharedConfig().getMonitoring().enablePrometheus) {
    LOGGER.debug("Initalizing Prometheus monitoring for submitted paths");
    submittedPaths = Counter.build().name("cineast_submitted_paths")
        .help("Submitted Paths for this instance").register();
  }
  open = true;
}
 
Example #20
Source File: SessionContainerProvider.java    From cineast with MIT License 5 votes vote down vote up
public SessionContainerProvider() {
  if (Config.sharedConfig().getMonitoring().enablePrometheus) {
    LOGGER.debug("Enabling prometheus monitoring for paths in queue {}", queueNumber.get());
    instance = queueNumber.getAndIncrement();
    pathsInQueue = Gauge.build().name("cineast_item_in_queue_" + instance)
        .help("Paths currently in Queue " + instance).register();
    pathsCompleted = Counter.build().name("cineast_item_completed_queue_" + instance)
        .help("Paths completed in Queue " + instance).register();
  } else {
    instance = 0;
  }
}
 
Example #21
Source File: ServerMetrics.java    From java-grpc-prometheus with Apache License 2.0 5 votes vote down vote up
private ServerMetrics(
    GrpcMethod method,
    Counter serverStarted,
    Counter serverHandled,
    Counter serverStreamMessagesReceived,
    Counter serverStreamMessagesSent,
    Optional<Histogram> serverHandledLatencySeconds) {
  this.method = method;
  this.serverStarted = serverStarted;
  this.serverHandled = serverHandled;
  this.serverStreamMessagesReceived = serverStreamMessagesReceived;
  this.serverStreamMessagesSent = serverStreamMessagesSent;
  this.serverHandledLatencySeconds = serverHandledLatencySeconds;
}
 
Example #22
Source File: PrometheusMetric.java    From athenz with Apache License 2.0 5 votes vote down vote up
@Override
public void increment(String metricName, String requestDomainName, String principalDomainName, int count) {
    // prometheus does not allow null labels
    requestDomainName = (this.isLabelRequestDomainNameEnable) ? Objects.toString(requestDomainName, "") : "";
    principalDomainName = (this.isLabelPrincipalDomainNameEnable) ? Objects.toString(principalDomainName, "") : "";

    metricName = this.normalizeCounterMetricName(metricName);
    Counter counter = (Counter) createOrGetCollector(metricName, Counter.build());
    counter.labels(requestDomainName, principalDomainName).inc(count);
}
 
Example #23
Source File: AbstractMetricsRegistry.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void incrementCounter(double val, String counterName, String... labels) {
    Counter counter = nameToCounterMap.get(counterName);
    if (counter == null) {
        throw new IllegalArgumentException("Counter '" + counterName + "' does not exist in this registry");
    }

    counter.labels(labels).inc(val);
}
 
Example #24
Source File: PrometheusPullServerTest.java    From athenz with Apache License 2.0 5 votes vote down vote up
@Test
public void testConstructor() throws IOException {

    int port = 8181;
    String counterName = "constructor_test_total";
    String counterHelp = "constructor_test_help";
    double counterValue = 1234.6789;

    CollectorRegistry registry = new CollectorRegistry();
    Counter counter = Counter.build().name(counterName).help(counterHelp).register(registry);
    counter.inc(counterValue);

    // new
    String expectedResponseText = String.join(
        "\n",
        String.format("# HELP %s %s", counterName, counterHelp),
        String.format("# TYPE %s %s", counterName, counter.getClass().getSimpleName().toLowerCase()),
        String.format("%s %.4f", counterName, counterValue)
    );
    PrometheusPullServer exporter = null;
    try {
        exporter = new PrometheusPullServer(port, registry);

        HttpClient client = HttpClientBuilder.create().build();
        HttpGet request = new HttpGet(String.format("http://localhost:%d/metrics", port));
        HttpResponse response = client.execute(request);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String responseText = rd.lines().collect(Collectors.joining("\n"));

        // assertions
        Assert.assertEquals(responseText, expectedResponseText);
    } finally {
        // cleanup
        if (exporter != null) {
            exporter.quit();
        }
    }
}
 
Example #25
Source File: AbstractTimeLimiterMetrics.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
protected AbstractTimeLimiterMetrics(MetricNames names) {
    this.names = requireNonNull(names);
    callsCounter = Counter.build(names.getCallsMetricName(),
        "Total number of calls by kind")
        .labelNames("name", "kind")
        .create().register(collectorRegistry);
}
 
Example #26
Source File: CallMeter.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
private CallCollectors createMetrics() {
    final Counter totalCounter = Counter
        .build()
        .namespace(namespace)
        .subsystem(subsystem)
        .name(name + "_total")
        .help(help + " total")
        .labelNames(labelNames)
        .create();

    final Counter errorCounter = Counter
        .build()
        .namespace(namespace)
        .subsystem(subsystem)
        .name(name + "_failures_total")
        .help(help + " failures total")
        .labelNames(labelNames)
        .create();

    final Histogram histogram = Histogram
        .build()
        .namespace(namespace)
        .subsystem(subsystem)
        .name(name + "_latency")
        .help(help + " latency")
        .labelNames(labelNames)
        .create();

    return new CallCollectors(histogram, totalCounter, errorCounter);
}
 
Example #27
Source File: PrometheusCounterMetrics.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void inc() {
    Counter.Child metrics = this.getMetric();
    if (metrics != null) {
        metrics.inc();
    }
}
 
Example #28
Source File: PrometheusCounterMetrics.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void inc(double value) {
    Counter.Child metrics = this.getMetric();
    if (metrics != null) {
        metrics.inc(value);
    }
}
 
Example #29
Source File: HystrixPrometheusMetricsPublisherCommand.java    From prometheus-hystrix with Apache License 2.0 5 votes vote down vote up
private Counter.Child addCounter(String metric, String message, boolean deprecated, String... additionalLabels) {
    SortedMap<String, String> labels = new TreeMap<String, String>(this.labels);
    labels.putAll(this.labels);
    Iterator<String> l = Arrays.asList(additionalLabels).iterator();
    while (l.hasNext()) {
        labels.put(l.next(), l.next());
    }
    return collector.addCounter("hystrix_command", metric,
            (deprecated ? "DEPRECATED: " : "")
                    + message
                    + (message != null ? " " : "")
                    + "These are cumulative counts since the start of the application.", labels);
}
 
Example #30
Source File: InternalMetrics.java    From promregator with Apache License 2.0 5 votes vote down vote up
@PostConstruct
@SuppressWarnings("PMD.UnusedPrivateMethod")
// method is required and called by the Spring Framework
private void registerMetrics() {
	if (!this.enabled)
		return;
	
	this.latencyCFFetch = Histogram.build("promregator_cffetch_latency", "Latency on retrieving CF values")
			.labelNames("request_type").linearBuckets(0.1, 0.1, 50).register();
	
	this.autoRefreshingCacheMapSize = Gauge.build("promregator_autorefreshingcachemap_size", "The size of objects stored in an AutoRefreshingCacheMap")
			.labelNames(CACHE_MAP_NAME).register();
	
	this.autoRefreshingCacheMapExpiry = Counter.build("promregator_autorefreshingcachemap_expiry", "The number of objects having expired so far in an AutoRefreshingCacheMap")
			.labelNames(CACHE_MAP_NAME).register();
	this.autoRefreshingCacheMapRefreshSuccess = Counter.build("promregator_autorefreshingcachemap_refresh_success", "The number of successful refreshes of object so far in an AutoRefreshingCacheMap")
			.labelNames(CACHE_MAP_NAME).register();
	this.autoRefreshingCacheMapRefreshFailure = Counter.build("promregator_autorefreshingcachemap_refresh_failure", "The number of failed refreshes of object so far in an AutoRefreshingCacheMap")
			.labelNames(CACHE_MAP_NAME).register();
	
	this.autoRefreshingCacheMapErroneousEntryDisplaced = Counter.build("promregator_autorefreshingcachemap_erroneous_entry_displaced", "The number of cache items displaced in an AutoRefreshingCacheMap, because they were detected to be erroneous")
			.labelNames(CACHE_MAP_NAME).register();

	this.autoRefreshingCacheMapLastScan = Gauge.build("promregator_autorefreshingcachemap_scantimestamp", "The timestamp of the last execution of the RefreshThread execution of an AutoRefreshingCacheMap")
			.labelNames(CACHE_MAP_NAME).register();
	
	this.connectionWatchdogReconnects = Counter.build("promregator_connection_watchdog_reconnect", "The number of reconnection attempts made by the Connection Watchdog")
			.register();
	
	this.caffeineCacheMetricsCollector = new CacheMetricsCollector().register();
	
	this.rateLimitWaitTime = Histogram.build("promregator_cffetch_ratelimit_waittime", "Wait time due to CFCC rate limiting")
			.labelNames("request_type").linearBuckets(0.0, 0.05, 50).register();
	
	CollectorRegistry.defaultRegistry.register(new InternalCollector());
}