GithubHelp home page GithubHelp logo

graphite-nginx-module's Introduction

graphite-nginx-module

An nginx module for collecting location stats into Graphite.

This module is not distributed with the Nginx source. See the installation instructions.

Features

  • Aggregation of location, server or http metrics
  • Calculation of percentiles
  • Sending data to Graphite over UDP or TCP in non-blocking way
  • Sending custom metrics from lua

Version

This document describes graphite-nginx-module v2.3.0 released on 21 August 2018.

Synopsis

http {
    graphite_config prefix=playground server=127.0.0.1;
    server {
        location /foo/ {
            graphite_data nginx.foo;
        }
    }
}

Description

This module use shared memory segment to collect aggregated stats from all workers and send calculated values for last minute to Graphite every 60s (default) over UDP or TCP in non-blocking way. Stats aggegation made on the fly in fixed size buffer allocated on server start and does't affect server performance.

This module is in active use on Mail.Ru Sites (one of largest web-services in Russia) for about a year and considered stable and well-tested.

To collect metrics from nginx core modules (ssl, gzip, upstream) little patch must be applied on nginx source tree. See the installation instructions. You can build this module as a dynamic one, but then you won't be able to collect metrics from nginx core modules (ssl, gzip, upstream) and lua functions.

Directives

graphite_config

syntax: graphite_config key1=<value1> key2=<value2> ... keyN=<valueN>

context: http

Specify global settings for a whole server instance.

Param Required Default Description
prefix path prefix for all graphs
host gethostname() host name for all graphs
server Yes carbon-cache server IP address
protocol udp carbon-cache server protocol (udp or tcp)
port 2003 carbon-cache server port
frequency 60 how often send values to Graphite (seconds)
intervals 1m aggregation intervals, time interval list, vertical bar separator (m - minutes)
params * limit metrics list to track, vertical bar separator
shared 2m shared memory size, increase in case of too small shared memory error
buffer 64k network buffer size, increase in case of too small buffer size error
package 1400 maximum UDP packet size
template template for graph name (default is $prefix.$host.$split.$param_$interval)
error_log path suffix for error logs graphs (*)

(*): works only when nginx_error_log_limiting*.patch is applied to the nginx source code

Example (standard):

http {
    graphite_config prefix=playground server=127.0.0.1;
}

Example (custom):

http {
    graphite_config prefix=playground server=127.0.0.1 intervals=1m|5m|15m params=rps|request_time|upstream_time template=$prefix.$host.$split.$param_$interval;
}

Example (error_log):

http {
    graphite_config prefix=playground server=127.0.0.1 error_log=log;
}

graphite_default_data

syntax: graphite_default_data <path prefix> [params=<params>] [if=<condition>]

context: http, server

Create measurement point in all nested locations. You can use "$location" or "$server" variables which represent the name of the current location and the name of current server with all non-alphanumeric characters replaced with "_." Leading and trailing "_" are deleted.

Example:

   graphite_default_data nginx.$location;

   location /foo/ {
   }

   location /bar/ {
   }

Data for /foo/ will be sent to nginx.foo, data for /bar/ - to nginx.bar. The <params> parameter (1.3.0) specifies list of params to be collected for all nested locations. To add all default params, use *. The <if> parameter (1.1.0) enables conditional logging. A request will not be logged if the condition evaluates to "0" or an empty string.

Example(with $server):

    graphite_default_data nginx.$server.$location

    server {
        server_name foo_host;

        location /foo/ {
        }
    }

    server {
        server_name bar_host;

        location /bar/ {
        }
    }

Data for /foo/ will be sent to nginx.foo_host.foo, data for /bar/ - to nginx.bar_host.bar.

graphite_data

syntax: graphite_data <path prefix> [params=<params>] [if=<condition>]

context: http, server, location, if

Create measurement point in specific location.

Example:

    location /foo/ {
        graphite_data nginx.foo;
    }

The <params> parameter (1.3.0) specifies list of params to be collected for this location. To add all default params, use *. The <if> parameter (1.1.0) enables conditional logging. A request will not be logged if the condition evaluates to "0" or an empty string.

Example:

    map $scheme $is_http { http 1; }
    map $scheme $is_https { https 1; }

    ...

    location /bar/ {
        graphite_data nginx.all.bar;
        graphite_data nginx.http.bar if=$is_http;
        graphite_data nginx.https.bar if=$is_https;
        graphite_data nginx.arg params=rps|request_time;
        graphite_data nginx.ext params=*|rps|request_time;
    }

graphite_param

syntax: graphite_param name=<path> interval=<time value> aggregate=<func>

