Class MeterRepresentation
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation
-
- All Implemented Interfaces:
io.micrometer.core.instrument.Meter
- Direct Known Subclasses:
CounterRepresentation,GaugeRepresentation,TimerRepresentation
public abstract class MeterRepresentation extends java.lang.Object implements io.micrometer.core.instrument.MeterThis class aims to provide a prototypical implementation of the Meter Interface from Micrometer-API, allowing a client process to access the Meter 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 meter is a named and dimensioned producer of one or more measurements. This is a generic superclass that is extended by each individual meter. Even though every meter can be represented as a Meter for simplification and Abstraction, it is recommended that the prototype is instanced as a particular type of Meter in stead of a generic type. Please seeCounterRepresentation,GaugeRepresentationandTimerRepresentationto instantiate a more specific type of Meter. This representation of a Meter should only be an important detail to know.
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": [] }Please seeCounterRepresentation,GaugeRepresentationandTimerRepresentationfor a more specific and accurate representation of each specific type of meter. If a generic meter is instantiated, special attention is required in the keys of the JsonValues as well as making sure that there is at least one measurement that consists of JsonObject containing a statistic and a value.
The services offered by this class are:- Collect the Meter's ID
- Collect the Meter's measurements
- Create a JsonObject with the update information
- Author:
- Miguel Gomez
- See Also:
Meter,CounterRepresentation,GaugeRepresentation,TimerRepresentation
-
-
Field Summary
Fields Modifier and Type Field Description private io.micrometer.core.instrument.Meter.Ididprivate static java.lang.StringNON_VALID_JSON
-
Constructor Summary
Constructors Modifier Constructor Description protectedMeterRepresentation(java.lang.String name, io.micrometer.core.instrument.Meter.Type type)Instantiates a brand new Meter representation with just the name.
This method should be called by all extending subclasses to provide the attributes required by the Meter superclass that is extended by the interface they represent.protectedMeterRepresentation(javax.json.JsonObject object, io.micrometer.core.instrument.Meter.Type type, java.lang.String... tags)Instantiates a new Meter representation.
This method should be called by all extending subclasses to provide the attributes required by the Meter superclass that is extended by the interface they represent.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private static io.micrometer.core.instrument.TagsextractTagsMap(java.lang.String... tags)Extracts the tags from a string array and turns them into a Tags object.
The tags should be the same ones used for the HTTP request that provided the JsonObject representation of the Meter.
Following the same format used for the tags from said request, these tags follow the notationkey:value.io.micrometer.core.instrument.Meter.IdgetId()abstract javax.json.JsonObjectgetUpdater()Creates a JsonObject with the information required to update the meter in the Meter registry in the server-side.abstract java.lang.Iterable<io.micrometer.core.instrument.Measurement>measure()static io.micrometer.core.instrument.MeterparseMeter(java.lang.String json, java.lang.String... tags)Generically parses a meter.static io.micrometer.core.instrument.MeterparseMeter(javax.json.JsonObject object, java.lang.String... tags)Generically parses a meter.static io.micrometer.core.instrument.MeterparseMeterQuiet(java.lang.String json, java.lang.String... tags)Generically parses a meter.
-
-
-
Field Detail
-
NON_VALID_JSON
private static final java.lang.String NON_VALID_JSON
- See Also:
- Constant Field Values
-
id
private io.micrometer.core.instrument.Meter.Id id
-
-
Constructor Detail
-
MeterRepresentation
protected MeterRepresentation(javax.json.JsonObject object, io.micrometer.core.instrument.Meter.Type type, java.lang.String... tags)Instantiates a new Meter representation.
This method should be called by all extending subclasses to provide the attributes required by the Meter superclass that is extended by the interface they represent. The type of Meter to be indicated isCOUNTER,GAUGEorTIMERdepending on the subclass calling. If we don't want/need to specify the type, we can useOTHER.- Parameters:
object- JsonObject representing the Meter we wish to parsetype- type of meter that is being createdtags- tags that the meter has following the formatkey:value- Throws:
java.lang.IllegalArgumentException- if the object isnull, or if the JsonObject doesn't represent a valid Meter.
-
MeterRepresentation
protected MeterRepresentation(java.lang.String name, io.micrometer.core.instrument.Meter.Type type)Instantiates a brand new Meter representation with just the name.
This method should be called by all extending subclasses to provide the attributes required by the Meter superclass that is extended by the interface they represent. The type of Meter to be indicated isCOUNTER,GAUGEorTIMERdepending on the subclass calling. If we don't want/need to specify the type, we can useOTHER.- Parameters:
name- URN of the metertype- type of meter that is being created- Throws:
java.lang.IllegalArgumentException- if the name is null or empty
-
-
Method Detail
-
extractTagsMap
private static io.micrometer.core.instrument.Tags extractTagsMap(java.lang.String... tags)
Extracts the tags from a string array and turns them into a Tags object.
The tags should be the same ones used for the HTTP request that provided the JsonObject representation of the Meter.
Following the same format used for the tags from said request, these tags follow the notationkey:value.- Parameters:
tags- tags that the meter has- Returns:
- Tags representation of the set of tags
-
getId
public io.micrometer.core.instrument.Meter.Id getId()
- Specified by:
getIdin interfaceio.micrometer.core.instrument.Meter
-
measure
public abstract java.lang.Iterable<io.micrometer.core.instrument.Measurement> measure()
- Specified by:
measurein interfaceio.micrometer.core.instrument.Meter
-
getUpdater
public abstract javax.json.JsonObject getUpdater()
Creates a JsonObject with the information required to update the meter in the Meter registry in the server-side.- Returns:
- a JsonObject representing the changes this meter has experienced
-
parseMeter
public static io.micrometer.core.instrument.Meter parseMeter(java.lang.String json, java.lang.String... tags)Generically parses a meter. Emits a log message if thejsoncannot be parsed.- Parameters:
json- JSON string representation of the metertags- tags that the counter has following the formatkey:value- Returns:
- a Meter representation of the JsonObject (null if invalid, unknown)
-
parseMeterQuiet
public static io.micrometer.core.instrument.Meter parseMeterQuiet(java.lang.String json, java.lang.String... tags)Generically parses a meter. Does not emit anything if thejsoncannot be parsed.- Parameters:
json- JSON string representation of the metertags- tags that the counter has following the formatkey:value- Returns:
- a Meter representation of the JsonObject (null if invalid, unknown)
-
parseMeter
public static io.micrometer.core.instrument.Meter parseMeter(javax.json.JsonObject object, java.lang.String... tags)Generically parses a meter.- Parameters:
object- JsonObject representing the Timer we wish to parsetags- tags that the counter has following the formatkey:value- Returns:
- a Meter representation of the JsonObject (null if invalid, unknown)
-
-