Wednesday, June 28, 2017

OpenTSDB Installation and Playing

opentsdb

Install OpenTSDB in Ubuntu 16.04

Preinstall

apt-get update && sudo apt-get upgrade -y && sudo reboot 

Install Java8

apt-get install -y default-jdk

Get Hbase and Install It

wget http://apache.claz.org/hbase/stable/hbase-1.2.6-bin.tar.gz
tar xzvf hbase-*.tar.gz
cd hbase*

Export Java Home

echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' >> conf/hbase-env.sh

Create Hbase and Zookeeper

for system to store data(hbase), and management data(zookeeper)

mkdir /root/hbase
mkdir /root/zookeeper

You might change above directory to other directory with large capacity drive.

edit conf/hbase-site.xml

<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>file:///root/hbase</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/root/zookeeper</value>
  </property>
</configuration>

Execute Hbase and Test Hbase

bin/start-hbase.sh
or /root/hbase-1.2.6/bin/start-hbase.sh

Test bash shell and port enabling


./bin/hbase shell
2017-06-29 07:50:18,366 WARN  [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017

hbase(main):001:0>

and testing the port enabling

nc -v localhost 2181

Install Necessary Package

apt-get install -y gnuplot build-essential python autoconf

Install OpenTSDB

cd /root/.
git clone http://github.com/OpenTSDB/opentsdb.git
cd opentsdb 
./build.sh
cd build
make install
export HBASE_HOME=/root/hbase-1.2.6
env COMPRESSION=NONE ./src/create_table.sh
mkdir /tmp/tsd
./build/tsdb tsd --port 14242 --staticroot=/root/hbase-1.2.6/opentsdb/build/staticroot --cachedir=/tmp/tsd --auto-metric

.
.
.
quested-With, If-Modified-Since)
2017-06-28 15:22:32,580 INFO  [main] ConnectionManager: TSD concurrent connection limit set to: 0
2017-06-28 15:22:32,583 WARN  [main] PluginLoader: Unable to locate any plugins of the type: net.opentsdb.tsd.HttpSerializer
2017-06-28 15:22:32,604 INFO  [main] TSDMain: Ready to serve on /0.0.0.0:14242

Playing with OpenTSDB

This example is playing with two-dimenstinoal data.
No idea if a better way to deal with it?

upload data

edit realgps.json

[
    {
        "metric": "rrrrealgps",
        "timestamp": 1435716527,
        "value": "23.1234",
        "tags": {
           "id": "jonah",
           "loc":"x"
                   }    },
    {
        "metric": "rrrrealgps",
        "timestamp": 1435716527,
        "value": "123.2222",
        "tags": {
           "id": "jonah",
           "loc":"y"
                   }    },
    {
        "metric": "rrrrealgps",
        "timestamp": 1435716627,
        "value": "23.3333",
        "tags": {
           "id": "jonah",
           "loc":"x"
                   }    },
    {
        "metric": "rrrrealgps",
        "timestamp": 1435716627,
        "value": "123.6666",
        "tags": {
           "id": "jonah",
           "loc":"y"
                   }    }
]

put data

curl -i -H "Content-Type: application/json; charset=UTF-8" -X POST -d @realgps.json http://172.16.155.181:14242/api/put?details

Qeury data

edit grealgps.json

{
    "start": 1435716526,
    "queries": [
        {
            "metric": "rrrrealgps",
            "aggregator": "avg",
            "tags": {
                "id": "jonah",
                "loc":"*"
                           }        }
    ]}

query data

curl -i -H "Content-Type: application/json; charset=UTF-8"  -d @grealgps.json http://172.16.155.181:14242/api/query



[{"metric":"rrrrealgps","tags":{"loc":"x","id":"jonah"},"aggregateTags":[],"dps":{"1435716527":23.12339973449707,"1435716627":23.33329963684082}},{"metric":"rrrrealgps","tags":{"loc":"y","id":"jonah"},"aggregateTags":[],"dps":{"1435716527":123.22219848632812,"1435716627":123.6666030883789}}]

You might need to change the grealgps.json with "loc":"x", and you will see the different result.

[{"metric":"rrrrealgps","tags":{"loc":"x","id":"jonah"},"aggregateTags":[],"dps":{"1435716527":23.12339973449707,"1435716627":23.33329963684082}}]

No comments:

Post a Comment