Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 2 Next »

원하는 Tag의 통계정보를 얻는 API이다.

HTTP Request

GET https://${CloudVendor}.${CountryCode}.machlake.com/lakes/${lake_id}/values/stat
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

Parameters

Optional

Type

Description

Example

tag_name

String

tag name with , separator

&tag_name=tag1,tag2,tag3

separator

string

separator for tag_name, columns, and_condition

&separator=

value_return_form

int

result set format

0 : separate standard (default) or 1 : merged standard

date_format

string

date format of select time or timestamp type ("SECOND", "MILLISECOND", "MICROSECOND", "NANOSECOND")

&date_format=YYYY-MM-DD HH24:MI:SS or &date_format=MILLISECOND (default : YYYY-MM-DD HH24:MI:SS)

offset

int

count of skip

&offset=500

limit

int

count of display

&limit=1000 (default : Restricted by 'lake tier' by lake tier)

Request Example

GET https://aws1.us.machlake.com/lakes/xbacd1234/values/stat?tag_name=tag01
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

Response Example

Status 200
{
    "data": {
        "calc_mode": "raw",
        "columns": [
            {
                "length": 20,
                "name": "ROW_COUNT",
                "type": 112
            },
            {
                "length": 17,
                "name": "MIN_VALUE",
                "type": 20
            },
            {
                "length": 17,
                "name": "MAX_VALUE",
                "type": 20
            },
            {
                "length": 4096,
                "name": "MIN_TIME",
                "type": 5
            },
            {
                "length": 4096,
                "name": "MAX_TIME",
                "type": 5
            },
            {
                "length": 4096,
                "name": "MIN_VALUE_TIME",
                "type": 5
            },
            {
                "length": 4096,
                "name": "MAX_VALUE_TIME",
                "type": 5
            },
            {
                "length": 4096,
                "name": "RECENT_ROW_TIME",
                "type": 5
            }
        ],
        "samples": [
            {
                "data": [
                    {
                        "MAX_TIME": "2022-04-15 10:14:58",
                        "MAX_VALUE": 1625,
                        "MAX_VALUE_TIME": "2022-04-13 10:12:00",
                        "MIN_TIME": "2022-04-13 10:12:00",
                        "MIN_VALUE": 1625,
                        "MIN_VALUE_TIME": "2022-04-13 10:12:00",
                        "RECENT_ROW_TIME": "2022-04-15 10:14:58",
                        "ROW_COUNT": 270
                    }
                ],
                "tag_name": "tag01"
            }
        ]
    },
    "status": "success"
}

Name of Value

Value Description

MAX_TIME

Maximum time value among records of the tag

MAX_VALUE

Maximum value among records in that tag

MAX_VALUE_TIME

The time value of the record with the maximum value entered

MIN_TIME

Minimum time value among records of that tag

MIN_VALUE

Minimum value among records in that tag

MIN_VALUE_TIME

The time value of the record with the minimum value entered

RECENT_ROW_TIME

Time value of the most recently entered data

ROW_COUNT

Number of records

Sample Code

 window(batch)

github

chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Select Data by Time Range for tag API by using curl in window script
:: written by yeony kim

set API_KEY=YOUR_API_TOKEN

set CONTENT_HEADER="Content-Type: application/json"
set API_HEADER="x-api-key: %API_KEY%"
set LAKE_ID=YOUR_LAKE_ID
set URL="https://%LAKE_ID%.machlake.com/lakes/values/time_range"

:: ------------------------------------------------------------------------------------------------- ::

:: CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set TAG_NAME=sensor1,sensor2
set DATE_FORMAT=YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "tag_name=%TAG_NAME%" --data-urlencode "date_format=%DATE_FORMAT%"

:: Return Format
:: {"data":{"columns":[{"length":4096,"name":"MIN","type":5},{"length":4096,"name":"MAX","type":5}],"samples":[{"data":[{"MAX":"2021-01-07 02:00:00 009:000:000","MIN":"2021-01-06 17:00:00 000:000:000"}],"tag_name":"sensor2"},{"data":[{"MAX":"2021-01-06 20:00:06 000:000:000","MIN":"2021-01-06 17:00:00 001:000:000"}],"tag_name":"sensor1"}]},"status":"success"}

:: ------------------------------------------------------------------------------------------------- ::
:: ------------------------------------------------------------------------------------------------- ::

