Code Monkey home page Code Monkey logo

log_aggregate_for_zabbix's Introduction

log_aggregate_for_zabbix

purpose: aggregate url classified response staus from nginx log for zabbix monitor

make binary (require boost)

clang++ -l boost_date_time log_report.cc -o log_report

configuration step

assume deploy to directory /data/monit:

1, set nginx log format like this, then reload nginx:

        log_format json '{"remote_addr": "$remote_addr", "remote_user": "$remote_user", '
                '"time_iso8601": "$time_iso8601", "request": "$request", '
                '"status": $status, "body_bytes_sent": $body_bytes_sent, '
                '"request_length":  $request_length, '
                '"request_time": $request_time, "connection_requests": $connection_requests, '
                '"http_referer": "$http_referer", "http_user_agent": "$http_user_agent"}';

        access_log              /var/log/nginx/access_datacollect.log json;

2, copy log_report discover.py to this directory

3, make a configuration file like this:

{
    "log_file_name": "\/var\/log\/nginx\/access_datacollect.log",
    "last_position": "3101241185",
    "lock": "0",
    "urls": [
        "POST \/collect"
    ]
}

here

log_file_name: point to nginx log file path.

last_position: initial it to 0 (begin of the file).

lock: initial it to 0 (indicate no instance run now).

urls: list urls you care here.

4, set cron routines like this:

* * * * * /data/monit/log_report /data/monit/config.json /data/monit/log_stat.json > /dev/null 2>&1

the log_stat.json should be like:

{
    "ts": "2017-07-31T16:39",
    "POST \/collect:1xx:cnt": "0",
    "POST \/collect:1xx:avg": "0.00",
    "POST \/collect:2xx:cnt": "16012",
    "POST \/collect:2xx:avg": "22.73",
    "POST \/collect:3xx:cnt": "0",
    "POST \/collect:3xx:avg": "0.00",
    "POST \/collect:4xx:cnt": "122",
    "POST \/collect:4xx:avg": "29532.20",
    "POST \/collect:5xx:cnt": "0",
    "POST \/collect:5xx:avg": "0.00"
}    

5, add two zabbix rules to zabbix-agent like this:

UserParameter=nginx.log.requests, python3 /data/monit/discover.py /data/monit/config.json
UserParameter=nginx.log.requests.status[*], python3 -c 'import json ; print(json.loads(open("/data/monit/log_stat.json", "rt").read())["'"$1"'"])'

6, set up zabbix server to create discovery rules to monitor request status...

log_aggregate_for_zabbix's People

Watchers

James Cloos avatar cloud123 avatar

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.