protected void addValue(final long timestamp, final Metrics metrics, final String name, final String value) { metrics.add(name, timestamp, value); }
public Metrics parse(final InputStream stream) throws IOException, ParseException { final Metrics result = new Metrics(); doParse(stream, result); return result; }
private Metrics readMetrics() { logger.debug("Opening reader {}", reader); reader.open(); logger.debug("Reading metrics from {}", reader); final Metrics result = new Metrics(); for (final MetricsSelector selector : selectors) { logger.debug("Reading metrics from {} via {}", reader, selector); final Metrics metrics = selector.readMetrics(reader); logger.debug("Selector " + selector + " returned " + metrics.size() + " metrics for " + reader); result.addAll(metrics); } reader.close(); scheduleResetIfNecessary(result.size()); if (System.currentTimeMillis() >= resetAfterTimestamp) { reset(); } return result; }
public Metrics parse(final Unzipper unzipper) throws ZipException, IOException, ParseException { final Metrics result = new Metrics(); for (final String name : unzipper.getEntries()) { for (final AbstractFileParser parser : parsers) { if (parser.canParseEntry(name)) { result.addAll(parseZipEntry(unzipper, name, parser)); break; } } } return result; }
@Override public Metrics readAllMetrics() { final Metrics result = new Metrics(); final GlobalRegistry registry = GlobalRegistry.getInstance(); final long timestamp = System.currentTimeMillis(); for(final SamplerTask task : registry.getTasks()) { final SamplerStats stats = task.getStats(); final String prefix = "samplers." + task.getName() + "."; result.add(prefix + "activeTime", "The number of seconds since the last activation of the sampler", timestamp, stats.getActiveTime()); result.add(prefix + "sampleSuccessCount", "The total number of successful samplings", timestamp, stats.getSampleSuccessCount()); result.add(prefix + "sampleFailureCount", "The total number of failed samplings due to unexpected exception", timestamp, stats.getSampleFailureCount()); result.add(prefix + "connectCount", "The total number of times the reader tried to connect to the input", timestamp, stats.getConnectCount()); result.add(prefix + "disconnectCount", "The total number of times the reader tried to disconnect from the input", timestamp, stats.getDisconnectCount()); result.add(prefix + "metricsCount", "The total number of metrics sampled the last time", timestamp, stats.getMetricsCount()); result.add(prefix + "sampleDuration", "The last sample duration in seconds", timestamp, stats.getSampleDuration()); } for (final SharedResource sharedResource : registry.getSharedResources()) { final Map<String, Object> stats = sharedResource.getStats(); for (final Entry<String, Object> entry : stats.entrySet()) { result.add(entry.getKey(), timestamp, entry.getValue()); } } return result; }
if (columnCount == 2) { logger.debug("Using current timestamp as metric timestamp for "+key); result.add(metric, start, value); } else if (columnCount == 3) { logger.debug("Using timestamp from query result column 3 as metric timestamp for "+key); final long timestamp = resultSet.getLong(3); result.add(metric, timestamp, value); } else { closeQuietly(resultSet); timingsLogger.debug("Discovered {} metrics in {} ms", result.size(), end - start); } catch (final SQLException e) { reconnect();
@Override public void open() throws MetricReadException { final long start = System.currentTimeMillis(); try { fetchOverHttp(httpClient, httpContext); } catch (final Exception e) { throw new OpenMetricsReaderException(e); } final long end = System.currentTimeMillis(); timingsLogger.debug("Discovered {} metrics in {} ms", values.size(), end - start); }
default Iterable<MetricName> readNames() { return readAllMetrics().getNames(); }
@Override public Metrics readAllMetrics() { final Metrics result = new Metrics(); final GlobalRegistry registry = GlobalRegistry.getInstance(); final long timestamp = System.currentTimeMillis(); for(final SamplerTask task : registry.getTasks()) { final SamplerStats stats = task.getStats(); final String prefix = "samplers." + task.getName() + "."; result.add(prefix + "activeTime", "The number of seconds since the last activation of the sampler", timestamp, stats.getActiveTime()); result.add(prefix + "sampleSuccessCount", "The total number of successful samplings", timestamp, stats.getSampleSuccessCount()); result.add(prefix + "sampleFailureCount", "The total number of failed samplings due to unexpected exception", timestamp, stats.getSampleFailureCount()); result.add(prefix + "connectCount", "The total number of times the reader tried to connect to the input", timestamp, stats.getConnectCount()); result.add(prefix + "disconnectCount", "The total number of times the reader tried to disconnect from the input", timestamp, stats.getDisconnectCount()); result.add(prefix + "metricsCount", "The total number of metrics sampled the last time", timestamp, stats.getMetricsCount()); result.add(prefix + "sampleDuration", "The last sample duration in seconds", timestamp, stats.getSampleDuration()); } for (final SharedResource sharedResource : registry.getSharedResources()) { final Map<String, Object> stats = sharedResource.getStats(); for (final Entry<String, Object> entry : stats.entrySet()) { result.add(entry.getKey(), timestamp, entry.getValue()); } } return result; }
if (columnCount == 2) { logger.debug("Using current timestamp as metric timestamp for "+key); result.add(metric, start, value); } else if (columnCount == 3) { logger.debug("Using timestamp from query result column 3 as metric timestamp for "+key); final long timestamp = resultSet.getLong(3); result.add(metric, timestamp, value); } else { closeQuietly(resultSet); timingsLogger.debug("Discovered {} metrics in {} ms", result.size(), end - start); } catch (final SQLException e) { reconnect();
@Override public void open() throws MetricReadException { final long start = System.currentTimeMillis(); try { fetchOverHttp(httpClient, httpContext); } catch (final Exception e) { throw new OpenMetricsReaderException(e); } final long end = System.currentTimeMillis(); timingsLogger.debug("Discovered {} metrics in {} ms", values.size(), end - start); }
default Iterable<MetricName> readNames() { return readAllMetrics().getNames(); }
protected void addMetric(final long timestamp, final String name, final Object value) { values.add(name, timestamp, value); }
protected Metrics readAlreadySelected(final MetaDataMetricsReader reader) { final List<SelectedMetric> matchingMetrics = getSelectedMetrics(reader); final Metrics result = new Metrics(); for (final SelectedMetric bean : matchingMetrics) { try { final MetricValue value = reader.readMetric(bean.getOriginalName()); result.add(bean.getName(), value); } catch (final MetricReadException e) { logger.warn("Failed to read " + bean.getOriginalName(), e); } } return result; }
@Override protected void processResponse(HttpUriRequest request, HttpResponse response) throws Exception { final HttpEntity entity = response.getEntity(); if (entity != null) { try(final InputStreamReader reader = streamEntity(entity)) { values = parser.parse(response, entity, reader); } } else { values = new Metrics(); logger.warn("Response was null. Response line: {}", response.getStatusLine()); } } }
private Metrics readMetrics() { logger.debug("Opening reader {}", reader); reader.open(); logger.debug("Reading metrics from {}", reader); final Metrics result = new Metrics(); for (final MetricsSelector selector : selectors) { logger.debug("Reading metrics from {} via {}", reader, selector); final Metrics metrics = selector.readMetrics(reader); logger.debug("Selector " + selector + " returned " + metrics.size() + " metrics for " + reader); result.addAll(metrics); } reader.close(); scheduleResetIfNecessary(result.size()); if (System.currentTimeMillis() >= resetAfterTimestamp) { reset(); } return result; }
@Override public void sample() { logger.debug("Sampling"); try { final long readStart = System.currentTimeMillis(); final Metrics rawMetrics = readMetrics(); final Metrics metrics = transformValues(rawMetrics); final long readEnd = System.currentTimeMillis(); timingsLogger.debug("Sampled {} metrics in {} ms", metrics.size(), readEnd-readStart); writeMetrics(metrics); timingsLogger.debug("Metrics sent to writers in {} ms", System.currentTimeMillis()-readEnd); SamplerStats.get().setMetricsCount(metrics.size()); } catch (final OpenMetricsReaderException e) { if (logger.isDebugEnabled()) { logger.debug("Failed to open reader", e); } else { if (!config.isQuiet()) { final String msg = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); logger.info("Failed to open reader: {}", msg); } } } catch (final MetricReadException e) { logger.warn("Failed to read metrics", e); } catch (final MetricWriteException e) { logger.warn("Failed to write metrics", e); } }
@Override public Set<String> metrics() { logger.debug("Listing the matched metrics"); try { final Metrics rawMetrics = readMetrics(); final Metrics metrics = transformValues(rawMetrics); final Set<String> result = new TreeSet<>(); metrics.getNames().forEach(i -> result.add(i.getName())); return result; } catch (final OpenMetricsReaderException e) { final String msg = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); logger.warn("Failed to open reader: {}", msg); } catch (final MetricReadException e) { logger.warn("Failed to read metrics", e); } catch (final MetricWriteException e) { logger.warn("Failed to write metrics", e); } return Collections.emptySet(); }
protected void addValue(final long timestamp, final Metrics metrics, final String name, final String value) { metrics.add(name, timestamp, value); }
protected Metrics readAlreadySelected(final MetaDataMetricsReader reader) { final List<SelectedMetric> matchingMetrics = getSelectedMetrics(reader); final Metrics result = new Metrics(); for (final SelectedMetric bean : matchingMetrics) { try { final MetricValue value = reader.readMetric(bean.getOriginalName()); result.add(bean.getName(), value); } catch (final MetricReadException e) { logger.warn("Failed to read " + bean.getOriginalName(), e); } } return result; }