Class MeterRepresentation
java.lang.Object
de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation
- All Implemented Interfaces:
de.iip_ecosphere.platform.support.metrics.Meter
- Direct Known Subclasses:
CounterRepresentation,GaugeRepresentation,TimerRepresentation
public abstract class MeterRepresentation
extends Object
implements de.iip_ecosphere.platform.support.metrics.Meter
This 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 see
The JsonObject representing a Gauge will have the following format:
The services offered by this class are:
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 see
CounterRepresentation, GaugeRepresentation and
TimerRepresentation to 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 see CounterRepresentation, GaugeRepresentation and
TimerRepresentation for 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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.iip_ecosphere.platform.support.metrics.Meter
de.iip_ecosphere.platform.support.metrics.Meter.Id, de.iip_ecosphere.platform.support.metrics.Meter.Type -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate de.iip_ecosphere.platform.support.metrics.Meter.Idprivate static final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMeterRepresentation(de.iip_ecosphere.platform.support.json.JsonObject object, de.iip_ecosphere.platform.support.metrics.Meter.Type type, 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.protectedMeterRepresentation(String name, de.iip_ecosphere.platform.support.metrics.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. -
Method Summary
Modifier and TypeMethodDescriptionprivate static List<de.iip_ecosphere.platform.support.metrics.Tag> extractTagsMap(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.de.iip_ecosphere.platform.support.metrics.Meter.IdgetId()getName()abstract de.iip_ecosphere.platform.support.json.JsonObjectCreates a JsonObject with the information required to update the meter in the Meter registry in the server-side.abstract Iterable<de.iip_ecosphere.platform.support.metrics.Measurement> measure()static de.iip_ecosphere.platform.support.metrics.MeterparseMeter(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags) Generically parses a meter.static de.iip_ecosphere.platform.support.metrics.MeterparseMeter(String json, String... tags) Generically parses a meter.static de.iip_ecosphere.platform.support.metrics.MeterparseMeterQuiet(String json, String... tags) Generically parses a meter.
-
Field Details
-
NON_VALID_JSON
- See Also:
-
id
private de.iip_ecosphere.platform.support.metrics.Meter.Id id
-
-
Constructor Details
-
MeterRepresentation
protected MeterRepresentation(de.iip_ecosphere.platform.support.json.JsonObject object, de.iip_ecosphere.platform.support.metrics.Meter.Type type, 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:
IllegalArgumentException- if the object isnull, or if the JsonObject doesn't represent a valid Meter.
-
MeterRepresentation
protected MeterRepresentation(String name, de.iip_ecosphere.platform.support.metrics.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:
IllegalArgumentException- if the name is null or empty
-
-
Method Details
-
extractTagsMap
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 de.iip_ecosphere.platform.support.metrics.Meter.Id getId()- Specified by:
getIdin interfacede.iip_ecosphere.platform.support.metrics.Meter
-
measure
- Specified by:
measurein interfacede.iip_ecosphere.platform.support.metrics.Meter
-
getUpdater
public abstract de.iip_ecosphere.platform.support.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 de.iip_ecosphere.platform.support.metrics.Meter parseMeter(String json, 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 de.iip_ecosphere.platform.support.metrics.Meter parseMeterQuiet(String json, 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 de.iip_ecosphere.platform.support.metrics.Meter parseMeter(de.iip_ecosphere.platform.support.json.JsonObject object, 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)
-
getName
- Specified by:
getNamein interfacede.iip_ecosphere.platform.support.metrics.Meter
-