Class Metrics
- java.lang.Object
-
- com.thingworx.metrics.Metrics
-
@ThingworxExtensionApiClass(since={8,1,1}, canInstantiate=true) public class Metrics extends java.lang.Object
A factory class for requesting metrics based on their type.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
Constructors Constructor Description Metrics()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IBooleanMetricBuilder
bool()
Provides access to a Boolean metric.static IBasicMetricBuilder<org.joda.time.DateTime>
dateTime()
Provides access to a DateTime metric.static ILongMetricBuilder
longValue()
Provides access to a Long metric.static java.lang.String
name(java.lang.String... components)
Generates the name for a metric using the specified components.static IBasicMetricBuilder<java.lang.Double>
number()
Provides access to a Number metric (a.k.a.static IBasicMetricBuilder<java.lang.String>
string()
Provides access to a String metric.
-
-
-
Method Detail
-
bool
@ThingworxExtensionApiMethod(since={8,1,1}) public static IBooleanMetricBuilder bool()
Provides access to a Boolean metric.- Returns:
- a Boolean metric builder
-
number
@ThingworxExtensionApiMethod(since={8,1,1}) public static IBasicMetricBuilder<java.lang.Double> 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
@ThingworxExtensionApiMethod(since={8,1,1}) public static IBasicMetricBuilder<java.lang.String> string()
Provides access to a String metric.- Returns:
- a String metric builder
-
longValue
@ThingworxExtensionApiMethod(since={8,1,1}) public static ILongMetricBuilder longValue()
Provides access to a Long metric.- Returns:
- a Long metric builder
-
name
@ThingworxExtensionApiMethod(since={8,1,1}) public static java.lang.String name(java.lang.String... components)
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
-
-