Class SdkMeter

  • All Implemented Interfaces:
    Meter

    final class SdkMeter
    extends java.lang.Object
    implements Meter
    SdkMeter is SDK implementation of Meter.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • VALID_INSTRUMENT_NAME_PATTERN

        private static final java.util.regex.Pattern VALID_INSTRUMENT_NAME_PATTERN
        Instrument names MUST conform to the following syntax.
        • They are not null or empty strings.
        • They are case-insensitive, ASCII strings.
        • The first character must be an alphabetic character.
        • Subsequent characters must belong to the alphanumeric characters, '_', '.', '/', and '-'.
        • They can have a maximum length of 255 characters.
      • NOOP_METER

        private static final Meter NOOP_METER
      • NOOP_INSTRUMENT_NAME

        private static final java.lang.String NOOP_INSTRUMENT_NAME
        See Also:
        Constant Field Values
      • collectLock

        private final java.lang.Object collectLock
      • callbackLock

        private final java.lang.Object callbackLock
      • meterEnabled

        private final boolean meterEnabled
    • Method Detail

      • collectAll

        java.util.Collection<MetricData> collectAll​(RegisteredReader registeredReader,
                                                    long epochNanos)
        Collect all metrics for the meter.
      • resetForTest

        void resetForTest()
        Reset the meter, clearing all registered callbacks and storages.
      • counterBuilder

        public LongCounterBuilder counterBuilder​(java.lang.String name)
        Description copied from interface: Meter
        Constructs a Counter instrument.

        This is used to build both synchronous instruments and asynchronous instruments (i.e. callbacks).

        Specified by:
        counterBuilder in interface Meter
        Parameters:
        name - the name of the Counter. Instrument names must consist of 255 or fewer characters including alphanumeric, _, ., -, /, and start with a letter.
        Returns:
        a builder for configuring a Counter instrument. Defaults to recording long values, but may be changed.
        See Also:
        Instrument Naming Rule
      • upDownCounterBuilder

        public LongUpDownCounterBuilder upDownCounterBuilder​(java.lang.String name)
        Description copied from interface: Meter
        Constructs an UpDownCounter instrument.

        This is used to build both synchronous instruments and asynchronous instruments (i.e. callbacks).

        Specified by:
        upDownCounterBuilder in interface Meter
        Parameters:
        name - the name of the UpDownCounter. Instrument names must consist of 255 or fewer characters including alphanumeric, _, ., -, /, and start with a letter.
        Returns:
        a builder for configuring an UpDownCounter instrument. Defaults to recording long values, but may be changed.
        See Also:
        Instrument Naming Rule
      • histogramBuilder

        public DoubleHistogramBuilder histogramBuilder​(java.lang.String name)
        Description copied from interface: Meter
        Constructs a Histogram instrument.
        Specified by:
        histogramBuilder in interface Meter
        Parameters:
        name - the name of the Histogram. Instrument names must consist of 255 or fewer characters including alphanumeric, _, ., -, /, and start with a letter.
        Returns:
        a builder for configuring a Histogram synchronous instrument. Defaults to recording double values, but may be changed.
        See Also:
        Instrument Naming Rule
      • gaugeBuilder

        public DoubleGaugeBuilder gaugeBuilder​(java.lang.String name)
        Description copied from interface: Meter
        Constructs an Asynchronous Gauge instrument.
        Specified by:
        gaugeBuilder in interface Meter
        Parameters:
        name - the name of the Gauge. Instrument names must consist of 255 or fewer characters including alphanumeric, _, ., -, /, and start with a letter.
        Returns:
        a builder used for configuring a Gauge instrument. Defaults to recording double values, but may be changed.
        See Also:
        Instrument Naming Rule
      • batchCallback

        public BatchCallback batchCallback​(java.lang.Runnable callback,
                                           ObservableMeasurement observableMeasurement,
                                           ObservableMeasurement... additionalMeasurements)
        Description copied from interface: Meter
        Constructs a batch callback.

        Batch callbacks allow a single callback to observe measurements for multiple asynchronous instruments.

        The callback will be called when the instruments are being observed.

        Callbacks are expected to abide by the following restrictions:

        • Run in a finite amount of time.
        • Safe to call repeatedly, across multiple threads.
        • Only observe values to registered instruments (i.e. observableMeasurement and additionalMeasurements
        Specified by:
        batchCallback in interface Meter
        Parameters:
        callback - a callback used to observe values on-demand.
        observableMeasurement - Instruments for which the callback may observe values.
        additionalMeasurements - Instruments for which the callback may observe values.
      • isMeterEnabled

        boolean isMeterEnabled()
        Returns true if the MeterConfig.enabled() of the meter is true.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • checkValidInstrumentName

        static boolean checkValidInstrumentName​(java.lang.String name)
        Check if the instrument name is valid. If invalid, log a warning.