After you use SkyWalking to instrument an application and report the trace data to the Managed Service for OpenTelemetry console, Managed Service for OpenTelemetry starts to monitor the application. Then, you can view the monitoring data of the application, such as the application topology, traces, abnormal transactions, slow transactions, and SQL analysis. This topic describes how to use the SkyWalking NGINX LUA module to perform automatic instrumentation and report the trace data of NGINX.
Prerequisites
Background information
SkyWalking is a popular application performance monitoring (APM) service developed in China. SkyWalking is designed for microservices, cloud-native architectures, and container-based architectures. Container-based architectures include Docker, Kubernetes, and Mesos. SkyWalking is also a distributed tracing system.
Before you can use SkyWalking to report Java application data to the Managed Service for OpenTelemetry console, you must instrument the application. SkyWalking provides auto-instrument agents such as Dubbo, gRPC, JDBC, OkHttp, Spring, Tomcat, Struts, and Jedis. SkyWalking also allows you to manually instrument applications based on the OpenTracing standard. This topic describes how to automatically instrument an application.
Configure the SkyWalking NGINX LUA module by using a Docker image
Use a pre-built Docker image to configure the SkyWalking NGINX LUA module.
Pull an image from Container Registry.
docker pull registry.cn-hangzhou.aliyuncs.com/public-community/skywalking-nginx-lua:0.2
Run NGINX in a Docker container.
docker run --rm -p 80:80 -e "BACKEND_URL=$skywalking-nginx-lua" -d registry.cn-hangzhou.aliyuncs.com/public-community/skywalking-nginx-lua:0.2
Replace
$skywalking-nginx-lua
with the NGINX LUA endpoint that you copy and save in Prerequisites.Example:
docker run --rm -p 80:80 -e "BACKEND_URL=http://tracing-analysis-dc-hz.aliyuncs.com/adapt_123@abc_456@efg" -d registry.cn-hangzhou.aliyuncs.com/public-community/skywalking-nginx-lua:0.2
Go to the NGINX page by using a browser.
Enter
localhost/nginx.conf
in the address bar of a browser.Run the
curl "localhost/nginx.conf"
command.
Configure the SkyWalking NGINX LUA module by using a Dockerfile
Download a Dockerfile.
wget https://arms-apm.oss-cn-hangzhou.aliyuncs.com/demo/nginx-skywalking-docker.tgz tar -xzvf nginx-skywalking-docker.tgz cd nginx-lua
Build the Dockerfile.
docker build --rm --tag skywalking-nginx-lua:0.2 .
Run Docker.
docker run --rm -p 80:80 -e "BACKEND_URL=$skywalking-nginx-lua" -d skywalking-nginx-lua:0.2
Replace
$skywalking-nginx-lua
with the NGINX LUA endpoint that you copy and save in Prerequisites.Example:
docker run --rm -p 80:80 -e "BACKEND_URL=http://tracing-analysis-dc-hz.aliyuncs.com/adapt_123@abc_456@efg" -d skywalking-nginx-lua:0.2
Go to the NGINX page by using a browser.
Enter
localhost/nginx.conf
in the address bar of a browser.Run the
curl "localhost/nginx.conf"
command.
Configure the SkyWalking NGINX LUA module on an ECS instance
In this example, CentOS 7.0 is installed on the Elastic Compute Service (ECS) instance.
Configure the runtime environment for LUA.
Install the required tools.
yum install gcc gcc-c++ kernel-devel -y yum install readline-devel -y yum install ncurses-devel -y
Download and install LUA 5.3.5.
cd /usr/local/src wget http://www.lua.org/ftp/lua-5.3.5.tar.gz tar -zxvf lua-5.3.5.tar.gz cd /usr/local/src/lua-5.3.5 && echo "INSTALL_TOP= /usr/local/lua_5.3.5" >> Makefile && make linux && make install
Download and install LuaRocks 2.2.2.
cd /usr/local/src wget http://keplerproject.github.io/luarocks/releases/luarocks-2.2.2.tar.gz tar -xzvf luarocks-2.2.2.tar.gz cd luarocks-2.2.2 ./configure --prefix=/usr/local/luarocks_2.2.2 --with-lua=/usr/local/lua_5.3.5 make build make install
Add the following lines to the /etc/profile file:
export LUA_HOME=/usr/local/lua_5.3.5 export LUAROCKS_HOME=/usr/local/luarocks_2.2.2 PATH=$PATH:$HOME/bin:$LUAROCKS_HOME/bin:$LUA_HOME/bin export PATH export LUA_PATH="$LUAROCKS_HOME/share/lua/5.3/?.lua;?.lua;;" export LUA_CPATH="$LUAROCKS_HOME/lib/lua/5.3/?.so;?.so;;"
Update the /etc/profile file.
source /etc/profile
Install LUA.
luarocks install luasocket luarocks install lua-resty-jit-uuid luarocks install luaunit luarocks install lua-cjson 2.1.0-1
Verify that LUA is installed.
luarocks list
Download and install OpenResty NGINX.
yum install pcre-devel openssl-devel gcc curl postgresql-devel cd /usr/local/src wget -c https://openresty.org/download/openresty-1.15.8.1rc2.tar.gz tar -zxvf openresty-1.15.8.1rc2.tar.gz cd openresty-1.15.8.1rc2 ./configure --prefix=/usr/local/openresty/ --with-http_stub_status_module --with-luajit --without-http_redis2_module --with-http_iconv_module --with-http_postgres_module --with-stream && gmake && gmake install export PATH=/usr/local/openresty/nginx/sbin:$PATH
Download and install the SkyWalking NGINX LUA module.
Download and decompress the installation package of the SkyWalking NGINX LUA module.
cd /usr/local/skywalking-nginx-lua wget https://mirrors.tuna.tsinghua.edu.cn/apache/skywalking/nginx-lua/0.5.0/skywalking-nginx-lua-0.5.0-src.tgz tar -xzvf skywalking-nginx-lua-0.5.0-src.tgz
Modify the lua_package_path and startBackendTimer variables in the nginx.conf file.
Example:
Set the lua_package_path variable to
/usr/local/skywalking-nginx-lua/lib/?.lua;;
.Set the startBackendTimer variable to
require("skywalking.client"):startBackendTimer("http://tracing-analysis-dc-hz.aliyuncs.com/adapt_***")
.
Start the SkyWalking NGINX LUA module.
nginx -c /usr/local/skywalking-nginx-lua/examples/nginx.conf
View the results
Log on to the ARMS console. In the left-side navigation pane, choose . On the Application List page, click the name of the application. On the page that appears, view the trace data.
If the icon is displayed in the Language column, the application is connected to Application Monitoring. If a hyphen (-) is displayed, the application is connected to Managed Service for OpenTelemetry.