All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hotels.styx.api.metrics.MetricRegistry Maven / Gradle / Ivy

There is a newer version: 1.0.0.beta9
Show newest version
/*
  Copyright (C) 2013-2018 Expedia Inc.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */
package com.hotels.styx.api.metrics;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistryListener;
import com.codahale.metrics.Timer;

import java.util.SortedMap;
import java.util.SortedSet;

/**
 * A registry for collecting all metrics.
 */
public interface MetricRegistry {

    /**
     * Returns or creates a sub-scope of this metric registry.
     *
     * @param name Name for the sub-scope.
     * @return A possibly-new metric registry, whose metrics will be 'children' of this scope.
     */
    MetricRegistry scope(String name);

    /**
     * Given a {@link com.codahale.metrics.Metric}, registers it under the given name.
     *
     * @param name   the name of the metric
     * @param metric the metric
     * @param     the type of the metric
     * @return {@code metric}
     * @throws IllegalArgumentException if the name is already registered
     */
     T register(String name, T metric) throws IllegalArgumentException;

    /**
     * Removes the metric with the given name.
     *
     * @param name the name of the metric
     * @return whether or not the metric was removed
     */
    boolean deregister(String name);


    /**
     * Creates a new {@link com.codahale.metrics.Counter} and registers it under the given name.
     *
     * @param name the name of the metric
     * @return a new {@link com.codahale.metrics.Counter}
     */
    Counter counter(String name);

    /**
     * Creates a new {@link com.codahale.metrics.Histogram} and registers it under the given name.
     *
     * @param name the name of the metric
     * @return a new {@link com.codahale.metrics.Histogram}
     */
    Histogram histogram(String name);

    /**
     * Creates a new {@link com.codahale.metrics.Meter} and registers it under the given name.
     *
     * @param name the name of the metric
     * @return a new {@link com.codahale.metrics.Meter}
     */
    Meter meter(String name);

    /**
     * Creates a new {@link com.codahale.metrics.Timer} and registers it under the given name.
     *
     * @param name the name of the metric
     * @return a new {@link com.codahale.metrics.Timer}
     */
    Timer timer(String name);

    /**
     * Adds a {@link MetricRegistryListener} to a collection of listeners that will be notified on
     * metric creation.  Listeners will be notified in the order in which they are added.
     * 

* N.B.: The listener will be notified of all existing metrics when it first registers. * * @param listener the listener that will be notified */ void addListener(MetricRegistryListener listener); /** * Removes a {@link MetricRegistryListener} from this registry's collection of listeners. * * @param listener the listener that will be removed */ void removeListener(MetricRegistryListener listener); /** * Returns a set of the names of all the metrics in the registry. * * @return the names of all the metrics */ SortedSet getNames(); /** * Returns a map of all the gauges in the registry and their names. * * @return all the gauges in the registry */ SortedMap getGauges(); /** * Returns a map of all the gauges in the registry and their names which match the given filter. * * @param filter the metric filter to match * @return all the gauges in the registry */ SortedMap getGauges(MetricFilter filter); /** * Returns a map of all the counters in the registry and their names. * * @return all the counters in the registry */ SortedMap getCounters(); /** * Returns a map of all the counters in the registry and their names which match the given * filter. * * @param filter the metric filter to match * @return all the counters in the registry */ SortedMap getCounters(MetricFilter filter); /** * Returns a map of all the histograms in the registry and their names. * * @return all the histograms in the registry */ SortedMap getHistograms(); /** * Returns a map of all the histograms in the registry and their names which match the given * filter. * * @param filter the metric filter to match * @return all the histograms in the registry */ SortedMap getHistograms(MetricFilter filter); /** * Returns a map of all the meters in the registry and their names. * * @return all the meters in the registry */ SortedMap getMeters(); /** * Returns a map of all the meters in the registry and their names which match the given filter. * * @param filter the metric filter to match * @return all the meters in the registry */ SortedMap getMeters(MetricFilter filter); /** * Returns a map of all the timers in the registry and their names. * * @return all the timers in the registry */ SortedMap getTimers(); /** * Returns a map of all the timers in the registry and their names which match the given filter. * * @param filter the metric filter to match * @return all the timers in the registry */ SortedMap getTimers(MetricFilter filter); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy