diff --git a/source/tools/monitor/unity/beaver/guide/outLine.md b/source/tools/monitor/unity/beaver/guide/outLine.md index 22a77dcd9ed46f9fdd6cebba7f18815a4dd367f4..d1788e81a59a0ddf18f1454bf11aec293fb0b627 100644 --- a/source/tools/monitor/unity/beaver/guide/outLine.md +++ b/source/tools/monitor/unity/beaver/guide/outLine.md @@ -1,9 +1,11 @@ # 外部数据写入支持 -unity-mon可以作为一个独立的TSDB 数据库进行使用,支持[行协议](https://jasper-zhang1.gitbooks.io/influxdb/content/Write_protocols/line_protocol.html)写入数据,并按需完成对外数据吐出。 +unity-mon可以作为一个独立的TSDB 数据库进行使用,支持[行协议](https://jasper-zhang1.gitbooks.io/influxdb/content/Write_protocols/line_protocol.html)写入数据,并按需完成对外数据吐出,如exporter等接口。 ## 行协议格式支持情况 unity-mon 当前除了不支持时间戳,支持行协议其它所有的数据类型,包含数值和日志。写行数据时,有以下注意事项: +* 指标写入周期需要与大循环刷新周期保持一致,参考 yaml/config/freq 参数配置; + * 不要将同一表名和同一索引,但数值不同的数据放在同一批次写入操作中,会发生时序数据覆盖,如; ``` @@ -18,7 +20,7 @@ talbe_a,index=table_a value1=1,value2=2 talbe_a,index=table_b value1=3,value2=4 ``` -不要出现同一张表,但是写入的索引和数值不的情况,如: +* 不要出现同一张表,但是写入的索引和数值不的情况,如: ``` talbe_a,index=table_a value1=1 @@ -34,7 +36,7 @@ unity-mon 同时支持管道和http post 两种方式进行写入,两者差别 | --- | --- | --- | | 适用范围 | 内部 | 内部 + 外部 | | 写入效率 | 高 | 低 | -| 最大写入数据长度 | 64K | 2M | +| 最大单次写入数据长度 | 64K | 2M | 使用者可以结合自己的实际情况进行推送 diff --git a/source/tools/monitor/unity/beaver/url_api.lua b/source/tools/monitor/unity/beaver/url_api.lua index e54fa5c3d1b8a03b69e7a6b0237edbae0e4c5f9d..47389f6b62f50270bd5694a1fdf27054caaa33cc 100644 --- a/source/tools/monitor/unity/beaver/url_api.lua +++ b/source/tools/monitor/unity/beaver/url_api.lua @@ -45,11 +45,11 @@ local function reqOSS(oss, uuid, stream) end function CurlApi:oss(tReq) - local stat, tJson = pcall(self.getJson, self, tReq) - if stat and tJson then - local uuid = tJson.uuid - local stream = tJson.stream - if uuid and stream then + local uuid = tReq.header['uuid'] + local cLen = tonumber(tReq.header['content-length']) + if uuid and cLen and cLen > 0 then + local stream = tReq.data + if stream then local stat, body = pcall(reqOSS, self._oss, uuid, stream) if stat then return body @@ -57,10 +57,10 @@ function CurlApi:oss(tReq) return "bad req dns " .. body, 400 end else - return "need uuid and stream arg.", 400 + return "need stream arg.", 400 end else - return "bad dns " .. tReq.data, 400 + return "need uuid and content-length > 0." .. tReq.data, 400 end end diff --git a/source/tools/monitor/unity/test/curl/postOSS.lua b/source/tools/monitor/unity/test/curl/postOSS.lua index 8d37e291ee5d97335d751b9170b9abc775b1e15c..dc1e78d1d2a7f10700a417319dd03df360239548 100644 --- a/source/tools/monitor/unity/test/curl/postOSS.lua +++ b/source/tools/monitor/unity/test/curl/postOSS.lua @@ -13,6 +13,10 @@ local url = "http://127.0.0.1:8400/api/oss" local file = io.open("test.bin", "rb") local content = file:read("*all") file:close() -local req = {stream = content, uuid = system:guid()} -local res = cli:postTable(url, req) +local header = { + uuid = system:guid(), + ['Content-Type'] = 'application/octet-stream', + ["Content-Length"] = #content +} +local res = cli:post(url, content, header) system:dumps(res) \ No newline at end of file diff --git a/source/tools/monitor/unity/test/curl/postOSS.py b/source/tools/monitor/unity/test/curl/postOSS.py index fb1f74da447f68f1ed856e3aa48e119e4adf9553..83074a31d0c86912791929d044e14b3c85881ca7 100644 --- a/source/tools/monitor/unity/test/curl/postOSS.py +++ b/source/tools/monitor/unity/test/curl/postOSS.py @@ -4,6 +4,8 @@ import uuid import json url = "http://127.0.0.1:8400/api/oss" -d = {"stream": "hello oss", "uuid": str(uuid.uuid4())} -res = requests.post(url, json=d) -print(res) +headers = {'Content-Type': 'application/octet-stream', 'uuid': str(uuid.uuid4())} +data = b'binary data' + +response = requests.post(url, headers=headers, data=data) +print(response)