03-opentsdb-telnet.mdx 3.3 KB
Newer Older
B
Bo Ding 已提交
1
---
2 3
sidebar_label: OpentsDB 行协议
title: OpentsDB 行协议
B
Bo Ding 已提交
4 5
---

6 7 8 9 10 11 12 13 14 15
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import JavaTelnet from "./_java_opts_telnet.mdx";
import PyTelnet from "./_py_opts_telnet.mdx";
import GoTelnet from "./_go_opts_telnet.mdx";
import RustTelnet from "./_rust_opts_telnet.mdx";
import NodeTelnet from "./_js_opts_telnet.mdx";
import CsTelnet from "./_cs_opts_telnet.mdx";
import CTelnet from "./_c_opts_telnet.mdx";

16 17 18 19 20 21 22 23 24 25 26
## 协议介绍

OpentsDB 行协议同样采用一行字符串来表示一行数据。OpentsDB 采用的是单列模型,因此一行只能包含一个普通数据列。标签列依然可以有多个。分为四部分,具体格式约定如下:

```txt
<metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
```

- metric 将作为超级表名。
- timestamp 本行数据对应的时间戳。根据时间戳的长度自动识别时间精度。支持秒和毫秒两种时间精度
- value 度量值,必须为一个数值。对应的列名也是 “value”。
27
- 最后一部分是标签集, 用空格分隔不同标签, 所有标签自动转化为 nchar 数据类型;
28 29 30 31 32 33 34 35 36

例如:

```txt
meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3
```

参考[OpenTSDB Telnet API文档](http://opentsdb.net/docs/build/html/api_telnet/put.html)。

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
## 示例代码

<Tabs defaultValue="java" groupId="lang">
  <TabItem label="Java" value="java">
    <JavaTelnet />
  </TabItem>
  <TabItem label="Python" value="Python">
    <PyTelnet />
  </TabItem>
  <TabItem label="Go" value="go">
    <GoTelnet />
  </TabItem>
  <TabItem label="Rust" value="rust">
    <RustTelnet />
  </TabItem>
  <TabItem label="Node.js" value="nodejs">
    <NodeTelnet />
  </TabItem>
  <TabItem label="C#" value="csharp">
    <CsTelnet />
  </TabItem>
  <TabItem label="C" value="c">
    <CTelnet />
  </TabItem>
</Tabs>
B
Bo Ding 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

以上示例代码会自动创建 2 个超级表, 每个超级表有 4 条数据。

```cmd
taos> use test;
Database changed.

taos> show stables;
              name              |      created_time       | columns |  tags  |   tables    |
============================================================================================
 meters.current                 | 2022-03-30 17:04:10.877 |       2 |      2 |           2 |
 meters.voltage                 | 2022-03-30 17:04:10.882 |       2 |      2 |           2 |
Query OK, 2 row(s) in set (0.002544s)

taos> select tbname, * from `meters.current`;
             tbname             |           ts            |           value           | groupid |            location            |
==================================================================================================================================
 t_0e7bcfa21a02331c06764f275... | 2022-03-28 09:56:51.249 |              10.800000000 | 3       | Beijing.Haidian                |
 t_0e7bcfa21a02331c06764f275... | 2022-03-28 09:56:51.250 |              11.300000000 | 3       | Beijing.Haidian                |
 t_7e7b26dd860280242c6492a16... | 2022-03-28 09:56:51.249 |              10.300000000 | 2       | Beijing.Chaoyang               |
 t_7e7b26dd860280242c6492a16... | 2022-03-28 09:56:51.250 |              12.600000000 | 2       | Beijing.Chaoyang               |
Query OK, 4 row(s) in set (0.005399s)
```