摘自官网:
pushing data over the Telnet or HTTP APIs, or use an existing tool with OpenTSDB support such as 'tcollector'.
所有数据可以通过 telent,http apti,和自身支持的tcollecotr 收集到
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数据了 (功能较少,一般做测试用吧)
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 datapoints 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 donot 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 onewill 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 storagehttp 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 storedsuccessfully. 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文件也能看到
其他所有的api可以从官网的input methods上很容易找到,手敲不容易啊,看到点个赞吧。