context: http, server, location, if

Param Required Description
name Yes path prefix for all graphs
interval Yes* aggregation interval, time intrval value format (m - minutes)
aggregate Yes* aggregation function on values
percentile Yes* percentile level

aggregate functions

func Description
sum sum of values per interval
persec sum of values per second (sum divided on seconds in interval)
avg average value on interval
gauge gauge value

Example: see below.

Nginx API for Lua

syntax: ngx.graphite.param(<name>)

Get a link on a graphite parameter name, to use it in place of the name for the functions below. The link is valid up to nginx reload. After getting the link of a parameter, you can still pass the parameter name to the functions below. You can get the link of a parameter multiple times, you'll always get the same object by the same name (a lightuserdata). The function returns false if the parameter specified by name doesn't exist. The function returns nil on link getting errors. Functions access parameters information by link faster than by name.

Available after applying patch to lua-nginx-module. The feature is present in the patch for lua module v0.10.12. See the installation instructions.

syntax: ngx.graphite(<name_or_link>,<value>[,<config>])

Write stat value into aggregator function. Floating point numbers accepted in value.

Available after applying patch to lua-nginx-module. See the installation instructions.

ngx.graphite(name, value, config)

Example:

location /foo/ {
    graphite_param name=lua.foo_sum aggregate=sum interval=1m;
    graphite_param name=lua.foo_rps aggregate=persec interval=1m;
    graphite_param name=lua.foo_avg aggregate=avg interval=1m;
    graphite_param name=lua.foo_gauge aggregate=gauge;

    content_by_lua '
        ngx.graphite("lua.foo_sum", 0.01)
        ngx.graphite("lua.foo_rps", 1)
        ngx.graphite("lua.foo_avg", ngx.var.request_uri:len())
        local foo_gauge_link = ngx.graphite.param("lua.foo_gauge")
        ngx.graphite(foo_gauge_link, 10)
        ngx.graphite(foo_gauge_link, -2)
        ngx.graphite("lua.auto_rps", 1, "aggregate=persec interval=1m percentile=50|90|99")
        ngx.say("hello")
    ';
}

You must either specify the graphite_param command or pass the config argument. If you choose the second option, the data for this graph will not be sent until the first call to ngx.graphite.

Warning: If you do not declare graph using graphite_param command then memory for the graph will be allocated dynamically in module's shared memory. If module's shared memory is exhausted while nginx is running, no new graphs will be created and an error message will be logged.

syntax: ngx.graphite.get(<name_or_link>)

Get value of the gauge param with specified name_or_link.

syntax: ngx.graphite.set(<name>,<value>)

Set value to the gauge param with specified name_or_link.

Params

Param Units Func Description
request_time ms avg total time spent on serving request
bytes_sent bytes avg http response length
body_bytes_sent bytes avg http response body length
request_length bytes avg http request length
ssl_handshake_time ms avg time spent on ssl handsake
ssl_cache_usage % last how much SSL cache used
content_time ms avg time spent generating content inside nginx
gzip_time ms avg time spent gzipping content ob-the-fly
lua_time ms avg time spent on lua code
upstream_time ms avg time spent tailking with upstream
upstream_connect_time ms avg time spent on upstream connect (nginx >= 1.9.1)
upstream_header_time ms avg time spent on upstream header (nginx >= 1.9.1)
upstream_response_2xx_rps rps sum total upstream responses number with 2xx code (nginx >= 1.9.1)
upstream_response_3xx_rps rps sum total upstream responses number with 3xx code (nginx >= 1.9.1)
upstream_response_4xx_rps rps sum total upstream responses number with 4xx code (nginx >= 1.9.1)
upstream_response_5xx_rps rps sum total upstream responses number with 5xx code (nginx >= 1.9.1)
upstream_response_[0-9]{3}_rps rps sum total upstream responses number with given code (nginx >= 1.9.1)
rps rps sum total requests number per second
keepalive_rps rps sum requests number sent over previously opened keepalive connection
response_2xx_rps rps sum total responses number with 2xx code
response_3xx_rps rps sum total responses number with 3xx code
response_4xx_rps rps sum total responses number with 4xx code
response_5xx_rps rps sum total responses number with 5xx code
response_[0-9]{3}_rps rps sum total responses number with given code
upstream_cache_(miss|bypass|expired|stale|updating|revalidated|hit)_rps rps sum totar responses with a given upstream cache status

Percentiles

To calculate percentile value for any parameter, set percentile level via /. E.g. request_time/50|request_time/90|request_time/99.

Installation

Requirements

  • nginx: 1.2.0 - 1.14.x
  • lua-nginx-module: 0.8.6 - 0.10.13 (optional)

Build nginx with graphite module

wget 'http://nginx.org/download/nginx-1.9.2.tar.gz'
tar -xzf nginx-1.9.2.tar.gz
cd nginx-1.9.2/

# patch to collect ssl_cache_usage, ssl_handshake_time content_time, gzip_time, upstream_time, upstream_connect_time, upstream_header_time graphs (optional)
patch -p1 < /path/to/graphite-nginx-module/graphite_module_v1_7_7.patch

./configure --add-module=/path/to/graphite-nginx-module

make
make install

Build nginx with graphite dynamic module

wget 'http://nginx.org/download/nginx-1.9.2.tar.gz'
tar -xzf nginx-1.9.2.tar.gz
cd nginx-1.9.2/

./configure --add-dynamic-module=/path/to/graphite-nginx-module

make
make install

Build nginx with lua and graphite modules

wget 'https://github.com/chaoslawful/lua-nginx-module/archive/v0.9.16.tar.gz'
tar -xzf v0.9.16.tar.gz
cd lua-nginx-module-0.9.16/
# patch to add api for sending metrics from lua code (optional)
patch -p1 < /path/to/graphite-nginx-module/lua_module_v0_9_11.patch
cd ..

wget 'http://nginx.org/download/nginx-1.9.2.tar.gz'
tar -xzf nginx-1.9.2.tar.gz
cd nginx-1.9.2/

# patch to collect ssl_cache_usage, ssl_handshake_time content_time, gzip_time, upstream_time, upstream_connect_time, upstream_header_time graphs (optional)
patch -p1 < /path/to/graphite-nginx-module/graphite_module_v1_7_7.patch

./configure \
    --add-module=/path/to/ngx_devel_kit \
    --add-module=/path/to/lua-nginx-module \
    --add-module=/path/to/graphite-nginx-module

make
make install

Instructions on installing lua-nginx-module can be found in documentation on lua-nginx-module.

License

Copyright (c) 2013-2018, Mail.Ru Ltd.

This module is licensed under the terms of the BSD license.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

graphite-nginx-module's People

Contributors

arnej27959 avatar birdi7 avatar cooleck avatar cryptofuture avatar evan-simmons-ck avatar hexangel1 avatar kirimedia avatar lomik avatar morf avatar pansershrek avatar sorc1 avatar vchimishuk 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  avatar  avatar  avatar

graphite-nginx-module's Issues

Couldn't build with nginx 1.13.12

	-o objs/addon/src/ngx_http_graphite_module.o \
	debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_source_content_time':
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c:2785:21: error: 'ngx_http_request_t {aka struct ngx_http_request_s}' has no member named 'content_time'
     return (double)r->content_time;
                     ^
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_source_gzip_time':
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c:2791:21: error: 'ngx_http_request_t {aka struct ngx_http_request_s}' has no member named 'gzip_time'
     return (double)r->gzip_time;
                     ^
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_source_lua_time':
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c:2877:13: error: 'ngx_http_request_t {aka struct ngx_http_request_s}' has no member named 'lua_time'
     return r->lua_time;
             ^
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c:2878:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_source_gzip_time':
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c:2792:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_source_content_time':
debian/extra/graphite-nginx-module/src/ngx_http_graphite_module.c:2786:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1: all warnings being treated as errors
objs/Makefile:3843: recipe for target 'objs/addon/src/ngx_http_graphite_module.o' failed

Can't use ngx.graphite() function to send metric data

I failed to write ngx.graphite() function to send metric data. Could you give me some guide to solve it, thanks.

My environment is below

/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.10.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
built with OpenSSL 1.0.1s 1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-ipv6 --with-http_dav_module --with-debug --with-stream --with-stream_ssl_module --with-openssl=../openssl-1.0.1s --add-module=../ngx_cache_purge-2.3 --add-module=../echo-nginx-module-0.58 --add-module=../nginx-http-auth-digest-master --with-ld-opt='-Wl,-rpath,/usr/local/luajit/lib /usr/local/src/gc.lua/mydata.o' --add-dynamic-module=../ngx_devel_kit-0.3.0 --add-dynamic-module=../lua-nginx-module-0.10.6 --add-dynamic-module=../graphite-nginx-module-1.1.0

nginx.conf

location /code {
graphite_param name=lua.abc aggregate=sum interval=10s;
content_by_lua_block {
ngx.graphite("lua.abc", 0.01)
ngx.say("hello")
}
}

