Java Code Examples for io.prometheus.client.Counter#Child
The following examples show how to use
io.prometheus.client.Counter#Child .
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: HystrixMetricsCollector.java From prometheus-hystrix with Apache License 2.0 | 6 votes |
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 2
Source File: ReaderFactory.java From garmadon with Apache License 2.0 | 6 votes |
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 3
Source File: MemoryAllocationExportsTest.java From client_java with Apache License 2.0 | 5 votes |
@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 4
Source File: HystrixPrometheusMetricsPublisherCommand.java From prometheus-hystrix with Apache License 2.0 | 5 votes |
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 5
Source File: PrometheusCounterMetrics.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void inc(double value) { Counter.Child metrics = this.getMetric(); if (metrics != null) { metrics.inc(value); } }
Example 6
Source File: PrometheusCounterMetrics.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void inc() { Counter.Child metrics = this.getMetric(); if (metrics != null) { metrics.inc(); } }
Example 7
Source File: PrometheusMetrics.java From garmadon with Apache License 2.0 | 4 votes |
public static Counter.Child messageWrittenCounter(String eventName, int partition) { return buildChild(MESSAGES_WRITTEN, partition, eventName, String.valueOf(partition)); }
Example 8
Source File: PrometheusMetrics.java From garmadon with Apache License 2.0 | 4 votes |
public static Counter.Child hearbeatsSentCounter(String eventName, int partition) { return buildChild(HEARTBEATS_SENT, partition, eventName, String.valueOf(partition)); }
Example 9
Source File: PrometheusMetrics.java From garmadon with Apache License 2.0 | 4 votes |
public static Counter.Child messageWritingFailuresCounter(String eventName, int partition) { return buildChild(MESSAGES_WRITING_FAILURES, partition, eventName, String.valueOf(partition)); }
Example 10
Source File: MetricsFetcherMetrics.java From promregator with Apache License 2.0 | 4 votes |
public Counter.Child getFailedRequests() { if (failedRequests == null) return null; return failedRequests.labels(this.ownTelemetryLabels); }
Example 11
Source File: CallMeterChildImpl.java From resilience4j with Apache License 2.0 | 4 votes |
CallMeterChildImpl(Histogram.Child histogram, Counter.Child totalCounter, Counter.Child errorCounter) { this.histogram = histogram; this.totalCounter = totalCounter; this.errorCounter = errorCounter; }
Example 12
Source File: PrometheusMetrics.java From garmadon with Apache License 2.0 | 4 votes |
public static Counter.Child checkpointSuccessesCounter(String eventName, int partition) { return buildChild(CHECKPOINTS_SUCCESSES, partition, eventName, String.valueOf(partition)); }
Example 13
Source File: PrometheusMetrics.java From garmadon with Apache License 2.0 | 4 votes |
public static Counter.Child checkpointFailuresCounter(String eventName, int partition) { return buildChild(CHECKPOINTS_FAILURES, partition, eventName, String.valueOf(partition)); }
Example 14
Source File: HystrixPrometheusMetricsPublisherCommand.java From prometheus-hystrix with Apache License 2.0 | 4 votes |
private Counter.Child addCounter(String metric, String... additionalLabels) { return addCounter(metric, null, false, additionalLabels); }
Example 15
Source File: PrometheusMetrics.java From garmadon with Apache License 2.0 | 4 votes |
public static Counter.Child filesCommittedCounter(String eventName) { return buildChild(FILES_COMMITTED, eventName); }
Example 16
Source File: PrometheusMetrics.java From garmadon with Apache License 2.0 | 4 votes |
public static Counter.Child tmpFilesOpened(String eventName) { return buildChild(TMP_FILES_OPENED, eventName); }
Example 17
Source File: PrometheusMetrics.java From garmadon with Apache License 2.0 | 4 votes |
public static Counter.Child tmpFileOpenFailuresCounter(String eventName) { return buildChild(TMP_FILE_OPEN_FAILURES, eventName); }