Openresty: Linux load average


/usr/local/openresty/nginx/conf/nginx.conf

		location = /api/loadaverage {
            add_header 'Content-Type' 'text/plain';
            content_by_lua_block {			
				 
				local file = "/proc/loadavg"
				local f = io.open(file, "rb")
				if f == nil then
					ngx.say()
					return
				end
				
				local content = f:read("*all")
				f:close()
				
				local l = string.sub( content, 1, 14 ) 
				ngx.say(l)
			}			
        }

Example: http://162.250.190.40/api/loadaverage

1.15 1.26 0.59

Leave a Reply