Error messages below:
2016/09/22 18:44:22 [debug] 1879#0: *1 lua run thread, top:0 c:1
2016/09/22 18:44:22 [debug] 1879#0: *1 lua resume returned 2
2016/09/22 18:44:22 [error] 1879#0: *1 lua entry thread aborted: runtime error: content_by_lua(rick.conf:100):2: attempt to call field 'graphite' (a nil value)
stack traceback:
coroutine 0:

empty prefix

Is it possible to use empty prefix in graphite_config?
If i set prefix='' i have ''.hostname.nginx... in graphite.

Does not connect to graphite

Was having issues before with 1.0.3 and adding the patches, but with 1.0.4 that has been resolved for me now.

However it doesn't seem like it will connect to graphite, no errors in my logs, and using tcpdump on port 2003 shows nothing happening. Let me know if I can provide any additional information to debug. Thank you.

ngx_http_graphite_ssl_session_reused breaks nginx tests

Hello,
I've noticed that this part of code breaks nginx tests

#if (NGX_SSL)
static ngx_int_t
ngx_http_graphite_ssl_session_reused(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) {

    ngx_str_t s;

    if (r->connection->requests == 1) {
        if (r->connection->ssl && SSL_session_reused(r->connection->ssl->connection)) {
            ngx_str_set(&s, "yes");
        }
        else {
            ngx_str_set(&s, "no");
        }
    }
    else {
        ngx_str_set(&s, "none");
    }

This is because nginx have the same variable $ssl_session_reused, but it has values 'r'/'.' instead of 'yes'/'no'.

Example of graphite_param in documentation only sends 0 for me

Hi,

I managed to get graphite_default_data and graphite_data working for me successfully (I can see line items being sent, and field values fluctuate based on request behaviour like as expected). When I try to set up custom parameter as shown in https://github.com/mailru/graphite-nginx-module#nginx-api-for-lua , I only see values of 0 being sent. I'm not using compiling in any additional modules into nginx besides this graphite-nginx-module and I don't see any errors in the logs, so I am really puzzled as to what might be wrong.

Thank you once again,

Is there a way to get the current aggregate value set by ngx.graphite()?

Hi.

I ran into a problem where I am trying to collect a number of concurrent requests by emitting some 1s and -1s as part of a request. However, I run into an issue that the data that gets emitted into Grafana ends up being negative due to the fact that the aggregate value gets reset.

Without going too much into detail into the problem, is there a way I can access the current value that is set by ngx.graphite() function?

Build failure with version >= 1.21.5

Привет. Пытаюсь собрать модуль со свежим nginx и напоролся на то, что не собираемся с версии 1.21.5 и больше.
Я сделал мальенький воркфлоу в гитхаб экшнс и проверил, что версии 1.21.1 - 1.21.4 собираются нормально.

Мои опции сборки (вырезано из моего большого докерфайла):

RUN ./configure \
		--user=nginx \
		--group=nginx \
		--prefix=/etc/nginx \
		--pid-path=/var/run/nginx.pid \
		--lock-path=/var/run/nginx.lock \
		--sbin-path=/usr/sbin/nginx \
		--modules-path=/usr/lib/nginx/modules \
		--conf-path=/etc/nginx/nginx.conf \
		--error-log-path=/var/log/nginx/error.log \
		--http-log-path=/var/log/nginx/access.log \
		--http-client-body-temp-path=/var/cache/nginx/client_temp \
		--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
		--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
		--with-pcre \
		--with-pcre-jit \
		--without-select_module \
		--without-poll_module \
		--without-http_ssi_module \
		--without-http_split_clients_module \
		--without-http_uwsgi_module \
		--without-http_scgi_module \
		--without-http_memcached_module \
		--without-http_empty_gif_module \
		--without-http_browser_module \
		--without-http_userid_module \
		--with-threads \
		--with-file-aio \
		--with-http_ssl_module \
		--with-http_v2_module \
		--with-http_realip_module \
		--with-http_auth_request_module \
		--with-http_sub_module \
		--with-http_secure_link_module\
		--with-http_stub_status_module \
		--with-http_dav_module \
		--with-http_realip_module \
		--with-http_addition_module \
		--with-stream=dynamic \
		--with-stream_ssl_preread_module \
		--with-stream_realip_module \
		--with-http_xslt_module=dynamic \
		--with-http_image_filter_module=dynamic \
		--with-http_geoip_module=dynamic \
		--with-compat \
		--add-dynamic-module=../ngx_http_auth_pam_module-${NGXMOD_PAM_VERSION} \
		--add-dynamic-module=../ngx_brotli-${NGXMOD_BROTLI_VERSION} \
		--add-module=../graphite-nginx-module-${NGXMOD_GRAPHITE_VERSION} \
		--add-module=../testcookie-nginx-module-${NGXMOD_TSTCK_VERSION} \
		--add-module=../nginx-http-rdns-${NGXMOD_RDNS_VERSION} \
		--add-module=../headers-more-nginx-module-${NGXMOD_HEADMR_VERSION} \
		--with-cc-opt='-O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'

Не могу точно сказать это конфликт модулей или все же апдейт самого nginx. Исходя из чейндж лога там прикрутили PCRE по дефолту, может быть с этим связано.

Изменения в nginx 1.21.5                                          28.12.2021

    *) Изменение: теперь nginx по умолчанию собирается с библиотекой PCRE2.

    *) Изменение: теперь nginx всегда использует sendfile(SF_NODISKIO) на
       FreeBSD.

    *) Добавление: поддержка sendfile(SF_NOCACHE) на FreeBSD.

    *) Добавление: переменная $ssl_curve.

    *) Исправление: при использовании HTTP/2 без SSL вместе с директивами
       sendfile и aio соединения могли зависать.

Вот сам лог с ошибкой:

2022-03-13T20:15:17.5216749Z #22 35.11 	-o objs/addon/src/ngx_http_graphite_module.o \
2022-03-13T20:15:17.5217196Z #22 35.11 	../graphite-nginx-module-3.1/src/ngx_http_graphite_module.c
2022-03-13T20:15:17.8217463Z #22 35.43 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wno-deprecated-declarations  -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/include -I /usr/include/libxml2 -I objs -I src/http -I src/http/modules -I src/http/v2 -I ../graphite-nginx-module-3.1/src -I src/stream \
2022-03-13T20:15:17.8218534Z #22 35.43 	-o objs/addon/src/ngx_http_graphite_net.o \
2022-03-13T20:15:17.8218986Z #22 35.43 	../graphite-nginx-module-3.1/src/ngx_http_graphite_net.c
2022-03-13T20:15:17.9284531Z #22 35.59 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wno-deprecated-declarations  -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/include -I /usr/include/libxml2 -I objs -I src/http -I src/http/modules -I src/http/v2 -I ../graphite-nginx-module-3.1/src -I src/stream \
2022-03-13T20:15:17.9285638Z #22 35.59 	-o objs/addon/src/ngx_http_testcookie_access_module.o \
2022-03-13T20:15:17.9286145Z #22 35.59 	../testcookie-nginx-module-master/src/ngx_http_testcookie_access_module.c
2022-03-13T20:15:18.0788225Z #22 35.60 ../graphite-nginx-module-3.1/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_get_source':
2022-03-13T20:15:18.0789135Z #22 35.60 ../graphite-nginx-module-3.1/src/ngx_http_graphite_module.c:1963:42: error: passing argument 2 of 'ngx_regex_exec' discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
2022-03-13T20:15:18.0789702Z #22 35.60  1963 |             if (ngx_regex_exec(rc.regex, name, NULL, 0) >= 0)
2022-03-13T20:15:18.0790010Z #22 35.60       |                                          ^~~~
2022-03-13T20:15:18.0790290Z #22 35.60 In file included from src/core/ngx_core.h:73,
2022-03-13T20:15:18.0791112Z #22 35.60                  from ../graphite-nginx-module-3.1/src/ngx_http_graphite_module.c:3:
2022-03-13T20:15:18.0791673Z #22 35.60 src/core/ngx_regex.h:66:54: note: expected 'ngx_str_t *' but argument is of type 'const ngx_str_t *'
2022-03-13T20:15:18.0792088Z #22 35.60    66 | ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures,
2022-03-13T20:15:18.0792412Z #22 35.60       |                                           ~~~~~~~~~~~^
2022-03-13T20:15:18.3800666Z #22 35.93 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wno-deprecated-declarations  -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/include -I /usr/include/libxml2 -I objs -I src/http -I src/http/modules -I src/http/v2 -I ../graphite-nginx-module-3.1/src -I src/stream \
2022-03-13T20:15:18.3801786Z #22 35.93 	-o objs/addon/nginx-http-rdns-master/ngx_http_rdns_module.o \
2022-03-13T20:15:18.3802265Z #22 35.93 	../nginx-http-rdns-master/ngx_http_rdns_module.c
2022-03-13T20:15:19.1319527Z #22 36.69 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wno-deprecated-declarations  -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/include -I /usr/include/libxml2 -I objs -I src/http -I src/http/modules -I src/http/v2 -I ../graphite-nginx-module-3.1/src -I src/stream \
2022-03-13T20:15:19.1320622Z #22 36.69 	-o objs/addon/src/ngx_http_headers_more_filter_module.o \
2022-03-13T20:15:19.1321165Z #22 36.69 	../headers-more-nginx-module-master/src/ngx_http_headers_more_filter_module.c
2022-03-13T20:15:19.5836912Z #22 37.17 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wno-deprecated-declarations  -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/include -I /usr/include/libxml2 -I objs -I src/http -I src/http/modules -I src/http/v2 -I ../graphite-nginx-module-3.1/src -I src/stream \
2022-03-13T20:15:19.5838004Z #22 37.17 	-o objs/addon/src/ngx_http_headers_more_headers_out.o \
2022-03-13T20:15:19.5838519Z #22 37.17 	../headers-more-nginx-module-master/src/ngx_http_headers_more_headers_out.c
2022-03-13T20:15:19.7344392Z #22 37.26 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wno-deprecated-declarations  -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/include -I /usr/include/libxml2 -I objs -I src/http -I src/http/modules -I src/http/v2 -I ../graphite-nginx-module-3.1/src -I src/stream \
2022-03-13T20:15:19.7345514Z #22 37.26 	-o objs/addon/src/ngx_http_headers_more_headers_in.o \
2022-03-13T20:15:19.7346028Z #22 37.26 	../headers-more-nginx-module-master/src/ngx_http_headers_more_headers_in.c
2022-03-13T20:15:20.0115784Z #22 37.68 cc1: all warnings being treated as errors
2022-03-13T20:15:20.1621302Z #22 37.74 make[1]: *** [objs/Makefile:1393: objs/addon/src/ngx_http_graphite_module.o] Error 1
2022-03-13T20:15:20.1621695Z #22 37.74 make[1]: *** Waiting for unfinished jobs....
2022-03-13T20:15:20.2638328Z #22 37.90 make[1]: Leaving directory '/usr/src/nginx/nginx-1.21.5'
2022-03-13T20:15:20.2638744Z #22 37.90 make: *** [Makefile:10: build] Error 2
2022-03-13T20:15:20.2639409Z #22 ERROR: process "/bin/sh -c make -j$(( `nproc` + 1 )) \t&& make DESTDIR=/usr/local/nginx install" did not complete successfully: exit code: 2
2022-03-13T20:15:20.2639810Z ------
2022-03-13T20:15:20.2640223Z  > [builder 15/18] RUN make -j$(( `nproc` + 1 )) 	&& make DESTDIR=/usr/local/nginx install:
2022-03-13T20:15:20.2640917Z #22 37.17 	-o objs/addon/src/ngx_http_headers_more_headers_out.o \
2022-03-13T20:15:20.2641424Z #22 37.17 	../headers-more-nginx-module-master/src/ngx_http_headers_more_headers_out.c
2022-03-13T20:15:20.2642854Z #22 37.26 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wno-deprecated-declarations  -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/include -I /usr/include/libxml2 -I objs -I src/http -I src/http/modules -I src/http/v2 -I ../graphite-nginx-module-3.1/src -I src/stream \
2022-03-13T20:15:20.2643891Z #22 37.26 	-o objs/addon/src/ngx_http_headers_more_headers_in.o \
2022-03-13T20:15:20.2644397Z #22 37.26 	../headers-more-nginx-module-master/src/ngx_http_headers_more_headers_in.c
2022-03-13T20:15:20.2644785Z #22 37.68 cc1: all warnings being treated as errors
2022-03-13T20:15:20.2645156Z #22 37.74 make[1]: *** [objs/Makefile:1393: objs/addon/src/ngx_http_graphite_module.o] Error 1
2022-03-13T20:15:20.2645514Z #22 37.74 make[1]: *** Waiting for unfinished jobs....
2022-03-13T20:15:20.2645934Z #22 37.90 make[1]: Leaving directory '/usr/src/nginx/nginx-1.21.5'
2022-03-13T20:15:20.2646259Z #22 37.90 make: *** [Makefile:10: build] Error 2
2022-03-13T20:15:20.2646530Z ------
2022-03-13T20:15:20.2708031Z Dockerfile:97
2022-03-13T20:15:20.2708474Z --------------------
2022-03-13T20:15:20.2708726Z   96 |     # make && make install
2022-03-13T20:15:20.2709075Z   97 | >>> RUN make -j$(( `nproc` + 1 )) \
2022-03-13T20:15:20.2777121Z   98 | >>> 	&& make DESTDIR=/usr/local/nginx install
2022-03-13T20:15:20.2778616Z   99 |     
2022-03-13T20:15:20.2782298Z --------------------
2022-03-13T20:15:20.2783184Z error: failed to solve: process "/bin/sh -c make -j$(( `nproc` + 1 )) \t&& make DESTDIR=/usr/local/nginx install" did not complete successfully: exit code: 2

При необходимости полный докерфайл и полные логи сборки можно найти тут https://github.com/MindHunter86/docker-nginx и тут https://github.com/MindHunter86/docker-nginx/actions

Заранее благодарю за фикс)

Error compiling with nginx 1.9.11+

It looks like lua-nginx-module had to do some updates to work with the nginx 1.9.11+, and it looks to have broken a few items with this module.

https://github.com/openresty/lua-nginx-module/releases/tag/v0.10.1rc1
https://github.com/openresty/lua-nginx-module/releases/tag/v0.10.1rc0

I was using 1.9.12, but same issue on 1.9.11

Lua Module Patch

patching file config
Hunk #1 FAILED at 254.
Hunk #2 FAILED at 307.
2 out of 2 hunks FAILED -- saving rejects to file config.rej

Graphite Patch

patching file src/ngx_http_lua_graphite.c
patching file src/ngx_http_lua_graphite.h
patching file src/ngx_http_lua_util.c
Hunk #1 succeeded at 51 with fuzz 2 (offset 1 line).
Hunk #2 FAILED at 685.
Hunk #3 succeeded at 754 (offset 35 lines).
1 out of 3 hunks FAILED -- saving rejects to file src/ngx_http_lua_util.c.rej

all metrics stay 0.000

Using nginx 1.10.1 (rebuilt from ppa version) on ubuntu 14

All metrics expected are sent, but their values are always 0.000
There no other sign of something being wrong.

nginx -V

nginx -V

nginx version: nginx/1.10.1
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --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 --add-dynamic-module=./debian/modules/nginx-auth-pam --add-module=./debian/modules/nginx-dav-ext-module --add-dynamic-module=./debian/modules/nginx-echo --add-dynamic-module=./debian/modules/nginx-upstream-fair --add-dynamic-module=./debian/modules/ngx_http_substitutions_filter_module --add-dynamic-module=./debian/modules/graphite-nginx-module

config:
graphite_config server=online01.alephd.com frequency=60 intervals=1m|5m|15m;

location ~ /post {
...
graphite_data nginx.post;
}

Fails to compile with ubuntu 12.04

cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/mail
-o objs/addon/src/ngx_http_graphite_module.o
../graphite-nginx-module/src/ngx_http_graphite_module.c
../graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_param_ssl_handshake_time':
../graphite-nginx-module/src/ngx_http_graphite_module.c:1402:39: error: 'ngx_ssl_connection_t' has no member named 'handshake_end_sec'
../graphite-nginx-module/src/ngx_http_graphite_module.c:1402:64: error: 'ngx_ssl_connection_t' has no member named 'handshake_start_sec'
../graphite-nginx-module/src/ngx_http_graphite_module.c:1402:100: error: 'ngx_ssl_connection_t' has no member named 'handshake_end_msec'
../graphite-nginx-module/src/ngx_http_graphite_module.c:1402:126: error: 'ngx_ssl_connection_t' has no member named 'handshake_start_msec'
../graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_param_content_time':
../graphite-nginx-module/src/ngx_http_graphite_module.c:1450:29: error: 'ngx_http_request_t' has no member named 'content_end_sec'
../graphite-nginx-module/src/ngx_http_graphite_module.c:1450:50: error: 'ngx_http_request_t' has no member named 'content_start_sec'
../graphite-nginx-module/src/ngx_http_graphite_module.c:1450:82: error: 'ngx_http_request_t' has no member named 'content_end_msec'
../graphite-nginx-module/src/ngx_http_graphite_module.c:1450:104: error: 'ngx_http_request_t' has no member named 'content_start_msec'
../graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_param_gzip_time':
../graphite-nginx-module/src/ngx_http_graphite_module.c:1464:29: error: 'ngx_http_request_t' has no member named 'gzip_end_sec'
../graphite-nginx-module/src/ngx_http_graphite_module.c:1464:47: error: 'ngx_http_request_t' has no member named 'gzip_start_sec'
../graphite-nginx-module/src/ngx_http_graphite_module.c:1464:76: error: 'ngx_http_request_t' has no member named 'gzip_end_msec'
../graphite-nginx-module/src/ngx_http_graphite_module.c:1464:95: error: 'ngx_http_request_t' has no member named 'gzip_start_msec'
make[1]: *** [objs/addon/src/ngx_http_graphite_module.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory `/tmp/nginx/nginx-1.8.0'
make: *** [build] Error 2

Metrics do not send over TCP to remote graphite host

Hi! First of all, thanks for this module!

I faсed with error graphite tcp buffer is full when metrics sending over TCP to remote graphite host. It seems there is not enough time to establish a connection and an attempt to send data is done without waiting for.

When metrics send to localhost or to a remote host over UDP all looks good.

No stats are seen with Openresty-1.19.3.1

I have tried to compile with Openresty-1.19.3.1. nginx version-1.19.3

Patch used for nginx is https://github.com/mailru/graphite-nginx-module/blob/master/graphite_module_v1_15_4.patch

Case 1: No lua patch is applied.
Case 2: https://github.com/mailru/graphite-nginx-module/blob/master/lua_module_v0_10_12.patch is applied with few modifications, as there were some rejects.

However with both the cases, I couldn't find any stats coming from the instance.

This used to work with simple nginx. The last version I have tried is 1.17.2. But as it is throwing a warning to use openresty for optimization, I have compile with openresty.

Please suggest.

Compile error in alpine

When attempting to compile on alpine with nginx 1.8.0 I get the following

        ../graphite-nginx-module/src/ngx_http_graphite_module.c
../graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_timer_event_handler':
../graphite-nginx-module/src/ngx_http_graphite_module.c:1239:56: error: passing argument 5 of 'sendto' from incompatible pointer type [-Werror]
                 if (sendto(fd, part, nl - part + 1, 0, &sin, sizeof(sin)) == -1)
                                                        ^
In file included from src/os/unix/ngx_linux_config.h:44:0,
                 from src/core/ngx_config.h:26,
                 from ../graphite-nginx-module/src/ngx_http_graphite_module.c:1:
/usr/include/fortify/sys/socket.h:53:9: note: expected 'const struct sockaddr *' but argument is of type 'struct sockaddr_in *'
 ssize_t sendto(int sockfd, const void *buf, size_t n, int flags,
         ^
cc1: all warnings being treated as errors
objs/Makefile:1446: recipe for target 'objs/addon/src/ngx_http_graphite_module.o' failed
make[1]: *** [objs/addon/src/ngx_http_graphite_module.o] Error 1
make[1]: Leaving directory '/nginx-1.8.0'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2

Any ideas what would be causing it?

Feature Request: Allow variables in graphite_param/graphite_data

Hello, love the module, and it's been working great for us.

One thing that would make it even better for us, and especially to add custom stats for many locations, would be to allow variables in graphite_param and in graphite_data. This would allow us to set a variable in a location and then include something else, instead of having to write out all the graphite_param blocks each time.

It's already possible to do this in the lua chunk just simply because you can concatenate the strings and the nginx variable yourself.

Fails with 1.9.2

Somehow with the latest now, it fails with:

�[91m../graphite-nginx-module/src/ngx_http_graphite_module.c: In function 'ngx_http_graphite_param_upstream_time':
�[0m�[91m../graphite-nginx-module/src/ngx_http_graphite_module.c:1470:44: error: 'ngx_http_upstream_state_t' has no member named 'response_sec'
             ms += (ngx_msec_int_t)(state[i].response_sec * 1000 + state[i].response_msec);
                                            ^
../graphite-nginx-module/src/ngx_http_graphite_module.c:1470:75: error: 'ngx_http_upstream_state_t' has no member named 'response_msec'
             ms += (ngx_msec_int_t)(state[i].response_sec * 1000 + state[i].response_msec);
                                                                           ^
�[0m�[91mmake[1]: *** [objs/addon/src/ngx_http_graphite_module.o] Error 1
�[0mobjs/Makefile:1577: recipe for target 'objs/addon/src/ngx_http_graphite_module.o' failed
make[1]: Leaving directory '/nginx-1.9.2'
�[91mmake: *** [build] Error 2
�[0mMakefile:8: recipe for target 'build' failed

I did notice the patch fails to go through initially.

Any ideas?

Slow reload/shutdown

Is it expected for the nginx workers to take longer to shutdown/reload when this module is compiled in + enabled? We've noticed the shutdown/reload process is significantly longer when enabled even when completely idle.

These are the config lines we have:

graphite_config server=graphite.domain.com prefix=stats.counters.tier1 frequency=10;
graphite_data nginx.location.slash

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.