Time collection are a quite common knowledge format that describes how issues change over time. A number of the commonest sources are industrial machines and IoT units, IT infrastructure stacks (resembling {hardware}, software program, and networking elements), and purposes that share their outcomes over time. Managing time collection knowledge effectively will not be straightforward as a result of the info mannequin doesn’t match general-purpose databases.

Because of this, I’m completely satisfied to share that Amazon Timestream is now typically accessible. Timestream is a quick, scalable, and serverless time collection database service that makes it straightforward to gather, retailer, and course of trillions of time collection occasions per day as much as 1,000 occasions quicker and at as little as to 1/10th the price of a relational database.

That is made potential by the way in which Timestream is managing knowledge: current knowledge is stored in reminiscence and historic knowledge is moved to cost-optimized storage primarily based on a retention coverage you outline. All knowledge is at all times robotically replicated throughout a number of availability zones (AZ) in the identical AWS region. New knowledge is written to the reminiscence retailer, the place knowledge is replicated throughout three AZs earlier than returning success of the operation. Knowledge replication is quorum primarily based such that the lack of nodes, or a whole AZ, doesn’t disrupt sturdiness or availability. As well as, knowledge within the reminiscence retailer is repeatedly backed as much as Amazon Simple Storage Service (S3) as an additional precaution.

Queries robotically entry and mix current and historic knowledge throughout tiers with out the necessity to specify the storage location, and help time series-specific functionalities that can assist you determine developments and patterns in knowledge in close to actual time.

There aren’t any upfront prices, you pay just for the info you write, retailer, or question. Primarily based on the load, Timestream robotically scales up or down to regulate capability, with out the necessity to handle the underlying infrastructure.

Timestream integrates with common providers for knowledge assortment, visualization, and machine studying, making it straightforward to make use of with present and new purposes. For instance, you may ingest knowledge instantly from AWS IoT Core, Amazon Kinesis Data Analytics for Apache Flink, AWS IoT Greengrass, and Amazon MSK. You’ll be able to visualize knowledge saved in Timestream from Amazon QuickSight, and use Amazon SageMaker to use machine studying algorithms to time collection knowledge, for instance for anomaly detection. You should use Timestream fine-grained AWS Identity and Access Management (IAM) permissions to simply ingest or question knowledge from an AWS Lambda perform. We’re offering the instruments to make use of Timestream with open supply platforms resembling Apache Kafka, Telegraf, Prometheus, and Grafana.

Utilizing Amazon Timestream from the Console
Within the Timestream console, I choose Create database. I can select to create a Commonplace database or a Pattern database populated with pattern knowledge. I proceed with an ordinary database and I title it MyDatabase.

All Timestream knowledge is encrypted by default. I exploit the default grasp key, however you should use a buyer managed key that you simply created utilizing AWS Key Management Service (KMS). In that means, you may management the rotation of the grasp key, and who has permissions to make use of or handle it.

I full the creation of the database. Now my database is empty. I choose Create desk and title it MyTable.

Every desk has its personal knowledge retention coverage. First knowledge is ingested within the reminiscence retailer, the place it may be saved from a minimal of 1 hour to a most of a 12 months. After that, it’s robotically moved to the magnetic retailer, the place it may be stored up from a minimal of in the future to a most of 200 years, after which it’s deleted. In my case, I choose 1 hour of reminiscence retailer retention and 5 years of magnetic retailer retention.

When writing knowledge in Timestream, you can not insert knowledge that’s older than the retention interval of the reminiscence retailer. For instance, in my case I won’t be able to insert information older than 1 hour. Equally, you can not insert knowledge with a future timestamp.

I full the creation of the desk. As you seen, I used to be not requested for an information schema. Timestream will robotically infer that as knowledge is ingested. Now, let’s put some knowledge within the desk!

