Add the following configuration needs to be added to monitor the nginx configuration file
#zabbix monitoring nginx configuration LOCATION / nginx_status { stub_status ON; access_log OFF; the allow 127.0.0.1; the allow 172.17.0.8; the IP address of the server #zabbix the deny All; }
curl from the zabbix server about whether to get value
Activeconnections: the number of connections on the back-end activities initiated;
Server accepts 193 245: nginx handled a total 193,245 connections;
the Handled: successfully created 193,245 handshake;
Requests: A total of 339 165 treatment requests.
Reading: nginx client reads the header;
Writing: Nginx header is returned to the number of clients;
Waiting: Nginx request processing is completed, the connection is waiting for a next request command.
Zabbix agent monitoring script writing
[root @ Node7 ~] # vim /etc/zabbix/zabbix_agentd.d/nginx_status.sh #! / bin / bash #script to FETCH nginx statuses for Monitoring Systems #Author Tony HOST = "127.0.0.1" PORT = "80" function ping {# process for detecting the presence or absence nginx / sbin / nginx pidof | WC the -l } function active {# value for extracting active status in the / usr / bin / curl "http : // $ HOST: $ PORT / nginx_status / "2> / dev / null | grep 'the Active' | awk '{} of NF Print $' } function for extracting the status # {reading the reading the value / usr / bin / curl" http : // $ HOST: PORT $ / nginx_status / "2> / dev / null | grep 'Reading' | awk 'Print $ {2}' } function {# Writing Writing status value is used to extract / usr / bin / curl "HTTP: // $ the HOST: PORT $ / nginx_status /" 2> / dev / null | grep 'Writing' | awk '{}. 4 Print $' / usr / bin / curl "http : // $ HOST: $ PORT / nginx_status /" 2>/ dev / null | == NR awk. 3 | awk '{}. 3 Print $' } $ #. 1 to calling the corresponding function by the first value of the location parameterWriting' | awk '{print $4}' } function waiting {# status of waiting for extracting the value / usr / bin / curl "http : // $ HOST: $ PORT / nginx_status /" 2> / dev / null | grep 'Waiting' | awk '{print $ 6} ' } function accepts values {# accepts status for extracting the / usr / bin / curl "http : // $ HOST: $ PORT / nginx_status /" 2> / dev / null | awk NR == 3 | awk' { } $. 1 Print ' } function for extracting the status handled {# handled in value / usr / bin / curl "http : // $ HOST: $ PORT / nginx_status /" 2> / dev / null | awk NR == 3 | awk 'Print $ {2}' } function {# Requests for extracting the status request value [root @ node7 ~] # chmod a + x nginx_status.sh
Write nginx monitored item configuration file
[root@node7 ~]# cat /etc/zabbix/zabbix_agentd.d/nginx_status.conf UserParameter=nginx.status[*],/etc/zabbix/zabbix_agentd.d/nginx_status.sh $1
Open the custom parameters in zabbix_agent.conf
[root@node7 ~]# cat /etc/zabbix/zabbix_agentd.conf PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Server=172.17.0.8 ServerActive=172.17.0.8 Hostname=172.17.0.8 Include=/etc/zabbix/zabbix_agentd.d/*.conf UnsafeUserParameters=1 //1代表允许,0代表关闭
Restart zabbix-agent
systemctl restart zabbix-agent
On zabbix server test was successful
[root@node7 ~]# zabbix_get -s 172.17.0.8 -k nginx.status[ping] 1 [root@node7 ~]# zabbix_get -s 172.17.0.8 -k nginx.status[accepts] 193172 [root@node7 ~]# zabbix_get -s 172.17.0.8 -k nginx.status[handled] 193176 [root@node7 ~]# zabbix_get -s 172.17.0.8 -k nginx.status[requests] 339029