Giter Club home page Giter Club logo

zbx_nginx_template's Introduction

zbx_nginx_template

Zabbix template for Nginx (python)

It's accumulate nginx stats and parse the access.log (just pice of log at once) and push result in Zabbix through trap-messages

System requirements

  • python
  • nginx with configured http_stub_status_module and access.log

What's logging:

  • Request\sec
  • Response codes (200,301,302,403,404,500,503)\min
  • Active\Keepalive connections
  • Header and body reading
  • Accepted, handled connections

Install

  1. Put zbx_nginx_stats.py into your scripts path (like: /etc/zabbix/script/nginx/) on your Zabbix agent hosts.

  2. Change next section in zbx_nginx_stats.py, to your configuration:

zabbix_host = '127.0.0.1'   # Zabbix server IP
zabbix_port = 10051         # Zabbix server port
hostname = 'Zabbix Agent'   # Name of monitored host, like it shows in zabbix web ui
time_delta = 1              # grep interval in minutes

# URL to nginx stat (http_stub_status_module)
stat_url = 'https://nginx.server/nginx_stat'

# Nginx log file path
nginx_log_file_path = '/var/log/nginx/access.log'

# Optional Basic Auth
username = 'user'
password = 'pass'

# Temp file, with log file cursor position
seek_file = '/tmp/nginx_log_stat'
  1. In script path (/etc/zabbix/script/nginx/) do:
chmod +x zbx_nginx_stats.py
  1. Configure cron to run script every one minute:
$ sudo crontab -e

*/1 * * * * /etc/zabbix/script/nginx/zbx_nginx_stats.py
  1. Import zbx_nginx_template.xml into zabbix in Tepmplate section web gui.

  2. Add the following configurations to you Nginx configuration file.

location /nginx_stat {
  stub_status on;       # Turn on nginx stats
  access_log   off;     # We do not need logs for stats
  allow 127.0.0.1;      # Security: Only allow access from IP
  allow ::1;            # Security IPv6: allow only from localhost
  deny all;             # Deny requests from the other of the world
}

That is all :)

zbx_nginx_template's People

Contributors

adubkov avatar bryant1410 avatar enyman avatar geekpete avatar junwei-wang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zbx_nginx_template's Issues

Error while sending data to Zabbix

I have Zabbix server 3.0 and your script zbx_nginx_stats.py show me this error - "Error while sending data to Zabbix". How can i fix this?

Unsupported

Hello,
Would you help me?
You are presenting this error message:

zabbix_agentd -t nginx[waiting,http://127.0.0.1/nginx_status]
nginx[waiting,http://127.0.0.1/nginx_status] [m|ZBX_NOTSUPPORTED] [Unsupported item key.]

In the web interface page shows the figures.
In Zabbix Server informs that the Key is Not supported;

Thanks

zbx_nginx_stats.py isn't outputting

hi I'm running the provide zbx_nginx_stats.py script but I'm getting the following output
I have followed the installation instructions excatly with no luck

Traceback (most recent call last):
File "./zbx_nginx_stats.py", line 176, in
data = parse_nginx_stat(data)
File "./zbx_nginx_stats.py", line 103, in parse_nginx_stat
a['accepted_connections'] = re.match(r'\s(\d*)\s(\d*)\s(\d*)', data[2], re.M | re.I).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

empty data coming to server

Hi,

Script is installed and set correctly. It works locally, meaning json is prepared with correct data. Issues starts when trying to send data to trapper:

ubuntu@ip-172-31-43-102:/usr/local/sbin$ sudo ./zbx_nginx_stats.py
{u'info': u'processed: 0; failed: 67; total: 67; seconds spent: 0.000324', u'response': u'success'}

/failed - what does it mean?/

On server side I can see "empty" msg:

12771:20161026:212719.109 __zbx_zbx_setproctitle() title:'trapper #3 [processing data]'
 12771:20161026:212719.109 trapper got ''
 12771:20161026:212719.109 __zbx_zbx_setproctitle() title:'trapper #3 [processed data in 0.000021 sec, waiting for connection]'

Data is not defined

Hi,

I use nginx on FreeBSD 10-3 i386 with Python 3.5.
I am trying to install zbx_nginx_template for monitoring. But I am in error in script zbx_nginx_stats.py

Traceback (most recent call last):
   File "./zbx_nginx_stats.py", line 185, in
     for i in date:
NameError: name 'data' is not defined

Could you help me?

Multiple vhosts

Hey. Apologize for opening a issue when your script works perfectly. I would like to know if there's a simple way to adapt it to monitor multiple log files on the same server. I have an independent access log file per virtual host. Thanks.

Username And Pass Problem

hi
i do everything all of in install step but i have problem with username and password.
what means this?
i can't understand
Please Help me

no res_code

Hi

I'm using your python script and I have no res_code sent to my zabbix server.
Can you help me to debug it ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.