Get the App
SLTechnology News&Howtos  ›  Servers  › 

Zabbix monitors the configuration of nginx

Shulou Source: shulou.com Published: 2022-06-01 10:49:06 10月02日 Update

This article mainly explains "the configuration of zabbix monitoring nginx". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the configuration of zabbix monitoring nginx.

I. modify the configuration

Modify the nginx configuration file and add this configuration at the end. In fact, php and nginx are configured together and taken out separately for scripting.

Server {listen 127.0.0.1 server_name 80; server_name 127.0.0.1; location / nginx_status {stub_status on; access_log off; allow 127.0.1; deny all } # location ~ ^ / (phpfpm_status) ${# include fastcgi_params; # fastcgi_pass 127.0.0.1 include fastcgi_params; 9000; # fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; #}}

2. Restart nginx

# service nginx restart

Third, configure the monitoring extension

For the monitored host, add this to the zabbix_agentd.conf file:

UserParameter=nginx [*], / etc/zabbix/scripts/nginx_status.py $1

4. Place the script in the / etc/zabbix/scripts/ directory

Chmod + x nginx_status.py

5. Script

#! / usr/bin/env python#__*__coding:utf8__*__import urllib2,sys Osdef Nginx_status (): nginx_stats_dirt = {} nginx_url = "http://127.0.0.1/nginx_status" req = urllib2.Request (nginx_url) response = urllib2.urlopen (req) request_list = response.read (). Split ("\ n ") nginx_stats_dirt [" active "] = request_list [0] .split () [2] nginx_stats_dirt [" accepts "] = Request_list [2] .split () [0] nginx_stats_dirt ["handled"] = request_list [2] .split () [1] nginx_stats_dirt ["requests"] = request_list [2] .split () [2] nginx_stats_dirt ["reading"] = request_list [3] .spl it () [1] nginx_stats_dirt ["writing"] = request_list [3] .split () [3] nginx _ stats_dirt ["waiting"] = request_list [3] .split () [5] if len (sys.argv) is not 2 or str (sys.argv [1]) not in nginx_stats_dirt.keys (): print "Usage: nginx_stauts.py $1 {active | accepts | handled | reading | writing | waiting}" exit (1) else: print nginx_stats_ dirt [str (sys.argv [1])] if _ _ name__ = ='_ main_ _': try: Nginx_status () except urllib2.URLError E: print "% s there may be something wrong with nginx!"% e Thank you for your reading. The above is the content of "zabbix monitoring nginx configuration". After the study of this article, I believe you have a deeper understanding of the configuration of zabbix monitoring nginx, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Configuration monitoring scripts learning content files hosts that is ideas situations articles more directories knowledge knowledge points articles follow questions practice push Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information macOS Redmi vpn