40-opentsdb-telnet.mdx 4.2 KB
Newer Older
1 2
---
title: OpenTSDB Line Protocol
D
danielclow 已提交
3 4
sidebar_label: OpenTSDB Line Protocol
description: This document describes how to insert data into TDengine using the OpenTSDB Line Protocol.
5 6 7 8 9 10 11 12 13 14 15 16 17 18
---

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";

## Introduction

19
A single line of text is used in OpenTSDB line protocol to represent one row of data. OpenTSDB employs a single column data model, so each line can only contain a single data column. There can be multiple tags. Each line contains 4 parts as below:
20

21
```txt
22 23 24
<metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
```

S
Sean Ely 已提交
25 26
- `metric` will be used as the STable name.
- `timestamp` is the timestamp of current row of data. The time precision will be determined automatically based on the length of the timestamp. Second and millisecond time precision are supported.
27
- `value` is a metric which must be a numeric value, The corresponding column name is "value".
28
- The last part is the tag set separated by spaces, all tags will be converted to NCHAR type automatically.
29 30 31 32

For example:

```txt
33
meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3
34
```
35

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
36
- The child table name is created automatically in a rule to guarantee its uniqueness. But you can configure `smlChildTableName` in taos.cfg to specify a tag value as the table names if the tag value is unique globally. For example, if a tag is called `tname` and you set `smlChildTableName=tname` in taos.cfg, when you insert `st,tname=cpu1,t1=4 c1=3 1626006833639000000`, the child table `cpu1` will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored.
37 38
- Due to the fact that SQL table names do not support point(.), schemaless has also processed point(.) and automatically replaced them with underscores(_)

39
  Please refer to [OpenTSDB Telnet API](http://opentsdb.net/docs/build/html/api_telnet/put.html) for more details.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

## Examples

<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="Node.js" value="nodejs">
    <NodeTelnet />
  </TabItem>
  <TabItem label="C#" value="csharp">
    <CsTelnet />
  </TabItem>
  <TabItem label="C" value="c">
    <CTelnet />
  </TabItem>
</Tabs>

64
2 STables will be created automatically and each STable has 4 rows of data in the above sample code.
65 66 67 68 69

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

70
taos> show stables;
71 72
              name              |
=================================
73 74
 meters_current                 |
 meters_voltage                 |
75 76
Query OK, 2 row(s) in set (0.002544s)

77
taos> select tbname, * from `meters_current`;
wmmhello's avatar
wmmhello 已提交
78
             tbname             |           _ts            |           _value           | groupid |            location            |
79
==================================================================================================================================
80 81
 t_0e7bcfa21a02331c06764f275... | 2022-03-28 09:56:51.249 |              10.800000000 | 3       | California.LosAngeles                |
 t_0e7bcfa21a02331c06764f275... | 2022-03-28 09:56:51.250 |              11.300000000 | 3       | California.LosAngeles                |
G
gccgdb1234 已提交
82 83
 t_7e7b26dd860280242c6492a16... | 2022-03-28 09:56:51.249 |              10.300000000 | 2       | California.SanFrancisco               |
 t_7e7b26dd860280242c6492a16... | 2022-03-28 09:56:51.250 |              12.600000000 | 2       | California.SanFrancisco               |
84 85
Query OK, 4 row(s) in set (0.005399s)
```
86

wmmhello's avatar
wmmhello 已提交
87
## Query Examples
88

89
If you want query the data of `location=California.LosAngeles groupid=3`, here is the query SQL:
90 91

```sql
92
SELECT * FROM `meters_current` WHERE location = "California.LosAngeles" AND groupid = 3;
93
```