Loading Knowledge in Amazon Timestream
Every document in a Timestream desk is a single knowledge level within the time collection and incorporates:

  • The measure title, sort, and worth. Every document can include a single measure, however completely different measure names and kinds could be saved in the identical desk.
  • The timestamp of when the measure was collected, with nanosecond granularity.
  • Zero or extra dimensions that describe the measure and can be utilized to filter or combination knowledge. Information in a desk can have completely different dimensions.

For instance, let’s construct a easy monitoring utility amassing CPU, reminiscence, swap, and disk utilization from a server. Every server is recognized by a hostname and has a location expressed as a rustic and a metropolis.

On this case, the size can be the identical for all information:

Information within the desk are going to measure various things. The measure names I exploit are:

  • cpu_utilization
  • memory_utilization
  • swap_utilization
  • disk_utilization

Measure sort is DOUBLE for all of them.

For the monitoring utility, I’m utilizing Python. To gather monitoring data I exploit the psutil module that I can set up with:

Right here’s the code for the acquire.py utility:

import time
import boto3
import psutil

from botocore.config import Config

DATABASE_NAME = "MyDatabase"
TABLE_NAME = "MyTable"

CITY = "London"
HOSTNAME = "MyHostname" # You can also make it dynamic utilizing socket.gethostname()

INTERVAL = 1 # Seconds

def prepare_record(measure_name, measure_value):
    document = 
        'Time': str(current_time),
        'Dimensions': dimensions,
        'MeasureName': measure_name,
        'MeasureValue': str(measure_value),
        'MeasureValueType': 'DOUBLE'
    return document

def write_records(information):
        consequence = write_client.write_records(DatabaseName=DATABASE_NAME,
        standing = consequence['ResponseMetadata']['HTTPStatusCode']
        print("Processed %d information. WriteRecords Standing: %s" %
              (len(information), standing))
    besides Exception as err:
        print("Error:", err)

if __name__ == '__main__':

    session = boto3.Session()
    write_client = session.consumer('timestream-write', config=Config(
        read_timeout=20, max_pool_connections=5000, retries='max_attempts': 10))
    query_client = session.consumer('timestream-query')

    dimensions = [
        'Name': 'country', 'Value': COUNTRY,
        'Name': 'city', 'Value': CITY,
        'Name': 'hostname', 'Value': HOSTNAME,

    information = []

    whereas True:

        current_time = int(time.time() * 1000)
        cpu_utilization = psutil.cpu_percent()
        memory_utilization = psutil.virtual_memory().%
        swap_utilization = psutil.swap_memory().%
        disk_utilization = psutil.disk_usage('/').%

        information.append(prepare_record('cpu_utilization', cpu_utilization))
            'memory_utilization', memory_utilization))
        information.append(prepare_record('swap_utilization', swap_utilization))
        information.append(prepare_record('disk_utilization', disk_utilization))

        print("information  - cpu  - reminiscence  - swap  - disk ".format(
            len(information), cpu_utilization, memory_utilization,
            swap_utilization, disk_utilization))

        if len(information) == 100:
            information = []


I begin the acquire.py utility. Each 100 information, knowledge is written within the MyData desk:

$ python3 acquire.py
information 4 - cpu 31.6 - reminiscence 65.3 - swap 73.8 - disk 5.7
information 8 - cpu 18.3 - reminiscence 64.9 - swap 73.8 - disk 5.7
information 12 - cpu 15.1 - reminiscence 64.8 - swap 73.8 - disk 5.7
. . .
information 96 - cpu 44.1 - reminiscence 64.2 - swap 73.8 - disk 5.7
information 100 - cpu 46.8 - reminiscence 64.1 - swap 73.8 - disk 5.7
Processed 100 information. WriteRecords Standing: 200
information 4 - cpu 36.3 - reminiscence 64.1 - swap 73.8 - disk 5.7
information 8 - cpu 31.7 - reminiscence 64.1 - swap 73.8 - disk 5.7
information 12 - cpu 38.8 - reminiscence 64.1 - swap 73.8 - disk 5.7
. . .

Now, within the Timestream console, I see the schema of the MyData desk, robotically up to date primarily based on the info ingested:

