> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-poc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# uptime()

> Get the total time live during a heartbeat aggregate

<Icon icon="tag" iconType="duotone" /> Since [1.15.0][toolkit-1.15.0]

Sum all the ranges where the system was live and return the total from a heartbeat aggregate.

There may appear to be some downtime between the start of the aggregate and the first heartbeat. If there is a heartbeat
aggregate covering the previous period, you can use its last heartbeat to correct for this using
[`interpolated_uptime()`][interpolated_uptime].

## Samples

Given a table called `liveness` containing weekly heartbeat aggregates in column `health` with timestamp column `date`,
use this command to get the total uptime of the system during the week of Jan 9, 2022.

```sql theme={"dark"}
SELECT uptime(health)
FROM liveness
WHERE date = '01-9-2022 UTC'
```

Returns:

```
    uptime
-----------------
6 days 23:55:35
```

## Arguments

The syntax is:

```sql theme={"dark"}
uptime(
    agg HEARTBEATAGG
) RETURNS INTERVAL
```

| Name | Type         | Default | Required | Description                                         |
| ---- | ------------ | ------- | -------- | --------------------------------------------------- |
| agg  | HeartbeatAgg | -       | ✔        | A heartbeat aggregate to get the liveness data from |

## Returns

| Column | Type     | Description                                      |
| ------ | -------- | ------------------------------------------------ |
| uptime | INTERVAL | The sum of all the live ranges in the aggregate. |

[interpolated_uptime]: /api-reference/timescaledb-toolkit/state-tracking/heartbeat_agg/interpolated_uptime

[toolkit-1.15.0]: https://github.com/timescale/timescaledb-toolkit/releases/tag/1.15.0
