private GaugeMetricFamily createGauge(String metric, String help, Function<PoolStats, Integer> metricValueFunction) { GaugeMetricFamily metricFamily = new GaugeMetricFamily(metric, help, LABEL_NAMES); poolStatsMap.forEach((k, v) -> metricFamily.addMetric( Collections.singletonList(k), metricValueFunction.apply(v) )); return metricFamily; } }
@Override public List<MetricFamilySamples> describe() { List<MetricFamilySamples> list = new ArrayList<>(); list.add(new GaugeMetricFamily(fullname, help, labelNames)); return list; }
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()); }
@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; }
@Override public void addMetric(List<String> labelValues, double value) { gauges.addMetric(labelValues, value); } }, provider);
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); GaugeMetricFamily instanceInfo = new GaugeMetricFamily(INSTANCE, INSTANCE_HELP, INFO_LABELS_LIST); GaugeMetricFamily subsInfo = new GaugeMetricFamily(SUBSCRIPTION, SUBSCRIPTION_HELP, DEST_LABELS_LIST); for (Map.Entry<String, MetaMetricsHolder> nme : instances.entrySet()) { final String destination = nme.getKey(); final MetaMetricsHolder nmh = nme.getValue(); instanceInfo.addMetric(nmh.infoLabelValues, 1); List<ClientIdentity> subs = nmh.metaManager.listAllSubscribeInfo(destination); int count = subs == null ? 0 : subs.size(); subsInfo.addMetric(nmh.destLabelValues, count); } mfs.add(instanceInfo); mfs.add(subsInfo); return mfs; }
@Override public List<MetricFamilySamples> describe() { return Collections.<MetricFamilySamples>singletonList(new GaugeMetricFamily(fullname, help, labelNames)); }
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()); }
@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; }
private GaugeMetricFamily createGaugeForQuery(String metric, String help, ValueProviderPerQuery provider) { final GaugeMetricFamily gauges = new GaugeMetricFamily(metric, help, LABEL_NAMES_PER_QUERY); addMetricsForQuery(new PerQuerySamples() { @Override public void addMetric(List<String> labelValues, double value) { gauges.addMetric(labelValues, value); } }, provider); return gauges; }
@Override public List<MetricFamilySamples> collect() { GaugeMetricFamily testSessionMetric = new GaugeMetricFamily("selenium_test_sessions_running", "The number of Selenium test sessions that are running by proxy type", Collections.singletonList("proxy")); Iterable<RemoteProxy> iterable = () -> proxySet.iterator(); Map<String, Integer> countByProxies = StreamSupport.stream(iterable.spliterator(), false).collect( Collectors.groupingBy(p -> p.getClass().getSimpleName(), Collectors.summingInt(p -> p.getTotalUsed()))); countByProxies.entrySet().stream() .forEach(e -> testSessionMetric.addMetric(Collections.singletonList(e.getKey()), e.getValue())); List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); mfs.add(testSessionMetric); return mfs; }
void collectMemoryMetricsLinux(List<MetricFamilySamples> mfs) { // statm/stat report in pages, and it's non-trivial to get pagesize from Java // so we parse status instead. BufferedReader br = null; try { br = statusReader.procSelfStatusReader(); String line; while ((line = br.readLine()) != null) { if (line.startsWith("VmSize:")) { mfs.add(new GaugeMetricFamily("process_virtual_memory_bytes", "Virtual memory size in bytes.", Float.parseFloat(line.split("\\s+")[1]) * KB)); } else if (line.startsWith("VmRSS:")) { mfs.add(new GaugeMetricFamily("process_resident_memory_bytes", "Resident memory size in bytes.", Float.parseFloat(line.split("\\s+")[1]) * KB)); } } } catch (IOException e) { LOGGER.fine(e.toString()); } finally { if (br != null) { try { br.close(); } catch (IOException e) { LOGGER.fine(e.toString()); } } } }
@Override public List<MetricFamilySamples> collect() { GaugeMetricFamily seleniumContainersStateMetric = new GaugeMetricFamily("selenium_containers", "The number of Selenium Containers broken down by state", singletonList("state")); Map<States, Long> containerStates = startedContainers.values().stream() .collect(groupingBy(s -> { return s.isStarted() ? States.RUNNING : States.STARTING; }, counting())); // Ensure that if a state is empty it is 0 instead of missing. STATES.stream().forEach(s -> seleniumContainersStateMetric.addMetric(singletonList(s.name().toLowerCase()), Optional.ofNullable(containerStates.get(s)).orElse(0L))); List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); mfs.add(seleniumContainersStateMetric); return mfs; }
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())); }
/** * {@inheritDoc} */ @Override public List<MetricFamilySamples> collect() { final GaugeMetricFamily stats = new GaugeMetricFamily( name, "Bulkhead Stats", asList("name", "param")); for (Bulkhead bulkhead : bulkheadsSupplier.get()) { final Bulkhead.Metrics metrics = bulkhead.getMetrics(); stats.addMetric( asList(bulkhead.getName(), "available_concurrent_calls"), metrics.getAvailableConcurrentCalls()); } return singletonList(stats); } }
mfs.add(new GaugeMetricFamily("process_start_time_seconds", "Start time of the process since unix epoch in seconds.", runtimeBean.getStartTime() / MILLISECONDS_PER_SECOND)); mfs.add(new GaugeMetricFamily( "process_open_fds", "Number of open file descriptors.", openFdCount)); Long maxFdCount = callLongGetter("getMaxFileDescriptorCount", osBean); mfs.add(new GaugeMetricFamily( "process_max_fds", "Maximum number of open file descriptors.", maxFdCount)); } catch (Exception e) {
/** * Export gauge as a prometheus gauge. */ private GaugeMetricFamily fromGauge(List<Map.Entry<MetricName, Gauge>> gaugesWithSameName) { final Map.Entry<MetricName, Gauge> first = gaugesWithSameName.get(0); final MetricName firstName = first.getKey(); final GaugeMetricFamily gaugeMetricFamily = new GaugeMetricFamily(firstName.getName(), getHelpMessage(first.getKey(), first.getValue()), first.getKey().getTagKeys()); for (Map.Entry<MetricName, Gauge> entry : gaugesWithSameName) { gaugeMetricFamily.addMetric(entry.getKey().getTagValues(), getDoubleFromGauge(entry.getValue())); } return gaugeMetricFamily; }
@Override public List<MetricFamilySamples> describe() { return Collections.<MetricFamilySamples>singletonList(new GaugeMetricFamily(fullname, help, labelNames)); }
/** * {@inheritDoc} */ @Override public List<MetricFamilySamples> collect() { final GaugeMetricFamily stats = new GaugeMetricFamily( name, "Rate Limiter Stats", asList("name", "param")); for (RateLimiter rateLimiter : rateLimitersSupplier.get()) { final RateLimiter.Metrics metrics = rateLimiter.getMetrics(); stats.addMetric( asList(rateLimiter.getName(), "available_permissions"), metrics.getAvailablePermissions()); stats.addMetric( asList(rateLimiter.getName(), "waiting_threads"), metrics.getNumberOfWaitingThreads()); } return singletonList(stats); } }
void collectMemoryMetricsLinux(List<MetricFamilySamples> mfs) { // statm/stat report in pages, and it's non-trivial to get pagesize from Java // so we parse status instead. BufferedReader br = null; try { br = statusReader.procSelfStatusReader(); String line; while ((line = br.readLine()) != null) { if (line.startsWith("VmSize:")) { mfs.add(new GaugeMetricFamily("process_virtual_memory_bytes", "Virtual memory size in bytes.", Float.parseFloat(line.split("\\s+")[1]) * KB)); } else if (line.startsWith("VmRSS:")) { mfs.add(new GaugeMetricFamily("process_resident_memory_bytes", "Resident memory size in bytes.", Float.parseFloat(line.split("\\s+")[1]) * KB)); } } } catch (IOException e) { LOGGER.fine(e.toString()); } finally { if (br != null) { try { br.close(); } catch (IOException e) { LOGGER.fine(e.toString()); } } } }