/** * Declare a counter metric without setting any default position. * * @param name * the name of the metric * @return a thread-safe counter */ public Counter declareCounter(String name) { return declareCounter(name, null); }
/** * Declare a gauge metric with any default position. * * @param name * the name of the metric * @return a thread-safe gauge instance */ public Gauge declareGauge(String name) { return declareGauge(name, null); }
/** * Get histogram definition for an arbitrary metric. Caveat emptor: This * involves reading a volatile. * * @param metricName * name of the metric to get histogram definition for * @return how to define a new histogram or null */ MetricSettings getHistogramDefinition(String metricName) { if (metricReceiver == null) { return null; } else { return metricReceiver.getMetricDefinition(metricName); } }
public DocumentApiMetrics(MetricReceiver metricReceiver, String apiName) { Map<String, String> dimensions = new HashMap<>(); dimensions.put("api", apiName); for (DocumentOperationStatus status : DocumentOperationStatus.values()) { points.put(status, new HashMap<>()); dimensions.put("status", status.name()); for (DocumentOperationType operation : DocumentOperationType.values()) { dimensions.put("operation", operation.name()); points.get(status).put(operation, new Point(dimensions)); } } feeds = metricReceiver.declareCounter("feed.operations"); feedLatency = metricReceiver.declareGauge("feed.latency"); feedRequests = metricReceiver.declareCounter("feed.http-requests"); }
/** * Add to this metric at the given point. * * @param n * the amount by which to increase this counter * @param p * the point in the metric space at which to add to the metric */ public void add(long n, Point p) { metricReceiver.update(new Sample(new Measurement(Long.valueOf(n)), new Identifier(name, p), AssumedType.COUNTER)); }
public Bucket getUpdatedSnapshot() throws InterruptedException { updater.gotData.await(10, TimeUnit.SECONDS); Bucket s = receiver.getSnapshot(); long startedWaitingForSnapshot = System.currentTimeMillis(); // just waiting for the correct snapshot being constructed (yes, this is // necessary) while (s == null || s.entrySet().size() == 0) { if (System.currentTimeMillis() - startedWaitingForSnapshot > (10L * 1000L)) { throw new RuntimeException("Test timed out."); } Thread.sleep(10); s = receiver.getSnapshot(); } return s; }
/** * Declare a gauge metric, with default dimension values as given. Create * the point argument by using a builder from {@link #pointBuilder()}. * MetricSettings instances are built using * {@link MetricSettings.Builder}. * * @param name * the name of the metric * @param boundDimensions * an optional of dimensions which have a fixed value in the life * cycle of the metric object * @param customSettings * any optional settings * @return a thread-safe gauge metric */ public Gauge declareGauge(String name, Optional<Point> boundDimensions, MetricSettings customSettings) { if (customSettings != null) { addMetricDefinition(name, customSettings); } Point defaultDimensions = null; if (boundDimensions.isPresent()) { defaultDimensions = boundDimensions.get(); } return new Gauge(name, defaultDimensions, this); }
private MetricManager(ManagerConfig settings, Updater<Bucket, Sample> updater) { log.log(LogLevel.CONFIG, "setting up simple metrics gathering." + " reportPeriodSeconds=" + settings.reportPeriodSeconds() + ", pointsToKeepPerMetric=" + settings.pointsToKeepPerMetric()); metricsCollection = new ThreadLocalDirectory<>(updater); final AtomicReference<Bucket> currentSnapshot = new AtomicReference<>(null); executor = new ScheduledThreadPoolExecutor(1); // Fixed rate, not fixed delay, is it is not too important that each // bucket has data for exactly one second, but one should strive for // this.buffer to contain data for as close a period to the report // interval as possible executor.scheduleAtFixedRate(new MetricAggregator(metricsCollection, currentSnapshot, settings), 1, 1, TimeUnit.SECONDS); receiver = new MetricReceiver(metricsCollection, currentSnapshot); }
/** * Record a sample at the given position. * * @param x * sample value * @param p * position/dimension values for the sample */ public void sample(double x, Point p) { receiver.update(new Sample(new Measurement(Double.valueOf(x)), new Identifier(name, p), AssumedType.GAUGE)); }
@Override public MetricSnapshot latestSnapshot() { Bucket curr = metricReceiver.getSnapshot(); if (curr == null) { log.warning("no snapshot from instance of " + metricReceiver.getClass()); return null; } else { SnapshotConverter converter = new SnapshotConverter(curr); return converter.convert(); } }
public ContainerLatencySearcher(MetricReceiver metrics) { latencyGauge = metrics.declareGauge("query_container_latency"); }
public InputCheckingSearcher(MetricReceiver metrics) { utfRejections = metrics.declareCounter("double_encoded_utf8_rejections"); repeatedTermsInPhraseRejections = metrics.declareCounter("repeated_terms_in_phrase_rejections"); repeatedConsecutiveTermsInPhraseRejections = metrics.declareCounter("repeated_consecutive_terms_in_phrase_rejections"); }
@Override public void set(String key, Number val, Context ctx) { receiver.update(new Sample(new Measurement(val), new Identifier(key, getSimpleCoordinate(ctx)), AssumedType.GAUGE)); }
@Override public void histogram(PrintStream output) { Bucket curr = metricReceiver.getSnapshot(); if (curr == null) { log.warning("no snapshot from instance of " + metricReceiver.getClass()); } else { SnapshotConverter converter = new SnapshotConverter(curr); converter.outputHistograms(output); } }
/** * Declare a gauge metric, with default dimension values as given. Create * the point argument by using a builder from {@link #pointBuilder()}. * * @param name * the name of the metric * @param boundDimensions * dimensions which have a fixed value in the life cycle of the * metric object or null * @return a thread-safe gauge metric */ public Gauge declareGauge(String name, Point boundDimensions) { Optional<Point> optionalOfBoundDimensions; if (boundDimensions == null) { optionalOfBoundDimensions = Optional.empty(); } else { optionalOfBoundDimensions = Optional.of(boundDimensions); } return declareGauge(name, optionalOfBoundDimensions, null); }
public CounterWrapper declareCounter(String application, Dimensions dimensions, String name, DimensionType type) { synchronized (monitor) { Map<Dimensions, Map<String, MetricValue>> metricsByDimensions = getOrCreateApplicationMetrics(application, type); if (!metricsByDimensions.containsKey(dimensions)) metricsByDimensions.put(dimensions, new HashMap<>()); if (!metricsByDimensions.get(dimensions).containsKey(name)) { CounterWrapper counter = new CounterWrapper(metricReceiver.declareCounter(name, new Point(dimensions.dimensionsMap))); metricsByDimensions.get(dimensions).put(name, counter); } return (CounterWrapper) metricsByDimensions.get(dimensions).get(name); } }
@Override public void add(String key, Number val, Context ctx) { receiver.update(new Sample(new Measurement(val), new Identifier(key, getSimpleCoordinate(ctx)), AssumedType.COUNTER)); }
public GaugeWrapper declareGauge(String application, Dimensions dimensions, String name, DimensionType type) { synchronized (monitor) { Map<Dimensions, Map<String, MetricValue>> metricsByDimensions = getOrCreateApplicationMetrics(application, type); if (!metricsByDimensions.containsKey(dimensions)) metricsByDimensions.put(dimensions, new HashMap<>()); if (!metricsByDimensions.get(dimensions).containsKey(name)) { GaugeWrapper gauge = new GaugeWrapper(metricReceiver.declareGauge(name, new Point(dimensions.dimensionsMap))); metricsByDimensions.get(dimensions).put(name, gauge); } return (GaugeWrapper) metricsByDimensions.get(dimensions).get(name); } }
/** For testing - allows injection of a timer to avoid depending on the system clock */ public RateLimitingSearcher(RateLimitingConfig rateLimitingConfig, ClusterInfoConfig clusterInfoConfig, MetricReceiver metric, Clock clock) { this.capacityIncrement = rateLimitingConfig.capacityIncrement(); this.recheckForCapacityProbability = rateLimitingConfig.recheckForCapacityProbability(); this.availableCapacity = new AvailableCapacity(rateLimitingConfig.maxAvailableCapacity(), clock); this.nodeCount = clusterInfoConfig.nodeCount(); this.overQuotaCounter = metric.declareCounter(requestsOverQuotaMetricName); }
public StatisticsSearcher(com.yahoo.statistics.Statistics manager, Metric metric, MetricReceiver metricReceiver) { this.peakQpsReporter = new PeakQpsReporter(); this.metric = metric; queries = new Counter(QUERIES_METRIC, manager, false); failedQueries = new Counter(FAILED_QUERIES_METRIC, manager, false); nullQueries = new Counter("null_queries", manager, false); illegalQueries = new Counter("illegal_queries", manager, false); queryLatency = new Value(MEAN_QUERY_LATENCY_METRIC, manager, new Value.Parameters().setLogRaw(false).setLogMean(true).setNameExtension(false)); maxQueryLatency = new Value(MAX_QUERY_LATENCY_METRIC, manager, new Value.Parameters().setLogRaw(false).setLogMax(true).setNameExtension(false)); queryLatencyBuckets = Value.buildValue(QUERY_LATENCY_METRIC, manager, null); peakQPS = new Value(PEAK_QPS_METRIC, manager, new Value.Parameters().setLogRaw(false).setLogMax(true).setNameExtension(false)); hitsPerQuery = new Value(HITS_PER_QUERY_METRIC, manager, new Value.Parameters().setLogRaw(false).setLogMean(true).setNameExtension(false)); emptyResults = new Counter(EMPTY_RESULTS_METRIC, manager, false); metricReceiver.declareGauge(QUERY_LATENCY_METRIC, Optional.empty(), new MetricSettings.Builder().histogram(true).build()); scheduler.schedule(peakQpsReporter, 1000, 1000); }