

For similar capabilities to Amazon Timestream for LiveAnalytics, consider Amazon Timestream for InfluxDB. It offers simplified data ingestion and single-digit millisecond query response times for real-time analytics. Learn more [here](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html).

# Derivatives functions
<a name="timeseries-specific-constructs.functions.derivatives"></a>

Derivatives are used calculate the rate of change for a given metric and can be used to proactively respond to an event. For example, suppose you calculate the derivative of the CPU utilization of EC2 instances over the past 5 minutes, and you notice a significant positive derivative. This can be indicative of increased demand on your workload, so you may decide want to spin up more EC2 instances to better handle your workload. 

Amazon Timestream supports two variants of derivative functions. This section provides usage information for the Timestream for LiveAnalytics derivative functions, as well as sample queries. 



## Usage information
<a name="w2aab7c59c13c13c13b9"></a>


| Function | Output data type | Description | 
| --- | --- | --- | 
|  `derivative_linear(timeseries, interval)`  |  timeseries  |  Calculates the [derivative](https://wikipedia.org/wiki/Derivative) of each point in the `timeseries` for the specified `interval`.  | 
|  `non_negative_derivative_linear(timeseries, interval)`  |  timeseries  |  Same as `derivative_linear(timeseries, interval)`, but only returns positive values.  | 

## Query examples
<a name="w2aab7c59c13c13c13c11"></a>

**Example**  
Find the rate of change in the CPU utilization every 5 minutes over the past 1 hour:  

```
SELECT DERIVATIVE_LINEAR(CREATE_TIME_SERIES(time, measure_value::double), 5m) AS result 
FROM “sampleDB”.DevOps 
WHERE measure_name = 'cpu_utilization' 
AND hostname = 'host-Hovjv' and time > ago(1h) 
GROUP BY hostname, measure_name
```

**Example**  
Calculate the rate of increase in errors generated by one or more microservices:  

```
WITH binned_view as (
    SELECT bin(time, 5m) as binned_timestamp, ROUND(AVG(measure_value::double), 2) as value            
    FROM “sampleDB”.DevOps  
    WHERE micro_service = 'jwt'  
    AND time > ago(1h) 
    AND measure_name = 'service_error'
    GROUP BY bin(time, 5m)
)
SELECT non_negative_derivative_linear(CREATE_TIME_SERIES(binned_timestamp, value), 1m) as rateOfErrorIncrease
FROM binned_view
```