Class Metrics

java.lang.Object
com.thingworx.metrics.Metrics

@ThingworxExtensionApiClass(since={8,1,1}, canInstantiate=true) public class Metrics extends 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:

  1. Gauge - A single value to track. The simplest form of metric.
  2. Counter - A numeric metric that allows for relative changes in value, rather than direct assignment.
  3. Statistic - A histogram metric that tracks statistical information, such as averages and percentiles.
  4. List - A list containing single values.
  5. 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.