Class GaugeRepresentation

  • All Implemented Interfaces:
    io.micrometer.core.instrument.Gauge, io.micrometer.core.instrument.Meter

    public class GaugeRepresentation
    extends MeterRepresentation
    implements io.micrometer.core.instrument.Gauge
    This class aims to provide a prototypical implementation of the Gauge Interface from Micrometer-API, allowing a client process to access the Gauge values collected from a Service in a uniform way.
    Even though the methods are functional and will indeed offer an accurate implementation of the metric we are simulating with this prototype, it is highly recommended that an instance of this class is used solely to access data and not to modify it, as the changes will not be registered in any sort of registry under normal circumstances, and this will alter the read values of the actual metrics.
    A gauge tracks a value that may go up or down. The value that is published for gauges is an instantaneous sample of the gauge at publishing time.
    The JsonObject representing a Gauge will have the following format:
    {
        "name": "sample.name",
        "description": "sample description, can be null",
        "baseUnit": "sample's.baseUnit",
        "measurements": [
            {
                "statistic": "VALUE",
                "value": 123.123
            }
        ],
        "availableTags": []
    }
     
    Special attention is required in the keys for the JsonValues as well as the type of Statistic and number of measurements.
    The services offered by this class are:
    • Parse a JsonObject into a Gauge
    • Check the gauge's value
    Author:
    Miguel Gomez
    See Also:
    Gauge
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.micrometer.core.instrument.Gauge

        io.micrometer.core.instrument.Gauge.Builder<T extends java.lang.Object>
      • Nested classes/interfaces inherited from interface io.micrometer.core.instrument.Meter

        io.micrometer.core.instrument.Meter.Builder, io.micrometer.core.instrument.Meter.Id, io.micrometer.core.instrument.Meter.Type
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<io.micrometer.core.instrument.Measurement> measurements  
      private double value  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private GaugeRepresentation​(java.lang.String name)
      Initializes a new GaugeRepresentation.
      private GaugeRepresentation​(javax.json.JsonObject object, java.lang.String... tags)
      Initializes a new GaugeRepresentation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static io.micrometer.core.instrument.Gauge createNewGauge​(java.lang.String name)
      Creates a new gauge with no value.
      javax.json.JsonObject getUpdater()
      Provides an updater for the Gauge.
      The update information for a Gauge is simply the name an the value of the Gauge.This information is packed into a JSON Object with the following format:
      java.lang.Iterable<io.micrometer.core.instrument.Measurement> measure()  
      static io.micrometer.core.instrument.Gauge parseGauge​(javax.json.JsonObject object, java.lang.String... tags)
      Parses a new gauge from a JsonObject.
      See the class documentation to see the format of a JsonObject representing a Gauge is expecting to have.
      void setValue​(double value)
      Changes the value of this gauge to the requested value.
      double value()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface io.micrometer.core.instrument.Meter

        close, getId, match, use
    • Field Detail

      • value

        private double value
      • measurements

        private java.util.List<io.micrometer.core.instrument.Measurement> measurements
    • Constructor Detail

      • GaugeRepresentation

        private GaugeRepresentation​(javax.json.JsonObject object,
                                    java.lang.String... tags)
        Initializes a new GaugeRepresentation.
        Parameters:
        object - JsonObject representing the Gauge
        tags - tags that the counter has
        Throws:
        java.lang.IllegalArgumentException - if the object is null, or if the JsonObject doesn't represent a valid Gauge.
      • GaugeRepresentation

        private GaugeRepresentation​(java.lang.String name)
        Initializes a new GaugeRepresentation.
        Parameters:
        name - URN of the gauge
        Throws:
        java.lang.IllegalArgumentException - if the name is null or empty
    • Method Detail

      • parseGauge

        public static io.micrometer.core.instrument.Gauge parseGauge​(javax.json.JsonObject object,
                                                                     java.lang.String... tags)
        Parses a new gauge from a JsonObject.
        See the class documentation to see the format of a JsonObject representing a Gauge is expecting to have.
        Parameters:
        object - JsonObject representing the Gauge we wish to parse
        tags - tags that the gauge has following the format key:value
        Returns:
        a Gauge representation of the JsonObject
        Throws:
        java.lang.IllegalArgumentException - if the object is null, or if the JsonObject doesn't represent a valid Gauge.
      • createNewGauge

        public static io.micrometer.core.instrument.Gauge createNewGauge​(java.lang.String name)
        Creates a new gauge with no value.
        Parameters:
        name - URN of the gauge
        Returns:
        a new Gauge ready to be used
        Throws:
        java.lang.IllegalArgumentException - if the name is null or empty
      • value

        public double value()
        Specified by:
        value in interface io.micrometer.core.instrument.Gauge
      • measure

        public java.lang.Iterable<io.micrometer.core.instrument.Measurement> measure()
        Specified by:
        measure in interface io.micrometer.core.instrument.Gauge
        Specified by:
        measure in interface io.micrometer.core.instrument.Meter
        Specified by:
        measure in class MeterRepresentation
      • getUpdater

        public javax.json.JsonObject getUpdater()
        Provides an updater for the Gauge.
        The update information for a Gauge is simply the name an the value of the Gauge.This information is packed into a JSON Object with the following format:
         {
             "name":"customgauge",
             "value":123.4
         }
         
        Specified by:
        getUpdater in class MeterRepresentation
        Returns:
        a JsonObject representing the changes this meter has experienced
        See Also:
        MeterRepresentation.getUpdater()
      • setValue

        public void setValue​(double value)
        Changes the value of this gauge to the requested value.
        Parameters:
        value - new value we want this Gauge to have