All Products
Search
Document Center

Application Real-Time Monitoring Service:Use SkyWalking to perform tracing analysis on NGINX

Last Updated:Mar 20, 2024

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

To obtain an endpoint of SkyWalking, perform the following steps:

  1. Log on to the Managed Service for OpenTelemetry console.

  2. In the left-side navigation pane, click Cluster Configurations. On the page that appears, click the Access point information tab.

  3. In the top navigation bar, select a region. In the Cluster Information section, turn on Show Token.

  4. Set the Client parameter to SkyWalking.

    Obtain an endpoint of SkyWalking in the Related Information column of the table in the lower part.

    SkyWalking接入点信息

    Note

    If your application is deployed in an Alibaba Cloud production environment, use a VPC endpoint. Otherwise, use a public endpoint.

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.

  1. Pull an image from Container Registry.

    docker pull registry.cn-hangzhou.aliyuncs.com/public-community/skywalking-nginx-lua:0.2
  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
  3. 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

  1. 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
  2. Build the Dockerfile.

    docker build --rm --tag skywalking-nginx-lua:0.2 .
  3. 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
  4. 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.

  1. Configure the runtime environment for LUA.

    1. Install the required tools.

      yum install gcc gcc-c++ kernel-devel -y
      yum install readline-devel -y
      yum install ncurses-devel -y
    2. 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
    3. 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
    4. 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;;"
    5. Update the /etc/profile file.

      source /etc/profile
    6. Install LUA.

      luarocks install luasocket
      luarocks install lua-resty-jit-uuid
      luarocks install luaunit
      luarocks install lua-cjson 2.1.0-1
    7. Verify that LUA is installed.

      luarocks list
  2. 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
  3. Download and install the SkyWalking NGINX LUA module.

    1. 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
    2. 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_***").

    3. 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 Application Monitoring > Application List. On the Application List page, click the name of the application. On the page that appears, view the trace data.

Note

If the Java图标 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.