Created
May 5, 2019 21:09
-
-
Save relvira/df439429f9fda5c61344b32b814da660 to your computer and use it in GitHub Desktop.
NGINX send metrics for each location to statsd using Lua and UDP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location /test { | |
set $service_name test; | |
content_by_lua_block { | |
--ngx.say("Let's send some stuff to statsd") | |
local sock = ngx.socket.udp() | |
local ok, err = sock:setpeername("127.0.0.1", 8125) | |
if not ok then | |
--ngx.say("failed to connect to udpserv: ", err) | |
return | |
end | |
--ngx.say("successfully connected to udpserv!") | |
local sendok, senderr = sock:send("test.nginx.requests:1|c") | |
if not sendok then | |
--ngx.say("Well.. This is embarrasing. Send failed.") | |
return | |
end | |
--ngx.say("Send successful") | |
sock:close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment