Giter Club home page Giter Club logo

ngx_http_pinba_module's Introduction

Pinba module for nginx

What

This is a Pinba module for nginx. It sends statistics packets by UDP that are received and processed by Pinba server to be accessible through MySQL interface. See http://pinba.org for more details on how Pinba works.

Why

Because PHP stats are simply not enough and we want to see some more info directly from nginx servers. HTTP status codes stats were among the main reasons, but there is a lot more data than that. And more data means more nice graphs, yay!

Pre-requisites

nginx sources, C compiler.

Installation

Add this to your nginx configure line:

--add-module=/path/to/ngx_http_pinba_module.git/

and then do make install.

Configuration options

All configuration options must be added to the http {} section of the config file, but you can always modify them in location/server sections.

pinba_enable - on/off. The module is disabled by default.

pinba_server - the adress of Pinba server.
Should be a valid host:port or ip_address:port combination. You can add several of these separated by space. In that case the same data will be sent to all of these.

pinba_ignore_codes - a list of HTTP status codes.
Can be comma separated list or comma separated ranges of codes or both.
No data packet will be sent if a request is finished with a final status from the list.

Example:
pinba_ignore_codes 200-399,499;

Make sure there are no spaces between the values, though.

pinba_buffer_size - integer number.
In general case you don't need this option.
And to use it you'll have to upgrade Pinba server to the latest version first.
That said, you might want to prevent nginx overloading your network by sending tons of packets, especially if you have a heavy loaded server. So the module can keep the data in the buffer and will send it only when there is no free space left the buffer. You'll have to tweak this value yourself, I can only say that Pinba packet size depends mostly on the URLs that are requested and in general case is less than 100 bytes.

$pinba_request_uri - variable. Use this variable to specify custom script name value, the module always checks if this variable is defined and if it is, uses it. The default value is nginx $request_uri variable without its GET parameters.

$pinba_hostname - variable. Use this variable to specify custom hostname value, the module always checks if this variable is defined and if it is, uses it. The default value is the result of gethostname() function.

$pinba_request_schema - variable. Use this variable to specify custom HTTP schema, the module always checks if this variable is defined and if it is, uses it. The default value is detected this way:

if (r->connection->ssl) {
	/* schema = "https" */
} else {
	/* schema = "http" */
}

$pinba_resolve_freq - integer (seconds). Resolve frequency for pinba server hostname. The module will try to re-resolve the hostname each N seconds to make sure it's up to date. Default value: 60 seconds.

Request tags

You can use request tags for tagging requests in the following way:

pinba_tag country US;
pinba_tag ua firefox;

Each request may feature an arbitrary number of tags, which could be using to create filtered reports in Pinba (say, a report showing User-Agent distribution only for US, as in the example).

Timers

Timers provide a way to measure how much time it took to execute a certain part of the code. nginx, of course, doesn't have access to your code and cannoe measure it automatically, but you can set the timer's value manually. To do this, use the following syntax:

pinba_timer 1.25 3 {
	server $hostname;
	group db;
}

This will create new timer with a value = 1.25 sec, hit count = 3, and 3 tags: server, group with the appropriate values. Variables are allowed for all parameters:

pinba_timer $timer_value {
	$tag $value;
}

Hit count is optional and set to 1 by default.

ngx_http_pinba_module's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx_http_pinba_module's Issues

cc1: warnings being treated as errors

Hello!
The current version produces errors when compiling (with new ngx_http_pinba_module.o):

