-
Notifications
You must be signed in to change notification settings - Fork 1
/
influxdb.lua
65 lines (52 loc) · 1.31 KB
/
influxdb.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
62
63
64
65
local skynet = require "skynet"
local function udp_test()
local ibuf = require "influxdb.buffer"
local ok, err = ibuf.init({
host = "127.0.0.1",
port = 8089,
proto = "udp",
})
if not ok then
ERROR(err)
end
ibuf.buffer({
measurement = "foo200",
tags = {
{ foo = "bar" }
},
fields = {
{ value = 200 }
}
})
ibuf.flush()
end
local function http_test()
local i = require "influxdb.object"
--curl -i -XPOST http://localhost:8086/query --data-urlencode "q=DROP DATABASE cloudfreexiao"
local influx, err =i:new({
host = "127.0.0.1",
port = 8086,
proto = "http",
db = "cloudfreexiao",
hostname = "localhost",
})
if not influx then
skynet.error("influx init error:", err)
return
end
influx:set_measurement("foo100")
influx:add_tag("foo", "bar100")
influx:add_field("value", 100)
influx:buffer()
-- add and buffer additional data points
local ok, err = influx:flush()
if not ok then
skynet.error("influx flush", err)
return
end
skynet.error("influx flush ok")
end
return function ()
udp_test()
http_test()
end