io.prometheus.client.CounterMetricFamily Java Examples
The following examples show how to use
io.prometheus.client.CounterMetricFamily.
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: AlibabaMetricsExports.java From metrics with Apache License 2.0 | 6 votes |
public void fromMeter(List<MetricFamilySamples> samples, MetricName metricName, Metered meter, long timestamp, boolean collectBucketCount) { samples.add(new CounterMetricFamily(normalizeName(metricName.getKey()) + "_count", getHelpMessage(metricName.getKey(), meter), meter.getCount())); samples.add(new GaugeMetricFamily(normalizeName(metricName.getKey()) + "_m1", getHelpMessage(metricName.getKey(), meter), meter.getOneMinuteRate())); samples.add(new GaugeMetricFamily(normalizeName(metricName.getKey()) + "_m5", getHelpMessage(metricName.getKey(), meter), meter.getFiveMinuteRate())); samples.add(new GaugeMetricFamily(normalizeName(metricName.getKey()) + "_m15", getHelpMessage(metricName.getKey(), meter), meter.getFifteenMinuteRate())); if (!collectBucketCount) { return; } long start = getNormalizedStartTime(timestamp, meter.getInstantCountInterval()); if (meter.getInstantCount().containsKey(start)) { samples.add(new GaugeMetricFamily(normalizeName(metricName.getKey()) + "_bucket_count", getHelpMessage(metricName.getKey(), meter), meter.getInstantCount().get(start))); } else { samples.add(new GaugeMetricFamily(normalizeName(metricName.getKey()) + "_bucket_count", getHelpMessage(metricName.getKey(), meter), 0)); } }
Example #2
Source File: EntryCollector.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); GaugeMetricFamily delay = new GaugeMetricFamily(DELAY, DELAY_HELP, DEST_LABELS_LIST); CounterMetricFamily transactions = new CounterMetricFamily(TRANSACTION, TRANSACTION_HELP, DEST_LABELS_LIST); for (EntryMetricsHolder emh : instances.values()) { long now = System.currentTimeMillis(); long latest = emh.latestExecTime.get(); // execTime > now,delay显示为0 long d = (now >= latest) ? (now - latest) : 0; delay.addMetric(emh.destLabelValues, d); transactions.addMetric(emh.destLabelValues, emh.transactionCounter.doubleValue()); } mfs.add(delay); mfs.add(transactions); return mfs; }
Example #3
Source File: EntryCollector.java From canal with Apache License 2.0 | 6 votes |
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); GaugeMetricFamily delay = new GaugeMetricFamily(DELAY, DELAY_HELP, DEST_LABELS_LIST); CounterMetricFamily transactions = new CounterMetricFamily(TRANSACTION, TRANSACTION_HELP, DEST_LABELS_LIST); for (EntryMetricsHolder emh : instances.values()) { long now = System.currentTimeMillis(); long latest = emh.latestExecTime.get(); // execTime > now,delay显示为0 long d = (now >= latest) ? (now - latest) : 0; delay.addMetric(emh.destLabelValues, d); transactions.addMetric(emh.destLabelValues, emh.transactionCounter.doubleValue()); } mfs.add(delay); mfs.add(transactions); return mfs; }
Example #4
Source File: ParserCollector.java From canal with Apache License 2.0 | 5 votes |
private void singleCollect(CounterMetricFamily bytesCounter, CounterMetricFamily blockingCounter, GaugeMetricFamily modeGauge, ParserMetricsHolder holder) { if (holder.isParallel) { blockingCounter.addMetric(holder.parserLabelValues, (holder.eventsPublishBlockingTime.doubleValue() / NANO_PER_MILLI)); } modeGauge.addMetric(holder.modeLabelValues, 1); bytesCounter.addMetric(holder.parserLabelValues, holder.receivedBinlogBytes.doubleValue()); }
Example #5
Source File: AlibabaMetricsExports.java From metrics with Apache License 2.0 | 5 votes |
public void fromCounter(List<MetricFamilySamples> samples, MetricName metricName, Counter counter, long timestamp) { samples.add(new CounterMetricFamily(normalizeName(metricName.getKey()) + "_count", getHelpMessage(metricName.getKey(), counter), counter.getCount())); if (counter instanceof BucketCounter) { long start = getNormalizedStartTime(timestamp, ((BucketCounter) counter).getBucketInterval()); if (((BucketCounter) counter).getBucketCounts().containsKey(start)) { samples.add(new GaugeMetricFamily(normalizeName(metricName.getKey()) + "_bucket_count", getHelpMessage(metricName.getKey(), counter), ((BucketCounter) counter).getBucketCounts().get(start))); } else { samples.add(new GaugeMetricFamily(normalizeName(metricName.getKey()) + "_bucket_count", getHelpMessage(metricName.getKey(), counter), 0)); } } }
Example #6
Source File: ParserCollector.java From canal with Apache License 2.0 | 5 votes |
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<>(); CounterMetricFamily bytesCounter = new CounterMetricFamily(RECEIVED_BINLOG, RECEIVED_BINLOG_HELP, parserLabels); GaugeMetricFamily modeGauge = new GaugeMetricFamily(PARSER_MODE, MODE_HELP, modeLabels); CounterMetricFamily blockingCounter = new CounterMetricFamily(PUBLISH_BLOCKING, PUBLISH_BLOCKING_HELP, parserLabels); for (ParserMetricsHolder emh : instances.values()) { if (emh instanceof GroupParserMetricsHolder) { GroupParserMetricsHolder group = (GroupParserMetricsHolder) emh; for (ParserMetricsHolder semh : group.holders) { singleCollect(bytesCounter, blockingCounter, modeGauge, semh); } } else { singleCollect(bytesCounter, blockingCounter, modeGauge, emh); } } mfs.add(bytesCounter); mfs.add(modeGauge); if (!blockingCounter.samples.isEmpty()) { mfs.add(blockingCounter); } return mfs; }
Example #7
Source File: SinkCollector.java From canal with Apache License 2.0 | 5 votes |
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); CounterMetricFamily blockingCounter = new CounterMetricFamily(SINK_BLOCKING_TIME, SINK_BLOCK_TIME_HELP, DEST_LABELS_LIST); for (SinkMetricsHolder smh : instances.values()) { blockingCounter.addMetric(smh.destLabelValues, (smh.eventsSinkBlockingTime.doubleValue() / NANO_PER_MILLI)); } mfs.add(blockingCounter); return mfs; }
Example #8
Source File: HibernateStatisticsCollector.java From client_java with Apache License 2.0 | 5 votes |
private CounterMetricFamily createCounterForQuery(String metric, String help, ValueProviderPerQuery provider) { final CounterMetricFamily counters = new CounterMetricFamily(metric, help, LABEL_NAMES_PER_QUERY); addMetricsForQuery(new PerQuerySamples() { @Override public void addMetric(List<String> labelValues, double value) { counters.addMetric(labelValues, value); } }, provider); return counters; }
Example #9
Source File: HibernateStatisticsCollector.java From client_java with Apache License 2.0 | 5 votes |
private CounterMetricFamily createCounter(String metric, String help, ValueProvider provider) { CounterMetricFamily metricFamily = new CounterMetricFamily(metric, help, LABEL_NAMES); for (Entry<String, SessionFactory> entry : sessionFactories.entrySet()) { metricFamily.addMetric( Collections.singletonList(entry.getKey()), provider.getValue(entry.getValue().getStatistics()) ); } return metricFamily; }
Example #10
Source File: ClassLoadingExports.java From client_java with Apache License 2.0 | 5 votes |
void addClassLoadingMetrics(List<MetricFamilySamples> sampleFamilies) { sampleFamilies.add(new GaugeMetricFamily( "jvm_classes_loaded", "The number of classes that are currently loaded in the JVM", clBean.getLoadedClassCount())); sampleFamilies.add(new CounterMetricFamily( "jvm_classes_loaded_total", "The total number of classes that have been loaded since the JVM has started execution", clBean.getTotalLoadedClassCount())); sampleFamilies.add(new CounterMetricFamily( "jvm_classes_unloaded_total", "The total number of classes that have been unloaded since the JVM has started execution", clBean.getUnloadedClassCount())); }
Example #11
Source File: ParserCollector.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
private void singleCollect(CounterMetricFamily bytesCounter, CounterMetricFamily blockingCounter, GaugeMetricFamily modeGauge, ParserMetricsHolder holder) { if (holder.isParallel) { blockingCounter.addMetric(holder.parserLabelValues, (holder.eventsPublishBlockingTime.doubleValue() / NANO_PER_MILLI)); } modeGauge.addMetric(holder.modeLabelValues, 1); bytesCounter.addMetric(holder.parserLabelValues, holder.receivedBinlogBytes.doubleValue()); }
Example #12
Source File: ParserCollector.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<>(); CounterMetricFamily bytesCounter = new CounterMetricFamily(RECEIVED_BINLOG, RECEIVED_BINLOG_HELP, parserLabels); GaugeMetricFamily modeGauge = new GaugeMetricFamily(PARSER_MODE, MODE_HELP, modeLabels); CounterMetricFamily blockingCounter = new CounterMetricFamily(PUBLISH_BLOCKING, PUBLISH_BLOCKING_HELP, parserLabels); for (ParserMetricsHolder emh : instances.values()) { if (emh instanceof GroupParserMetricsHolder) { GroupParserMetricsHolder group = (GroupParserMetricsHolder) emh; for (ParserMetricsHolder semh : group.holders) { singleCollect(bytesCounter, blockingCounter, modeGauge, semh); } } else { singleCollect(bytesCounter, blockingCounter, modeGauge, emh); } } mfs.add(bytesCounter); mfs.add(modeGauge); if (!blockingCounter.samples.isEmpty()) { mfs.add(blockingCounter); } return mfs; }
Example #13
Source File: SinkCollector.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); CounterMetricFamily blockingCounter = new CounterMetricFamily(SINK_BLOCKING_TIME, SINK_BLOCK_TIME_HELP, DEST_LABELS_LIST); for (SinkMetricsHolder smh : instances.values()) { blockingCounter.addMetric(smh.destLabelValues, (smh.eventsSinkBlockingTime.doubleValue() / NANO_PER_MILLI)); } mfs.add(blockingCounter); return mfs; }
Example #14
Source File: CacheMetricsCollector.java From client_java with Apache License 2.0 | 4 votes |
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); List<String> labelNames = Arrays.asList("cache"); CounterMetricFamily cacheHitTotal = new CounterMetricFamily("caffeine_cache_hit_total", "Cache hit totals", labelNames); mfs.add(cacheHitTotal); CounterMetricFamily cacheMissTotal = new CounterMetricFamily("caffeine_cache_miss_total", "Cache miss totals", labelNames); mfs.add(cacheMissTotal); CounterMetricFamily cacheRequestsTotal = new CounterMetricFamily("caffeine_cache_requests_total", "Cache request totals, hits + misses", labelNames); mfs.add(cacheRequestsTotal); CounterMetricFamily cacheEvictionTotal = new CounterMetricFamily("caffeine_cache_eviction_total", "Cache eviction totals, doesn't include manually removed entries", labelNames); mfs.add(cacheEvictionTotal); GaugeMetricFamily cacheEvictionWeight = new GaugeMetricFamily("caffeine_cache_eviction_weight", "Cache eviction weight", labelNames); mfs.add(cacheEvictionWeight); CounterMetricFamily cacheLoadFailure = new CounterMetricFamily("caffeine_cache_load_failure_total", "Cache load failures", labelNames); mfs.add(cacheLoadFailure); CounterMetricFamily cacheLoadTotal = new CounterMetricFamily("caffeine_cache_loads_total", "Cache loads: both success and failures", labelNames); mfs.add(cacheLoadTotal); GaugeMetricFamily cacheSize = new GaugeMetricFamily("caffeine_cache_estimated_size", "Estimated cache size", labelNames); mfs.add(cacheSize); SummaryMetricFamily cacheLoadSummary = new SummaryMetricFamily("caffeine_cache_load_duration_seconds", "Cache load duration: both success and failures", labelNames); mfs.add(cacheLoadSummary); for(Map.Entry<String, Cache> c: children.entrySet()) { List<String> cacheName = Arrays.asList(c.getKey()); CacheStats stats = c.getValue().stats(); try{ cacheEvictionWeight.addMetric(cacheName, stats.evictionWeight()); } catch (Exception e) { // EvictionWeight metric is unavailable, newer version of Caffeine is needed. } cacheHitTotal.addMetric(cacheName, stats.hitCount()); cacheMissTotal.addMetric(cacheName, stats.missCount()); cacheRequestsTotal.addMetric(cacheName, stats.requestCount()); cacheEvictionTotal.addMetric(cacheName, stats.evictionCount()); cacheSize.addMetric(cacheName, c.getValue().estimatedSize()); if(c.getValue() instanceof LoadingCache) { cacheLoadFailure.addMetric(cacheName, stats.loadFailureCount()); cacheLoadTotal.addMetric(cacheName, stats.loadCount()); cacheLoadSummary.addMetric(cacheName, stats.loadCount(), stats.totalLoadTime() / Collector.NANOSECONDS_PER_SECOND); } } return mfs; }
Example #15
Source File: CacheMetricsCollector.java From client_java with Apache License 2.0 | 4 votes |
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); List<String> labelNames = Arrays.asList("cache"); CounterMetricFamily cacheHitTotal = new CounterMetricFamily("guava_cache_hit_total", "Cache hit totals", labelNames); mfs.add(cacheHitTotal); CounterMetricFamily cacheMissTotal = new CounterMetricFamily("guava_cache_miss_total", "Cache miss totals", labelNames); mfs.add(cacheMissTotal); CounterMetricFamily cacheRequestsTotal = new CounterMetricFamily("guava_cache_requests_total", "Cache request totals, hits + misses", labelNames); mfs.add(cacheRequestsTotal); CounterMetricFamily cacheEvictionTotal = new CounterMetricFamily("guava_cache_eviction_total", "Cache eviction totals, doesn't include manually removed entries", labelNames); mfs.add(cacheEvictionTotal); CounterMetricFamily cacheLoadFailure = new CounterMetricFamily("guava_cache_load_failure_total", "Cache load failures", labelNames); mfs.add(cacheLoadFailure); CounterMetricFamily cacheLoadTotal = new CounterMetricFamily("guava_cache_loads_total", "Cache loads: both success and failures", labelNames); mfs.add(cacheLoadTotal); GaugeMetricFamily cacheSize = new GaugeMetricFamily("guava_cache_size", "Cache size", labelNames); mfs.add(cacheSize); SummaryMetricFamily cacheLoadSummary = new SummaryMetricFamily("guava_cache_load_duration_seconds", "Cache load duration: both success and failures", labelNames); mfs.add(cacheLoadSummary); for(Map.Entry<String, Cache> c: children.entrySet()) { List<String> cacheName = Arrays.asList(c.getKey()); CacheStats stats = c.getValue().stats(); cacheHitTotal.addMetric(cacheName, stats.hitCount()); cacheMissTotal.addMetric(cacheName, stats.missCount()); cacheRequestsTotal.addMetric(cacheName, stats.requestCount()); cacheEvictionTotal.addMetric(cacheName, stats.evictionCount()); cacheSize.addMetric(cacheName, c.getValue().size()); if(c.getValue() instanceof LoadingCache) { cacheLoadFailure.addMetric(cacheName, stats.loadExceptionCount()); cacheLoadTotal.addMetric(cacheName, stats.loadCount()); cacheLoadSummary.addMetric(cacheName, stats.loadCount(), stats.totalLoadTime() / Collector.NANOSECONDS_PER_SECOND); } } return mfs; }
Example #16
Source File: ThreadExports.java From client_java with Apache License 2.0 | 4 votes |
void addThreadMetrics(List<MetricFamilySamples> sampleFamilies) { sampleFamilies.add( new GaugeMetricFamily( "jvm_threads_current", "Current thread count of a JVM", threadBean.getThreadCount())); sampleFamilies.add( new GaugeMetricFamily( "jvm_threads_daemon", "Daemon thread count of a JVM", threadBean.getDaemonThreadCount())); sampleFamilies.add( new GaugeMetricFamily( "jvm_threads_peak", "Peak thread count of a JVM", threadBean.getPeakThreadCount())); sampleFamilies.add( new CounterMetricFamily( "jvm_threads_started_total", "Started thread count of a JVM", threadBean.getTotalStartedThreadCount())); sampleFamilies.add( new GaugeMetricFamily( "jvm_threads_deadlocked", "Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers", nullSafeArrayLength(threadBean.findDeadlockedThreads()))); sampleFamilies.add( new GaugeMetricFamily( "jvm_threads_deadlocked_monitor", "Cycles of JVM-threads that are in deadlock waiting to acquire object monitors", nullSafeArrayLength(threadBean.findMonitorDeadlockedThreads()))); GaugeMetricFamily threadStateFamily = new GaugeMetricFamily( "jvm_threads_state", "Current count of threads by state", Collections.singletonList("state")); Map<Thread.State, Integer> threadStateCounts = getThreadStateCountMap(); for (Map.Entry<Thread.State, Integer> entry : threadStateCounts.entrySet()) { threadStateFamily.addMetric( Collections.singletonList(entry.getKey().toString()), entry.getValue() ); } sampleFamilies.add(threadStateFamily); }
Example #17
Source File: TomcatGenericExports.java From tomcat_exporter with Apache License 2.0 | 4 votes |
private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) { try { final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*"); Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null); if (mBeans.size() > 0) { List<String> labelNameList = Collections.singletonList("name"); GaugeMetricFamily requestProcessorBytesReceivedGauge = new GaugeMetricFamily( "tomcat_requestprocessor_received_bytes", "Number of bytes received by this request processor", labelNameList); GaugeMetricFamily requestProcessorBytesSentGauge = new GaugeMetricFamily( "tomcat_requestprocessor_sent_bytes", "Number of bytes sent by this request processor", labelNameList); GaugeMetricFamily requestProcessorProcessingTimeGauge = new GaugeMetricFamily( "tomcat_requestprocessor_time_seconds", "The total time spend by this request processor", labelNameList); CounterMetricFamily requestProcessorErrorCounter = new CounterMetricFamily( "tomcat_requestprocessor_error_count", "The number of error request served by this request processor", labelNameList); CounterMetricFamily requestProcessorRequestCounter = new CounterMetricFamily( "tomcat_requestprocessor_request_count", "The number of request served by this request processor", labelNameList); for (final ObjectInstance mBean : mBeans) { List<String> labelValueList = Collections.singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", "")); requestProcessorBytesReceivedGauge.addMetric( labelValueList, ((Long) server.getAttribute(mBean.getObjectName(), "bytesReceived")).doubleValue()); requestProcessorBytesSentGauge.addMetric( labelValueList, ((Long) server.getAttribute(mBean.getObjectName(), "bytesSent")).doubleValue()); requestProcessorProcessingTimeGauge.addMetric( labelValueList, ((Long) server.getAttribute(mBean.getObjectName(), "processingTime")).doubleValue() / 1000.0); requestProcessorErrorCounter.addMetric( labelValueList, ((Integer) server.getAttribute(mBean.getObjectName(), "errorCount")).doubleValue()); requestProcessorRequestCounter.addMetric( labelValueList, ((Integer) server.getAttribute(mBean.getObjectName(), "requestCount")).doubleValue()); } mfs.add(requestProcessorBytesReceivedGauge); mfs.add(requestProcessorBytesSentGauge); mfs.add(requestProcessorProcessingTimeGauge); mfs.add(requestProcessorRequestCounter); mfs.add(requestProcessorErrorCounter); } } catch (Exception e) { log.error("Error retrieving metric.", e); } }
Example #18
Source File: AlibabaMetricsExports.java From metrics with Apache License 2.0 | 4 votes |
public void fromHistogram(List<MetricFamilySamples> samples, MetricName metricName, Histogram histogram) { String helpMessage = getHelpMessage(metricName.getKey(), histogram); fromSnapshot(samples, metricName, histogram.getSnapshot(), 1.0d, helpMessage); samples.add(new CounterMetricFamily(normalizeName(metricName.getKey()) + "_count", helpMessage, histogram.getCount())); }
Example #19
Source File: CustomCollectorUtils.java From uyuni with GNU General Public License v2.0 | 2 votes |
/** * Returns a Counter object. * @param metricName name of the metric * @param help help string * @param metricValue current value of the metric * @param metricPrefix prefix for the metric name * @return a Counter object */ public static CounterMetricFamily counterFor(String metricName, String help, long metricValue, String metricPrefix) { return new CounterMetricFamily(metricPrefix + "_" + metricName, metricPrefix + " - " + help, metricValue); }