1.stub_status Module installation
Use the command first to check if this module has been installed:
1 |
[root@test nginx]# ./nginx -V |
Uppercase -V will display information such as version number and module, and lowercase -v will only display version information.
If the stub_status module is already installed, the following information will be displayed.
1 |
./configure –with-http_stub_status_module |
2.Nginx configuration
Just modify the nginx configuration after installation, the configuration is as follows:
1 2 3 4 5 6 7 8 |
location /nginxerstatus { stub_status on; access_log off; allow 127.0.0.1; deny all; #auth_basic "NginxStatus"; #auth_basic_user_file conf/nginxstaus; } |
By default, there is only local access. If you want to be able to view the status remotely, you need to add a remote IP or remove “Deny all”. Encrypted files can be created using the
1 |
[root@test nginx]#htpasswd -c /usr/local/nginx/conf something |
command. After the configuration is complete, you need to restart the Nginx service.
The state configuration can only be for a certain Nginx service. Currently Nginx is unable to monitor individual sites.
3.View nginx Status
After the configuration is complete, enter http://127.0.0.1/nginxerstatus in the browser to view:
1 2 3 4 |
Active connections: 10 server accepts handled requests 858 889 1022 Reading: 1 Writing: 1 Waiting: 15 |
4.Nginx status parameter description
Active connections – the number of active connections
Server accepts handled requests — A total of 10,812,128 connections were processed, 10,565,289 handshakes were successfully created, and a total of 38,869,088 requests were processed.
There are three states for each connection:
1 |
waiting reading writing |
Reading — Reads the number of Header messages on the client. This operation simply reads the header information and immediately enters the writing state after reading, so the time is short.
Writing — The number of header information in response to the data to the client. This operation not only reads the header, but also waits for the service response, so the time is longer.
Waiting — Wait for the next connection to the next request command after the keep-alive is turned on.
Under normal circumstances, the number of waiting is relatively large, and does not indicate poor performance. On the contrary, if the number of reading + writing is more, the service may have concurrency problems.
View the number of Nginx concurrent processes:
1 |
[root@test nginx]#ps -ef | grep nginx | wc -l |
View the web server TCP connection status:
1 |
[root@test nginx]#netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' |
This article was first published by V on 2018-10-13 and can be reprinted with permission, but please be sure to indicate the original link address of the article :http://www.nginxer.com/records/monitor-the-nginx-service-status-using-stub_status/