NGINX is a free, open source, and high-performance server that serves as an HTTP server and a reverse proxy. You can perform tracing analysis on NGINX to better monitor the status of your applications. This topic describes how to perform tracing analysis on NGINX.
Prerequisites
- Log on to the Tracing Analysis console.
- In the left-side navigation pane, click Cluster Configurations. Then, click the Access point information tab.
- In the top navigation bar, select a region. In the Cluster Information section, turn on Show Token.
- In the Client section, click Jaeger or Zipkin.
Obtain an endpoint of Jaeger or Zipkin in the Related Information column of the table in the lower part.
Note If your application is deployed in an Alibaba Cloud production environment, use a private endpoint. Otherwise, use a public endpoint. Generally, use the endpoint of v2 for Zipkin. Use the endpoint of v1 only if you know Zipkin well.
Overview
If a slow response occurs in a microservice that uses NGINX as a proxy, you cannot estimate the impact of the slow response because no data is collected. In this case, you can use Tracing Analysis to trace NGINX requests for the microservice and calculate the number of page views that are affected by the slow response.
Deploy and trace NGINX in a Docker container
- Download, build, and then deploy a Dockerfile.
wget https://arms-apm.oss-cn-hangzhou.aliyuncs.com/demo/nginx-zipkin-docker.tgz tar -xzvf nginx-zipkin-docker.tgz cd nginx-zipkin // Build the Dockerfile. docker build --rm --tag nginx-zipkin:0.1
- Run Docker.
docker run --rm -p 80:80 -e "COLLECTOR_HOST=${ZIPKIN_ENDPOINT}?" -d nginx-zipkin:0.1
Set the
${ZIPKIN_ENDPOINT}
variable to the version 1 endpoint of Zipkin that you copy in Prerequisites, but remove "http://" and suffix the value with a question mark (?).Example:
docker run --rm -p 80:80 -e "COLLECTOR_HOST=tracing-analysis-dc-hz.aliyuncs.com/adapt_123@abc_456@efg/api/v1/spans?" -d nginx-zipkin:0.1
Deploy and trace NGINX on an ECS instance
- Install NGINX.
- Install OpenTracing.
- Use Zipkin to perform tracing analysis.
Deploy and trace NGINX on other environments
- Pull an image from Container Registry.
sudo docker pull registry.cn-hangzhou.aliyuncs.com/public-community/nginx-zipkin:0.1
- Run NGINX in a Docker container.
docker run --rm -p 80:80 -e "COLLECTOR_HOST=${ZIPKIN_ENDPOINT}?" -d registry.cn-hangzhou.aliyuncs.com/public-community/nginx-zipkin:0.1
Set the
${ZIPKIN_ENDPOINT}
variable to the version 1 endpoint of Zipkin that you copy in Prerequisites, but remove "http://" and suffix the value with a question mark (?).Example:
docker run --rm -p 80:80 -e "COLLECTOR_HOST=tracing-analysis-dc-hz.aliyuncs.com/adapt_******_******/api/v1/spans?" -d registry.cn-hangzhou.aliyuncs.com/public-community/nginx-zipkin:0.1
- Go to the NGINX page by using a browser. Enter localhost/nginx.conf or curl "localhost/nginx.conf" in the address bar of a browser to go to the NGINX page.
- View the trace data of NGINX. Log on to the Tracing Analysis console to view the trace data of the nginx-zipkin application.
Check the result
Wait for a moment. Then, log on to the Tracing Analysis console. If monitoring data appears, the tracing is successful.