关于OpenTSDB的Writing Data数据写入

摘自官网:

pushing data over the Telnet or HTTP APIs, or use an existing tool with OpenTSDB support such as 'tcollector'.

 

所有数据可以通过 telent,http apti,和自身支持的tcollecotr 收集到

 

 

 

Telnet:

 
The easiest way to get started with OpenTSDB is to open up a terminal or telnet client, connect to your TSD and issue a  put  command and hit 'enter'. If you are writing a program, simply open a socket, print the string command with a new line and send the packet.

 

最简单的莫过于使用 telnet put数据了 (功能较少,一般做测试用吧)

Each put can only send a single data point. Don't forget the newline character, e.g. \n at the end of your command

每个点只能接受到一条put的数据

 

For example:

 

 

 

 

put <metric> <timestamp> <value> <tagk1=tagv1[ tagk2=tagv2 ...tagkN=tagvN]>
 
 
put sys.cpu.user 1356998400 42.5 host=webserver01 cpu =0
 

Note

The Telnet method of writing is discouraged as it doesn't provide a way of determining which data points failed to write due to 

formatting or storage errors

但是用telent的写入失败 并不能确定是因为格式化或者存储异常造成的。

 

Http API

As of version 2.0, data can be sent over HTTP in formats supported by 'Serializer' plugins. Multiple, un-related data
points can be sent in a single HTTP POST request to save bandwidth. 
在2.0版本之后 opentsdb支持了 http api 可以批次传输数据
 
To save on bandwidth, the put API allows clients to store multiple data points in a single request. The data points do
not have to be related in any way. 
Each data point is processed individually and an error with one piece of data will not affect the storing of good data.
This means if your request has 100 data points and 1 of them has an error, 99 data points will still be written and one
will be rejected. See the Response section below for details on determining what data point was not stored,While the API  does support multiple data points per request, the API will not return until every one has been processed. That means metric  and tag names/values must be verified, the value parsed and the data queued for storage
http api允许客户端通过单个request 批次存储多个数据点的数据(包括以queue的方式per验证,解析)大量节省带宽。而且各个数据点的request状态(成功或
者失败)互不影响存储。
 
 

Example Single Data Point Put

You can supply a single data point in a request:

{
    "metric": "sys.cpu.nice",
    "timestamp": 1346846400,
    "value": 18,
    "tags": {
       "host": "web01",
       "dc": "lga"
    }
}

Example Multiple Data Point Put

Multiple data points must be encased in an array:

[
    {
        "metric": "sys.cpu.nice",
        "timestamp": 1346846400,
        "value": 18,
        "tags": {
           "host": "web01",
           "dc": "lga"
        }
    },
    {
        "metric": "sys.cpu.nice",
        "timestamp": 1346846400,
        "value": 9,
        "tags": {
           "host": "web02",
           "dc": "lga"
        }
    }
]
当然,2.0版本后的http api还增加了错误排查的机制
 

Response

By default, the put endpoint will respond with a 204 HTTP status code and no content if all data points were stored

successfully. If one or more datapoints had an error, the API will return a 400 with an error message in the content.

默认情况下 成功会返回204,如果有一条以上的错误 会返回400,更多的status code可以在官网查到

For debugging purposes, you can ask for the response to include a summary of how many data points were stored 

successfully and failed, or get details about what data points could not be stored and why so that you can fix your

client code. Also, errors with a data point will be logged in the TSD's log file so you can look there for issues.

类似于debug,http api也给出了 summary(只显示错误和成功次数) 和 details(显示详细errors)的支持。当然 tsd的log文件也能看到

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值