Word that, since all measures within the desk are of sort DOUBLE, the measure_value::double column incorporates the worth for all of them. If the measures have been of various sorts (for instance, INT or BIGINT) I might have extra columns (resembling measure_value::int and measure_value::bigint) .

Within the console, I also can see a recap of which type measures I’ve within the desk, their corresponding knowledge sort, and the size used for that particular measure:

Querying Knowledge from the Console
I can question time collection knowledge utilizing SQL. The reminiscence retailer is optimized for quick point-in-time queries, whereas the magnetic retailer is optimized for quick analytical queries. Nonetheless, queries robotically course of knowledge on all shops (reminiscence and magnetic) with out having to specify the info location within the question.

I’m working queries straight from the console, however I also can use JDBC connectivity to entry the question engine. I begin with a fundamental question to see the newest information within the desk:


Let’s strive one thing a bit of extra advanced. I wish to see the common CPU utilization aggregated by hostname in 5 minutes intervals for the final two hours. I filter information primarily based on the content material of measure_name. I exploit the perform bin() to spherical time to a a number of of an interval dimension, and the perform in the past() to match timestamps:

SELECT hostname,
       bin(time, 5m) as binned_time,
       avg(measure_value::double) as avg_cpu_utilization
  FROM MyDatabase.MyTable
 WHERE measure_name = ‘cpu_utilization'
   AND time > in the past(2h)
 GROUP BY hostname, bin(time, 5m)

When amassing time collection knowledge it’s possible you’ll miss some values. That is fairly widespread particularly for distributed architectures and IoT units. Timestream has some fascinating capabilities that you should use to fill within the lacking values, for instance utilizing linear interpolation, or primarily based on the final remark carried ahead.

Extra typically, Timestream provides many functions that show you how to to make use of mathematical expressions, manipulate strings, arrays, and date/time values, use common expressions, and work with aggregations/home windows.

To expertise what you are able to do with Timestream, you may create a pattern database and add the 2 IoT and DevOps datasets that we offer. Then, within the console question interface, take a look at the pattern queries to get a glimpse of a number of the extra superior functionalities:

Utilizing Amazon Timestream with Grafana
One of the fascinating facets of Timestream is the mixing with many platforms. For instance, you may visualize your time collection knowledge and create alerts utilizing Grafana 7.1 or increased. The Timestream plugin is a part of the open supply version of Grafana.

I add a brand new GrafanaDemo desk to my database, and use one other pattern utility to repeatedly ingest knowledge. The appliance simulates efficiency knowledge collected from a microservice structure working on 1000’s of hosts.

I set up Grafana on an Amazon Elastic Compute Cloud (EC2) occasion and add the Timestream plugin utilizing the Grafana CLI.

$ grafana-cli plugins set up grafana-timestream-datasource

I exploit SSH Port Forwarding to entry the Grafana console from my laptop computer:

$ ssh -L 3000:<EC2-Public-DNS>:3000 -N -f ec2-user@<EC2-Public-DNS>

Within the Grafana console, I configure the plugin with the best AWS credentials, and the Timestream database and desk. Now, I can choose the pattern dashboard, distributed as a part of the Timestream plugin, utilizing knowledge from the GrafanaDemo desk the place efficiency knowledge is repeatedly collected:

Accessible Now
Amazon Timestream is on the market in the present day in US East (N. Virginia), Europe (Eire), US West (Oregon), and US East (Ohio). You should use Timestream with the console, the AWS Command Line Interface (CLI), AWS SDKs, and AWS CloudFormation. With Timestream, you pay primarily based on the variety of writes, the info scanned by the queries, and the storage used. For extra data, please see the pricing page.

Yow will discover more sample applications in this repo. To be taught extra, please see the documentation. It’s by no means been simpler to work with time collection, together with knowledge ingestion, retention, entry, and storage tiering. Let me know what you’re going to construct!


Leave a Reply

Your email address will not be published. Required fields are marked *