:: CASE - Current DATA GET with date format nanosecond timestamp
set TAG_NAME=sensor1,sensor2
set DATE_FORMAT=NANOSECOND

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "tag_name=%TAG_NAME%" --data-urlencode "date_format=%DATE_FORMAT%"

:: Return Format
:: {"data":{"columns":[{"length":20,"name":"MIN","type":12},{"length":20,"name":"MAX","type":12}],"samples":[{"data":[{"MAX":1609952400009000000,"MIN":1609920000000000000}],"tag_name":"sensor2"},{"data":[{"MAX":1609930806000000000,"MIN":1609920000001000000}],"tag_name":"sensor1"}]},"status":"success"}

:: ------------------------------------------------------------------------------------------------- ::
 linux(shell)

github

# Text Encoding to UTF-8 in CMD
# Example For Get Tag Stat API by using curl in ubuntu

LAKE_ID=$YOUR_LAKE_ID
API_KEY=$YOUR_API_KEY
CLOUD_VENDOR=$YOUR_CLOUD_VENDOR
CLOUD_REGION=$YOUR_CLOUD_REGION
TAG_NAME=$YOUR_TAG_NAME

CONTENT_HEADER=Content-Type:application/json
API_HEADER=x-api-key:$API_KEY
URL=https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/values/stat

# ------------------------------------------------------------------------------------------------- #

# CASE - Select Tag

QUERY_LIMIT=
QUERY_OFFSET=


curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "limit=$QUERY_LIMIT" --data-urlencode "offset=$QUERY_OFFSET"

# Return Format / Example For 
# {"data":{"calc_mode":"raw","columns":[{"length":20,"name":"ROW_COUNT","type":112}......]},"status":"success"}

# ------------------------------------------------------------------------------------------------- #

# CASE - Select Tag with SQL Limit

QUERY_LIMIT=1
QUERY_OFFSET=

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "limit=$QUERY_LIMIT" --data-urlencode "offset=$QUERY_OFFSET"

# Return Format
# {"data":{"calc_mode":"raw","columns":[{"length":20,"name":"ROW_COUNT","type":112}......]},"status":"success"}

# ------------------------------------------------------------------------------------------------- #

# CASE - Select Tag with SQL Limit and SQL Offset

QUERY_LIMIT=1
QUERY_OFFSET=1

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "limit=$QUERY_LIMIT" --data-urlencode "offset=$QUERY_OFFSET"

# Return Format
# {"data":{"calc_mode":"raw","columns":[{"length":20,"name":"ROW_COUNT","type":112}......]},"status":"success"}

# ------------------------------------------------------------------------------------------------- #

# CASE - Select Tag about not exist

TAG_NAME=OTHER_NAME
QUERY_LIMIT=
QUERY_OFFSET=

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "limit=$QUERY_LIMIT" --data-urlencode "offset=$QUERY_OFFSET"

# Return Format
# {"data":{"calc_mode":"raw","columns":[{"length":20,"name":"ROW_COUNT","type":112}......]},"status":"success"}
 javascript

github

const API_KEY = "YOUR_API_TOKEN";
const LAKE_ID = "YOUR_LAKE_ID";
const CLOUD_VENDOR="CLOUD_VENDOR";
const CLOUD_REGION="CLOUD_REGION";
const TAG_NAME = "YOUR_TAG";

// process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
var request = require('request');
request.get({
    url: `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/values/stat`, 
    qs: {'tag_name': TAG_NAME},
    headers: {
        'x-api-key': API_KEY
    }}, 
    function(error, response, body) {
        console.log(body)
    })
 python

github

"""
Example For Get Tag View API by using requests in python
written by yeony kim
sensor1, sensor2 is applied in lake
"""

import requests

LAKE_ID = "YOUR_LAKE_ID"
API_KEY = "YOUR_API_TOKEN"
CLOUD_VENDOR="CLOUD_VENDOR"
CLOUD_REGION="CLOUD_REGION"

URL = f"https://{CLOUD_VENDOR}.{CLOUD_REGION}.machlake.com/lakes/{LAKE_ID}/values/stat"

headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
}

# CASE - Get Tag Information

params = {
    'name': 'sensor'
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"message":"no such name : sensor","status":"error"}

# CASE - Get Tag Information

params = {
    'name': 'sensor1'
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"name":"sensor1"},"status":"success"}

  • No labels