guycheung / falcon-ngx_metric Goto Github PK
View Code? Open in Web Editor NEWfalcon plugin for nginx statistic
License: Apache License 2.0
falcon plugin for nginx statistic
License: Apache License 2.0
python nginx_collect.py --service=hostname
--format=falcon --falcon-addr=http://127.0.0.1:1988/v1/push
Traceback (most recent call last):
File "nginx_collect.py", line 451, in collect
append_datapoint(datapoints, Render.render(la))
File "nginx_collect.py", line 71, in render
c = renders[la[0]]
KeyError: ''
这个报错是 采集参数拿到一个html作为 key ?
只设置这个参数无效,有人改过这个参数吗?
客户端打这种请求: { "timestamp": "2018-04-18T01:02:34+08:00", "host": "xx.xx.xx.xxx", "user": "-", "request": "\x16\x03\x01\x00\xDA\x01\x00\x00\xD6\x03\x03\xAD\x03\x99&*{\xAB\xAB\x8C\x1DS\x82\xCF\xA4y\xCF\x84\xB4\xEB\xAF}\x93S,u\xD4\xB5\x1E\x10\xB2\xE5;\x00\x00(\xC0,\xC0+\xC0$\xC0#\xC0", "clientip": "xx.xxx.xx.xxx", "size": 166, "responsetime": 5.000, "upstreamtime": "-", "upstreamhost": "-", "upstreamstatus": "-", "http_host": "_", "url": "-", "referrer": "-", "x_forwarded_for": "-", "agent": "-", "status": "400"}
error日志会有这种错误
2018/04/18 10:02:30 [error] 124908#124908: 4252054 failed to run log_by_lua: /usr/local/nginx/modules/ngx_metric/util.lua:49: bad argument #1 to 'gmatch' (string expected, got nil)
stack traceback:
[C]: in function 'gmatch'
/usr/local/nginx/modules/ngx_metric/util.lua:49: in function 'str_split'
.../local/nginx/modules/ngx_metric/ngx_metric.lua:12: in function 'cut_uri'
.../local/nginx/modules/ngx_metric/ngx_metric.lua:24: in function 'new'
/usr/local/nginx/modules/ngx_metric.lua:16: in function </usr/local/nginx/modules/ngx_metric.lua:1> while logging request, client: xxx.xx.xx.xxx, server: _, request: "µ±Z֧68Ӝe^,>c5T~쀍"
Traceback (most recent call last):
File "nginx_collect.py", line 450, in collect
append_datapoint(datapoints, Render.render(la))
File "nginx_collect.py", line 70, in render
c = renders[la[0]]
KeyError: ''
in falcon-ngx_metric/lua/ngx_metric/histogram.lua 24 line
if we should use **self.**values = util.str_split(values, ",") instead?
[root@izuf68l0q1ggeg7q97i1o5z falcon-ngx_metric]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
[root@izuf68l0q1ggeg7q97i1o5z falcon-ngx_metric]# systemctl status nginx.service
Jan 13 15:16:27 izuf68l0q1ggeg7q97i1o5z nginx[2388]: nginx: [emerg] unknown directive "lua_package_path" in /etc/nginx/conf.d/ngx_metric.conf:1
2016/12/08 14:46:13 [error] 25707#0: *633 lua entry thread aborted: runtime error: modules/ngx_metric/util.lua:9: attempt to call method 'get_keys' (a nil value)
stack traceback:
coroutine 0:
modules/ngx_metric/util.lua: in function 'dict_get_keys'
modules/ngx_metric/counter.lua:18: in function 'get_snapshot'
/usr/local/nginx/modules/ngx_metric_output.lua:18: in function </usr/local/nginx/modules/ngx_metric_output.lua:1>, client: 127.0.0.1, server: 127.0.0.1, request: "GET /monitor/basic_status HTTP/1.1", host: "localhost:9091"
2016/12/08 14:46:13 [error] 25707#0: 633 failed to run log_by_lua: modules/ngx_metric/util.lua:35: attempt to call method 'safe_add' (a nil value)
stack traceback:
modules/ngx_metric/util.lua:35: in function 'dict_safe_incr'
modules/ngx_metric/counter.lua:14: in function 'add'
modules/ngx_metric/ngx_metric.lua:58: in function 'err_count'
modules/ngx_metric/ngx_metric.lua:92: in function 'record'
/usr/local/nginx/modules/ngx_metric.lua:17: in function </usr/local/nginx/modules/ngx_metric.lua:1> while logging request, client: 127.0.0.1, server: 127.0.0.1, request: "GET /monitor/basic_status HTTP/1.1", host: "localhost:9091"
你好:
鉴于每个人的nginx启动方式和位置不同,可以考虑提示下部分代码内的lua文件路径地址根据需要修改,目前ngx_metric.conf 文件里调用的文件路径是相对的,会报错找不到文件。
别问我怎么想到的。嘿嘿。丢人。
error_rate
搜索失败:no counters in graph
有采集流量这个字段吗?请问latency_{50,75,95}th这几个字段表示什么意思呢?采集的数据大体一致,只是有些点不一样
一个负载均衡下的两个相同的nginx,运行着两个falcon-ngx_metric,相同的api请求数目统计push上去会相加么?
nginx版本:1.8.0
nginx编译参数:
nginx version: nginx/1.8.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.0.2e 3 Dec 2015
TLS SNI support enabled
configure arguments: --prefix=/usr/local/services/nginx-1.8.0 --with-pcre=/data/tmp/pcre-8.37 --with-zlib=/data/tmp/zlib-1.2.8 --with-openssl=/data/tmp/openssl-1.0.2e --with-http_gzip_static_module --with-http_ssl_module --add-module=/data/tmp/ngx_http_qrcode_module --with-ld-opt=-Wl,-rpath,/usr/local/lib --add-module=/data/tmp/ngx_http_barcode --add-module=/usr/local/src/lua-nginx-module-0.10.10/ --add-module=/usr/local/src/ngx_devel_kit-0.3.0/ --with-http_stub_status_module
lua版本:
ll /usr/local/bin/luajit
lrwxrwxrwx 1 root root 12 Nov 14 10:43 /usr/local/bin/luajit -> luajit-2.0.5
nginx_metric配置:
lua_package_path "modules/?.lua;;";
lua_shared_dict result_dict 128M;
log_by_lua_file modules/ngx_metric.lua;
server {
listen 127.0.0.1:9091;
server_name 127.0.0.1;
access_log logs/ngx_metric_for_falcon.access.log;
error_log logs/ngx_metric_for_falcon.error.log;
location /monitor/basic_status {
content_by_lua_file modules/ngx_metric_output.lua;
access_log off;
allow 127.0.0.1;
deny all;
}
location /monitor/nginx_status {
stub_status on;
access_log off ;
allow 127.0.0.1;
deny all;
}
}
配置好nginx,请求:
curl http://127.0.0.1:9091/monitor/basic_status
返回500错误
nginx_metric.error.log:
2018/11/14 17:11:31 [error] 21186#0: *8304 lua entry thread aborted: runtime error: ...local/services/nginx-1.8.0/modules/ngx_metric_output.lua:3: module 'ngx_metric.counter' not found:
no field package.preload['ngx_metric.counter']
no file 'modules/ngx_metric/counter.lua'
no file './ngx_metric/counter.lua'
no file '/usr/local/share/luajit-2.0.5/ngx_metric/counter.lua'
no file '/usr/local/share/lua/5.1/ngx_metric/counter.lua'
no file '/usr/local/share/lua/5.1/ngx_metric/counter/init.lua'
no file './ngx_metric/counter.so'
no file '/usr/local/lib/lua/5.1/ngx_metric/counter.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './ngx_metric.so'
no file '/usr/local/lib/lua/5.1/ngx_metric.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
coroutine 0:
[C]: in function 'require'
...local/services/nginx-1.8.0/modules/ngx_metric_output.lua:3: in function <...local/services/nginx-1.8.0/modules/ngx_metric_output.lua:1>, client: 127.0.0.1, server: 127.0.0.1, request: "GET /monitor/basic_status HTTP/1.1", host: "127.0.0.1:9091"
2018/11/14 17:11:31 [error] 21186#0: *8304 failed to run log_by_lua*: /usr/local/services/nginx-1.8.0/modules/ngx_metric.lua:4: module 'ngx_metric.ngx_metric' not found:
no field package.preload['ngx_metric.ngx_metric']
no file 'modules/ngx_metric/ngx_metric.lua'
no file './ngx_metric/ngx_metric.lua'
no file '/usr/local/share/luajit-2.0.5/ngx_metric/ngx_metric.lua'
no file '/usr/local/share/lua/5.1/ngx_metric/ngx_metric.lua'
no file '/usr/local/share/lua/5.1/ngx_metric/ngx_metric/init.lua'
no file './ngx_metric/ngx_metric.so'
no file '/usr/local/lib/lua/5.1/ngx_metric/ngx_metric.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './ngx_metric.so'
no file '/usr/local/lib/lua/5.1/ngx_metric.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
/usr/local/services/nginx-1.8.0/modules/ngx_metric.lua:4: in function </usr/local/services/nginx-1.8.0/modules/ngx_metric.lua:1> while logging request, client: 127.0.0.1, server: 127.0.0.1, request: "GET /monitor/basic_status HTTP/1.1", host: "127.0.0.1:9091"
看了下代码,写得很赞,学习了很多,特别是对sample抽样部分。
有两个问题请教下:
1,目前这个统计是针对uri(location)层面的,我打算将其扩展到可以统计server层和http层的,不知道有啥难度没?(估计应该是没啥难度的,代码的耦合度都很低,很方便扩展)
2,另外,是否可以按照每个upstream的名字统计下每个upstream的counter和time? 这样更具体详细。
(粗略看了下,目前只是按照uri对相应的upstream进行了time的统计,获取upstream的名字会是难点么?)
按照教程配置好了,但是
curl http://127.0.0.1:9091/monitor/basic_status
之后,只能得到query_count 和 lantency信息,如下所示
query_count|127.0.0.1|/monitor/basic_status|3
latency_99th|127.0.0.1|/monitor/basic_status|0.002
latency_95th|127.0.0.1|/monitor/basic_status|0.002
latency_50th|127.0.0.1|/monitor/basic_status|0.001
latency_75th|127.0.0.1|/monitor/basic_status|0.002
请问是什么问题 🙏
Traceback (most recent call last):
File "nginx_collect.py", line 450, in collect
append_datapoint(datapoints, Render.render(la))
File "nginx_collect.py", line 70, in render
c = renders[la[0]]
KeyError: ''
我执行脚本以后就报下面的错,请问是什么导致的呢,谢谢!
[root@fqy-nginx-4 falcon-ngx_metric]# python nginx_collect.py --format=falcon
Traceback (most recent call last):
File "nginx_collect.py", line 450, in collect
append_datapoint(datapoints, Render.render(la))
File "nginx_collect.py", line 70, in render
c = renders[la[0]]
KeyError: ''
/civil/api/civil.user.UserLogin
/civil/api/civil.device.GetDeviceListEx
/civil/api/civil.device.SetAlarmPlanConfig
。。。
upstream_web_civil 这个回源接口的req_total_count、 timeout_ total_count、 error_ total_count、 latency_ total_avg
比如我只想要过滤出如上这样的几个接口,其他都屏蔽掉, 有什么方法么?
/monitor/nginx_status, 您在nginx.conf有配置这个,但我发现代码中并没有通过这个接口来获取连接数等,这个配置是不是可以去掉呢?
大神,请问ngx_metric收集了当前nginx所有的访问吗? /monitor/basic_status这个链接的请求,是否记录了所有?
执行脚本之后可以取得数据 貌似没有推送到agent端 有没有跟我遇到一样的情况的
使用过程中,我按照 README.md 的方法,部署好了 lua 模块。但遇到些问题,我的使用流程大致如下:
#!/bin/bash
while [ 1 == 1 ]; do
curl http://localhost:9091/ >/dev/null 2>&1
sleep 1s
curl http://localhost:9091/monitor/basic_status >/dev/null 2>&1
curl http://localhost:9091/monitor/nginx_status >/dev/null 2>&1
curl http://localhost:9091/hello >/dev/null 2>&1
sleep 1s
done
http://127.0.0.1:1988/v1/push
)#!/bin/bash
while [ 1 == 1 ]; do
python nginx_collect.py --service=`hostname` --format=falcon --falcon-addr=http://127.0.0.1:1988/v1/push >/dev/null 2>&1
sleep 2s
done
我的几点疑问:
/monitor/basic_status
、/hello
和 /monitor/nginx_status
接口至少有几十次,但在 dashboard 都显示每分钟 只1次?这明显跟 README.md 上截图的监控效果不一样。@GuyCheung 你好,我在open-falcon中配置了latency_xx的策略,但是当达到了配置的阀值时,alarm没有报警。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.