Aggregating data from properties and other assets (metrics)
Metrics are mathematical expressions that use aggregate functions to process all input data points and output a single data point per specified time interval. For example, a metric can calculate the average hourly temperature from a temperature data stream.
Metrics can input data from associated assets' metrics, so you can calculate statistics that provide insight to your operation or a subset of your operation. For example, a metric can calculate the average hourly temperature across all wind turbines in a wind farm. For more information about how to define associations between assets, see Defining relationships between assets (hierarchies).
AWS IoT SiteWise also automatically computes a set of basic aggregation metrics for all asset properties. To reduce computation costs, you can use these aggregates instead of defining custom metrics for basic computations. For more information, see Querying asset property aggregates.
Defining metrics (console)
When you define a metric for an asset model in the AWS IoT SiteWise console, you specify the following parameters:

Name – The property's name.

Formula – The metric expression. Metric expressions can use common functions, aggregation functions, and temporal functions. Metric expressions can input data from a property for all associated assets in a hierarchy. Start typing or press the down arrow key to trigger the autocomplete feature. For more information, see Using formula expressions.
Important Metrics can only input properties that are integer or double type. If you define any metric input variables in a metric's expression, those inputs must have the same time interval as the output metric.

Time interval – The metric time interval. AWS IoT SiteWise supports the following tumbling window time intervals, where each interval starts when the previous one ends:

1 minute – 1 minute, computed at the end of each minute (12:00:00 AM, 12:01:00 AM, 12:02:00 AM, and so on).

5 minutes – 5 minutes, computed at the end of every five minutes starting on the hour (12:00:00 AM, 12:05:00 AM, 12:10:00 AM, and so on).

15 minutes – 15 minutes, computed at the end of every fifteen minutes starting on the hour (12:00:00 AM, 12:15:00 AM, 12:30:00 AM, and so on).

1 hour – 1 hour (60 minutes), computed at the end of every hour in UTC (12:00:00 AM, 01:00:00 AM, 02:00:00 AM, and so on).

1 day – 1 day (24 hours), computed at the end of every day in UTC (12:00:00 AM Monday, 12:00:00 AM Tuesday, and so on).

1 week – 1 week (7 days), computed at the end of every Sunday in UTC (every 12:00:00 AM Monday).

For more information, see Creating an asset model (console).
Example metric definition
The following example demonstrates a metric property that aggregates an asset's temperature data to calculate maximum hourly temperature.
Example metric definition that inputs data from associated assets
The following example demonstrates a metric property that aggregates multiple wind turbines' average power data to calculate total average power for a wind farm.
Defining metrics (CLI)
When you define a metric for an asset model with the AWS IoT SiteWise API, you specify the following parameters:

name
– The property's name. 
dataType
– The data type of the metric, which must beDOUBLE
. 
expression
– The metric expression. Metric expressions can use common functions, aggregation functions, and temporal functions. For more information, see Using formula expressions. 
window
– The time interval for the metric's tumbling window. AWS IoT SiteWise supports the following tumbling window time intervals, where each interval starts when the previous one ends:
1m
– 1 minute, computed at the end of each minute (12:00:00 AM, 12:01:00 AM, 12:02:00 AM, and so on). 
5m
– 5 minutes, computed at the end of every five minutes starting on the hour (12:00:00 AM, 12:05:00 AM, 12:10:00 AM, and so on). 
15m
– 15 minutes, computed at the end of every fifteen minutes starting on the hour (12:00:00 AM, 12:15:00 AM, 12:30:00 AM, and so on). 
1h
– 1 hour (60 minutes), computed at the end of every hour in UTC (12:00:00 AM, 01:00:00 AM, 02:00:00 AM, and so on). 
1d
– 1 day (24 hours), computed at the end of every day in UTC (12:00:00 AM Monday, 12:00:00 AM Tuesday, and so on). 
1w
– 1 week (7 days), computed at the end of every Sunday in UTC (every 12:00:00 AM Monday).


variables
– The list of variables that defines the other properties of your asset or child assets to use in the expression. Each variable structure contains a simple name for use in the expression and avalue
structure that identifies which property to link to that variable. Thevalue
structure contains the following information:
propertyId
– The ID of the property from which to pull values. You can use the property's name instead of its ID if the property is defined in the current model (rather than defined in a model from a hierarchy). 
hierarchyId
– (Optional) The ID of the hierarchy from which to query child assets for the property. You can use the hierarchy definition's name instead of its ID. If you omit this value, AWS IoT SiteWise finds the property in the current model.
Important Metrics can only input properties that are integer or double type. If you define any metric input variables in a metric's expression, those inputs must have the same time interval as the output metric.


unit
– (Optional) The scientific unit for the property, such as mm or Celsius.
Example metric definition
The following example demonstrates a metric property that aggregates an asset's temperature measurement data to calculate maximum hourly temperature in Fahrenheit. This object is an example of an AssetModelProperty that contains a Metric. You can specify this object as a part of the CreateAssetModel request payload to create a metric property. For more information, see Creating an asset model (CLI).
{
...
"assetModelProperties": [...
{ "name": "Max temperature", "dataType": "DOUBLE", "type": { "metric": { "expression": "max(temp_f)", "variables": [ { "name": "temp_f", "value": { "propertyId": "Temperature F" } } ], "window": { "tumbling": { "interval": "1h" } } } }, "unit": "Fahrenheit" } ],...
}
Example metric definition that inputs data from associated assets
The following example demonstrates a metric property that aggregates multiple wind turbines' average power data to calculate total average power for a wind farm. This object is an example of an AssetModelProperty that contains a Metric. You can specify this object as a part of the CreateAssetModel request payload to create a metric property. For more information, see Creating an asset model (CLI).
{
...
"assetModelProperties": [...
{ "name": "Total Average Power", "dataType": "DOUBLE", "type": { "metric": { "expression": "avg(power)", "variables": [ { "name": "power", "value": { "propertyId": "a1b2c3d4567890abcdef11111EXAMPLE", "hierarchyId": "Turbine Asset Model" } } ], "window": { "tumbling": { "interval": "5m" } } } }, "unit": "kWh" } ],...
}