cc1: warnings being treated as errors
/usr/local/src/ngx_http_pinba_module/ngx_http_pinba_module.c: In function ‘ngx_pinba_prepare_tag’:
/usr/local/src/ngx_http_pinba_module/ngx_http_pinba_module.c:342: error: missing braces around initializer
/usr/local/src/ngx_http_pinba_module/ngx_http_pinba_module.c:342: error: (near initialization for ‘tmp_tag.name’)
/usr/local/src/ngx_http_pinba_module/ngx_http_pinba_module.c:342: error: missing initializer
/usr/local/src/ngx_http_pinba_module/ngx_http_pinba_module.c:342: error: (near initialization for ‘tmp_tag.name_len’)
/usr/local/src/ngx_http_pinba_module/ngx_http_pinba_module.c: In function ‘ngx_pinba_prepare_timer’:
/usr/local/src/ngx_http_pinba_module/ngx_http_pinba_module.c:376: error: missing initializer
/usr/local/src/ngx_http_pinba_module/ngx_http_pinba_module.c:376: error: (near initialization for ‘tmp_timer.hit_count’)
make[1]: *** [objs/addon/ngx_http_pinba_module/ngx_http_pinba_module.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory `/usr/local/src/nginx-1.7.11'
make: *** [build] Error 2

Version nginx 1.7.11
Previos version ngx_http_pinba_module compiled successfully

compilation error

centos 7.4.1708
nginx-1.12.2
gcc 4.8.5

/root/ngx_http_pinba_module/ngx_http_pinba_module.c: In function 'ngx_http_pinba_server':
/root/ngx_http_pinba_module/ngx_http_pinba_module.c:776:16: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
for (i = 1; i < cf->args->nelts; i++) {
^
/root/ngx_http_pinba_module/ngx_http_pinba_module.c: In function 'ngx_http_pinba_handler':
/root/ngx_http_pinba_module/ngx_http_pinba_module.c:931:31: error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]
server = lcf->servers->elts + lcf->servers->size * i;
^
/root/ngx_http_pinba_module/ngx_http_pinba_module.c:1226:44: error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]
ngx_pinba_socket_t **sock = socks->elts + socks->size * i;
^
cc1: all warnings being treated as errors
make[1]: *** [objs/addon/ngx_http_pinba_module/ngx_http_pinba_module.o] Error 1
make[1]: Leaving directory `/root/nginx-1.12.2'
make: *** [build] Error 2

Steps for reproduce:

git clone https://github.com/tony2001/ngx_http_pinba_module
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --add-dynamic-module=/root/ngx_http_pinba_module
make

After this command I have gcc 7.3.1 but still have the same error:

yum -y install centos-release-scl && yum makecache && yum -y install devtoolset-7-gcc devtoolset-7-gcc-c++ && scl enable devtoolset-7 bash

Update:
ubuntu 18.04
gcc 7.3.0
the same problem

ngx_http_pinba_module.so is not binary compatible

centos 7.4.1708
nginx-1.12.2
gcc 7.3.1

nginx: [emerg] module "/usr/share/nginx/modules/ngx_http_pinba_module.so" is not binary compatible in /etc/nginx/nginx.conf:13
nginx: configuration file /etc/nginx/nginx.conf test failed

Steps for reproduce:

git clone https://github.com/tony2001/ngx_http_pinba_module
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --add-dynamic-module=/root/ngx_http_pinba_module
make
make install

config:

user www-data;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
worker_rlimit_nofile 65535;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
load_module modules/ngx_http_pinba_module.so;

events {
    worker_connections 20000;
}

http {

invalid status code value "200-399,499"

Used configuration from example https://github.com/AnchorFree/docker-nginx-pinba/blame/master/README.md#L41 for nginx error.

nginx.conf

    pinba_enable on;
    pinba_server pinba:30002;
    pinba_ignore_codes 200-399,499;

Nginx Error Log

elite-nginx    | 2018/06/19 03:00:45 [error] 1#1: [pinba] invalid status code value "200-399,499", values must not be less than 100 or greater than 599 in /etc/nginx/nginx.conf:17
elite-nginx    | nginx: [error] [pinba] invalid status code value "200-399,499", values must not be less than 100 or greater than 599 in /etc/nginx/nginx.conf:17

Some screenshots?

Hi Tony,

If not too hard could you show some differences compared to just using Pinba PHP module by adding a few screenshots or pointing to, may be, some article elsewhere which explains differences between your module and PHP one.

Thanks a lot,
Igor

pinba_enabled on; FAIL

Hi!

I have an issue with NGINx 1.3.4

nginx version: nginx/1.3.4
built by gcc 4.5.1 20101208 [gcc-4_5-branch revision 167585](SUSE Linux)
configure arguments: --with-pcre=/tmp/pcre-8.30/ --with-zlib=/tmp/zlib-1.2.7/ --with-debug --with-http_stub_status_module --add-module=/tmp/ngx_http_pinba_module-201112281455/

My nginx.conf contains

pinba_enabled on;
pinba_server 192.168.0.113:3300;

in http{} section but I getting an error:

nginx: [emerg] unknown directive "pinba_enabled" in /usr/local/nginx/conf/nginx.conf:31

What's wrong? :(

compilation error

docker
ubuntu 18.04
nginx 1.14.0
gcc 7.3.0

apt install -y zlib1g-dev libgd-dev libxslt1-dev libgeoip-dev && \
    git clone https://github.com/tony2001/ngx_http_pinba_module && \
    wget http://nginx.org/download/nginx-1.14.0.tar.gz && tar zxvf nginx-1.14.0.tar.gz && cd nginx-1.14.0 && \
    ./configure --add-dynamic-module=/ngx_http_pinba_module --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module && \
    make

errors:

/ngx_http_pinba_module/ngx_http_pinba_module.c
In file included from /ngx_http_pinba_module/ngx_http_pinba_module.c:9:0:
/ngx_http_pinba_module/ngx_http_pinba_module.c: In function 'ngx_http_pinba_resolve_and_open_socket':
/ngx_http_pinba_module/uthash.h:441:21: error: this statement may fall through [-Werror=implicit-fallthrough=]
case 11: hashv += ( (unsigned)_hj_key[10] << 24 );

cc1: all warnings being treated as errors
make[1]: *** [objs/addon/ngx_http_pinba_module/ngx_http_pinba_module.o] Error 1
objs/Makefile:1531: recipe for target 'objs/addon/ngx_http_pinba_module/ngx_http_pinba_module.o' failed
make[1]: Leaving directory '/nginx-1.14.0'
make: *** [build] Error 2
Makefile:8: recipe for target 'build' failed

Add $pinba_hostname variable

To specify hostname in nginx config. I think it will be useful to request with same script_name across mutiple domains.

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.