Skip to content

Commit 97c643f

Browse files
committed
renamed statsd to dogstatsd since we support tags now
1 parent 74f4640 commit 97c643f

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use in a location stanza:
1515

1616
```
1717
local conf = { host = "127.0.0.1", port = 8125, namespace = "Lua_Stats_App", timeout = 1}
18-
local statsd_logger = require "ngx_lua_statsd"
18+
local statsd_logger = require "ngx_lua_datadog"
1919
local logger, err = statsd_logger:new(conf)
2020
2121
if err then

lib/ngx_lua_datadog.lua

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
local ngx_socket_udp = ngx.socket.udp
21
local table_concat = table.concat
32
local setmetatable = setmetatable
43

5-
local statsd_mt = {}
6-
statsd_mt.__index = statsd_mt
4+
local dogstatsd_mt = {}
5+
dogstatsd_mt.__index = dogstatsd_mt
76

8-
function statsd_mt:new(conf)
9-
local sock = ngx_socket_udp()
7+
function dogstatsd_mt:new(conf)
8+
local sock = ngx.socket.udp()
109
sock:settimeout(conf.timeout)
1110
local _, err = sock:setpeername(conf.host, conf.port)
1211
if err then
1312
return nil, "failed to connect to "..conf.host..":"..tostring(conf.port)..": "..err
1413
end
1514

16-
local statsd = {
15+
local dogstatsd = {
1716
host = conf.host,
1817
port = conf.port,
1918
socket = sock,
2019
namespace = conf.namespace
2120
}
22-
return setmetatable(statsd, statsd_mt)
21+
return setmetatable(dogstatsd, dogstatsd_mt)
2322
end
2423

25-
function statsd_mt:create_statsd_message(stat, delta, kind, sample_rate, tags)
24+
function dogstatsd_mt:create_dogstatsd_message(stat, delta, kind, sample_rate, tags)
2625
local rate = ""
2726
if sample_rate and sample_rate ~= 1 then
2827
rate = "|@"..sample_rate
@@ -47,45 +46,45 @@ function statsd_mt:create_statsd_message(stat, delta, kind, sample_rate, tags)
4746
return table_concat(message, "")
4847
end
4948

50-
function statsd_mt:close_socket()
49+
function dogstatsd_mt:close_socket()
5150
local ok, err = self.socket:close()
5251
if not ok then
5352
ngx.log(ngx.ERR, "failed to close connection from "..self.host..":"..tostring(self.port)..": ", err)
5453
return
5554
end
5655
end
5756

58-
function statsd_mt:send_statsd(stat, delta, kind, sample_rate, tags)
59-
local udp_message = self:create_statsd_message(stat, delta, kind, sample_rate, tags)
57+
function dogstatsd_mt:send_dogstatsd(stat, delta, kind, sample_rate, tags)
58+
local udp_message = self:create_dogstatsd_message(stat, delta, kind, sample_rate, tags)
6059
local ok, err = self.socket:send(udp_message)
6160
if not ok then
6261
ngx.log(ngx.ERR, "failed to send data to "..self.host..":"..tostring(self.port)..": ", err)
6362
end
6463
end
6564

66-
function statsd_mt:gauge(stat, value, sample_rate, tags)
67-
return self:send_statsd(stat, value, "g", sample_rate, tags)
65+
function dogstatsd_mt:gauge(stat, value, sample_rate, tags)
66+
return self:send_dogstatsd(stat, value, "g", sample_rate, tags)
6867
end
6968

70-
function statsd_mt:counter(stat, value, sample_rate, tags)
71-
return self:send_statsd(stat, value, "c", sample_rate, tags)
69+
function dogstatsd_mt:counter(stat, value, sample_rate, tags)
70+
return self:send_dogstatsd(stat, value, "c", sample_rate, tags)
7271
end
7372

74-
function statsd_mt:timer(stat, ms, tags)
75-
return self:send_statsd(stat, ms, "ms", nil, tags)
73+
function dogstatsd_mt:timer(stat, ms, tags)
74+
return self:send_dogstatsd(stat, ms, "ms", nil, tags)
7675
end
7776

78-
function statsd_mt:histogram(stat, value, tags)
79-
return self:send_statsd(stat, value, "h", nil, tags)
77+
function dogstatsd_mt:histogram(stat, value, tags)
78+
return self:send_dogstatsd(stat, value, "h", nil, tags)
8079
end
8180

82-
function statsd_mt:meter(stat, value, tags)
83-
return self:send_statsd(stat, value, "m", nil, tags)
81+
function dogstatsd_mt:meter(stat, value, tags)
82+
return self:send_dogstatsd(stat, value, "m", nil, tags)
8483
end
8584

86-
function statsd_mt:set(stat, value, tags)
87-
return self:send_statsd(stat, value, "s", nil, tags)
85+
function dogstatsd_mt:set(stat, value, tags)
86+
return self:send_dogstatsd(stat, value, "s", nil, tags)
8887
end
8988

90-
return statsd_mt
89+
return dogstatsd_mt
9190

0 commit comments

Comments
 (0)