OpenTSDB

OpenTSDB is very similar to KairosDB but it is less popular and based instead on either Apache Cassandra or HBase. In the following simple example, we are going to start a single-node OpenTSDB based on HBase. We will use a Docker image to avoid a long installation process.

OpenTSDB uses the RESTful API and Telnet to query and ingest data. To install OpenTSDB, download the code from GitHub:

git clone https://github.com/PacktPublishing/Hands-On-Industrial-Internet-of-Things
cd Chapter07/opentsdb

Perform the following steps:

  1. Build the image with the following command:
docker build . --tag iiot:opentsdb
  1. Start the container:
docker run -v data:/data/hbase -p 4242:4242 --name opentsdb iiot:opentsdb 
  1. Check the status with the following command:
docker ps
  1. Open the browser at http://localhost:4242. This will look as shown in the following screenshot:

OpenTSDB GUI

Now we can push our first time-series using the RESTful API through CURL. You could also use a simple rest API client installed on Chrome, either Postman or an advanced REST client. Execute the following command several times, changing the value and the timestamp:

curl -d '{"metric": "sys.cpu", "timestamp": 1529176746, "value": 80, "tags": {"host": "localhost", "quality" : "GOOD"}' 
-H "Content-Type: application/json"
-X POST http://localhost:4242/api/put

We can then ask about the inserted time-series:

curl -X GET http://localhost:4242/api/search/lookup?m=sys.cpu

Following this, we can retrieve the inserted time-series interpolated every second (avg:duration_seconds), starting from 10 years ago (10y-ago):

http://localhost:4242/api/query?start=10y-ago&m=avg:duration_seconds:sys.cpu{host=localhost,quality=*}

The output should be as follows:

[{"metric":"sys.cpu","tags":{"host":"localhost","quality":"GOOD"},"aggregateTags":[],"dps":{"1529176746":90,"1529176756":100,"1529176766":110,"1529176776":111,"1529176876":211}}]

In OpenTSDB, a time-series data point consists of the following:

  • A metric name
  • A UNIX timestamp
  • A value
  • A set of tags (key-value pairs) that describe the time-series that the point belongs to

OpenTSDB supports  down-sampling and interpolation through aggregate functions, such as sum, last, and rate.

This example highlighted two important concepts: tags, and metrics or measures. In the IoT, we refer to tags when we want to provide a name to a measure or when we want to add attributes to a measure. Unfortunately, this naming is not standard and can cause confusion.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset