zabbix4.2 nginx configuration monitoring service

1. Monitoring Principle

  Monitoring (--with-http_stub_status_module) from the status module

 

 

 2. Modify nginx configuration (/etc/nginx/conf.d/default.conf)

  Modified on the monitored host nginx configuration file, add the following (a location) in the configuration file, remember to restart nginx revised service:

LOCATION / nginx_status { 
                stub_status ON; 
                the allow 192.168.10.100; # indicates the host is allowed access to URL: HTTP: //192.168.10.100/nginx_status 
                the allow 192.168.10.2; 
                access_log OFF; 
        }

  

3. Add monitor script

  Add Monitoring script on nginx nginx server host (/etc/zabbix/zabbix_agent.d/nginx_status.sh, while giving the script executable permissions chmod a + x nginx_status.sh

#!/bin/bash
#Script to fetch nginx statuses for monitoring systems 
    HOST="192.168.10.100"   #IP地址为装有nginx服务的主机地址
    PORT="80"

    function ping {
        /sbin/pidof nginx | wc -l
    }

    function active {
        /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
    }
    function reading {
        /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
    }
    function writing {
        /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
    }
    function waiting {
        /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
    }
    function accepts {
        /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
    }
    function handled {
        /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
    }
    function requests {
        /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
    }
    $1

  

4. The test detects access

[root @ zabbix-server-center alertscripts] # curl http://192.168.10.100/nginx_status #IP address nginx server host address 
the Active Connections:. 1 
Server Requests the accepts the Handled 
 . 1. 1. 1 
Reading: 0 Writing: Waiting. 1: 0

  

The detection script test

  Some concepts about nginx states:

The number of active link number Active connections Nginx being processed; important 
server Nginx start now handled a total of how many connections. 
accepts Nginx now start to create a total success several times to shake hands. 
handled requests Nginx handled a total request several times. 
Reading Nginx read Header information on the number of clients. 
Writing Nginx returned to the Header count information for the client. 
Waiting Nginx has been processed resides next link is awaiting a request command, open. 
Keep-alive in the case of, Waiting this value equals the active- (reading + writing). 
Requests loss = (Number handshake - connections) can be seen, this status display request is not lost.
[root@zabbix-server-center alertscripts]# sh nginx_status.sh active
1
[root@zabbix-server-center alertscripts]# sh nginx_status.sh reading
0
[root@zabbix-server-center alertscripts]# sh nginx_status.sh writing
1
[root@zabbix-server-center alertscripts]# sh nginx_status.sh accepts
20

 

6. Modify zabbix_agentd.conf configuration file on the host with a service of nginx (/etc/zabbix/zabbix_agentd.conf) 

Review: UnsafeUserParameters equal to 1: UnsafeUserParameters = 1

 

 

 

7. Add zabbix profile, put in the /etc/zabbix/zabbix_agentd.d/ directory (profiles /etc/zabbix/zabbix_agentd.conf agent are defined in other key contains a directory) to create a profile nginx_status.conf

Add: UserParameter = nginx [*], /etc/zabbix/zabbix_agentd.d/nginx_status.sh $ 1     
                                                    # after the path is to monitor the location of the script

 

 

 

8. Restart zabbix-agent service

[root@ansible-control zabbix_agentd.d]# systemctl restart zabbix-agent.service

  

9. On zabbix server test server, whether the acquired data is normal  

[root@zabbix-server-center /]# zabbix_get -s 192.168.10.100 -p 10050 -k nginx.status[ping]
1
[root@zabbix-server-center /]# zabbix_get -s 192.168.10.100 -p 10050 -k nginx.status[requests]
2304
[root@zabbix-server-center /]# zabbix_get -s 192.168.10.100 -p 10050 -k nginx.status[accepts]
6285
[root@zabbix-server-center /]# zabbix_get -s 192.168.10.100 -p 10050 -k nginx.status[handled]
6286

 

7. Enter interface configuration monitoring template zabbix  

  (1) create a template:

 

 

   (2) adding an application set:

 

 

   (3) create a monitored item:

 

 

   (4) create multiple monitoring entries:

 

 

   (5) to create a trigger: trigger real-time monitoring of a viable state Nginx, Nginx once Dump machine, an alarm will occur.

 

 

   (6) Creating Graphics:

 

 

 

8. The host template equipped with Nginx services

 

 

 

9. Check monitor graphics

 

 

 10. If the beginning of the value is relatively small, is not conducive to view graphics, you can use ab simple stress tests (mainly requests), and then see the change in value

[root@zabbix-server-center /]# ab -n 1000 -c 1000 http://192.168.10.100:80/nginx_status
[root@zabbix-server-center /]# ab -n 1000 -c 1000 http://192.168.10.100:80/nginx_status
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.100 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx/1.17.1
Server Hostname:        192.168.10.100
Server Port:            80

Document Path:          /nginx_status
Document Length:        106 bytes

Concurrency Level:      1000
Time taken for tests:   0.331 seconds
Complete requests:      1000
Failed requests:        819
   (Connect: 0, Receive: 0, Length: 819, Exceptions: 0)
Write errors:           0
Total transferred:      253092 bytes
HTML transferred:       109092 bytes
Requests per second:    3016.63 [#/sec] (mean)
Time per request:       331.496 [ms] (mean)
Time per request:       0.331 [ms] (mean, across all concurrent requests)
Transfer rate:          745.59 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        3   31  15.1     26      69
Processing:    26   90  68.1     62     253
Waiting:        1   90  68.2     62     253
Total:         72  121  64.4     91     282

Percentage of the requests served within a certain time (ms)
  50%     91
  66%    103
  75%    109
  80%    113
  90%    239
  95%    280
  98%    282
  99%    282
 100%    282 (longest request)

  

 

 

 

  

 

Guess you like

Origin www.cnblogs.com/python-wen/p/11571036.html