The Nginx monitoring request lua script sends a report to the server through udp when the response status code is not 200. Monitor. lua [plain] ---- ConfigNginx. conf: ---- set $ str $ uri; -- content_by_lua_file; ---- location/proxy {... the Nginx monitoring request lua script sends a report to the server through udp when the response status code is not 200. Monitor. lua [plain] -- Config Nginx. conf: -- set $ str $ uri; -- content_by_lua_file; -- location/proxy {-- proxy_pass http: // {your-server} $ str; --} -- Extends int to 4 byte -- function pad32bit (num) local hex = "" local rem = num for I = 256 do local bit = rem % rem = math. floor (rem/256) hex = hex .. string. char (bit) end return hex end local url = ngx. var. uri local res = ngx. loca Tion. capture ("/proxy", {vars = {str = url}) -- Response ngx. say (res. body) -- Send udp message if res. status ~ = 200 then -- Protocol -- Length | version | Top-Level no (4) | Second-Level no | json body -- local mydata = require "mydata" -- local udpsock = mydata: socket () local udpsock = ngx. socket. udp () udpsock: settimeout (0) local OK, err = udpsock: setpeername ("224.3.29.71", 10000) local body = "host :".. ngx. var. host .. ", url :".. url .. ", status :".. res. status local leng = 4 + 3 + string. len (body) local msg = pad32bit (leng ).. "\ 1 \ 4 \ 1 ".. body ngx. say (" ") Local OK, err = udpsock: send (msg) end Nginx. conf [plain] upstream web {server 127.0.0.1: 8080; server 127.0.0.1: 8081;} server {listen 80; server_name localhost; # charset KOI8-R; location/{root html; index index.html index.htm; set $ str $ uri; content_by_lua_file/home/hailin/monitor. lua;} location/proxy {resolver 8.8.8.8; proxy_pass http: // web $ str ;}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service