Class Metrics
Metrics are tracked through a concurrent-safe registry. A metric should be used to track important information that is useful for diagnostics and performance monitoring. All metrics requested must be specified by a key. All metric keys should be appropriately namespaced to avoid potential collisions with other code. For example, the following keys would be appropriate for an extension:
- "ExampleApp.ExampleTemplate.TheService.invokeCount"
- "CacheApp.DataCacheTemplate.StoreService.bytesStored"
There are five types of metrics you can create:
- Gauge - A single value to track. The simplest form of metric.
- Counter - A numeric metric that allows for relative changes in value, rather than direct assignment.
- Statistic - A histogram metric that tracks statistical information, such as averages and percentiles.
- List - A list containing single values.
- Set - A set that values can be added or removed from. It cannot be directly assigned to.
The typical use of metrics would be similar to:
Metrics.longValue().counter("ExampleApp.ExampleTemplate.TheService.invokeCount").incr();
Metrics are persisted across server restarts. It is not necessary to store metric values in a persisted environment, such as a property.
Note: A metric can only be of one type. If you attempt to get a metric key that was created via a different type, an
IllegalArgumentException
will be thrown.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic IBooleanMetricBuilder
bool()
Provides access to a Boolean metric.static IBasicMetricBuilder
<org.joda.time.DateTime> dateTime()
Provides access to a DateTime metric.static ILongMetricBuilder
Provides access to a Long metric.static String
Generates the name for a metric using the specified components.static IBasicMetricBuilder
<Double> number()
Provides access to a Number metric (a.k.a.static IBasicMetricBuilder
<String> string()
Provides access to a String metric.
-
Constructor Details
-
Metrics
public Metrics()
-
-
Method Details
-
bool
Provides access to a Boolean metric.- Returns:
- a Boolean metric builder
-
number
Provides access to a Number metric (a.k.a. a double).- Returns:
- a Number metric builder
-
dateTime
@ThingworxExtensionApiMethod(since={8,1,1}) public static IBasicMetricBuilder<org.joda.time.DateTime> dateTime()
Provides access to a DateTime metric.- Returns:
- a DateTime metric builder
-
string
Provides access to a String metric.- Returns:
- a String metric builder
-
longValue
Provides access to a Long metric.- Returns:
- a Long metric builder
-
name
Generates the name for a metric using the specified components. This method does not enforce the naming convention.- Parameters:
components
- one or more strings describing the metric- Returns:
- the generated metric name
-