主要逻辑:
通过lua nginx module的log_by_lua_file实时记录nginx请求数据,通过外部python脚本定时获取数据解析为Open-Falcon支持的数据类型。

Nginx编译lua支持:

1、下载安装LuaJIT-2.0.4.tar.gz

wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar xzvf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make install PREFIX=/usr/local/luajit

#注意环境变量!
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0

2.下载解压ngx_devel_kit
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -xzvf v0.3.0.tar.gz

3.下载解压lua-nginx-module
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
tar -xzvf v0.10.8.tar.gz

4.下载安装nginx-1.10.3.tar.gz
wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar -xzvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --add-module=/lgp/nginx/ngx_devel_kit-0.3.0 --add-module=/lgp/nginx/lua-nginx-module-0.10.8
#注意ngx_devel_kit和lua-nginx-module以实际解压路径为准
make
make install

注:依赖报错,可以执行
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

5.验证
#将nginx做成命令
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
cd /usr/local/nginx/conf/
vi nginx.conf

#lua指令方式
#在server 中添加一个localtion
location /hello {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
#lua文件方式
#在server 中添加一个localtion
location /lua {
default_type 'text/html';
content_by_lua_file conf/lua/test.lua; #相对于nginx安装目录
}
#test.lua文件内容
ngx.say("hello world");

#启动nginx(已经做了软连接了,可以在任何目录启动)
nginx

注:
报错nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory 可以执行
ln -s /usr/local/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
具体source的路径已实际安装路径为准

falcon-ngx_metric部署

1、程序下载
[root@oneapm-test openfalcon]# cd /opt/openfalcon/
# git clone https://github.com/GuyCheung/falcon-ngx_metric.git

2、lua文件部署
cd /usr/local/nginx/
mkdir modules
cp -r /opt/openfalcon/falcon-ngx_metric/lua/* /usr/local/nginx/modules
cp /opt/openfalcon/falcon-ngx_metric/ngx_metric.conf /usr/local/nginx/conf/conf.d

3、nginx.conf配置

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

access_log logs/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;
include /usr/local/nginx/conf.d/*.conf;
server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}
location /hello {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}
location /hello {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

4、启动测试
python nginx_collect.py --format=falcon –service=dst6-nginx
5、将启动脚本加入crontab
* * * * * python nginx_collect.py --format=falcon --service=HOSTNAME --falcon-addr=http://127.0.0.1:1988/v1/push

参数解释

python nginx_collect.py -h

Usage: nginx_collect.py [options]

Options:
-h, --help show this help message and exit
--use-ngx-host use the ngx collect lib output host as service column,
default read self
--service=SERVICE logic service name(endpoint in falcon) of metrics, use
nginx service_name as the value when --use-ngx-host
specified. default is ngx_metric
--format=FORMAT output format, valid values "odin|falcon", default is
odin
--falcon-step=FALCON_STEP
Falcon only. metric step
--falcon-addr=FALCON_ADDR
Falcon only, the addr of falcon push api
--ngx-out-sep=NGX_OUT_SEP
ngx output status seperator, default is "|"

--use-ngx-host: 使用nginx配置里的service_name作为采集项的endpoint

--service: 手动设置endpoint值,当指定--use-ngx-host时,该参数无效

--format: 采集数据输出格式,对接falcon请使用--format=falcon

--falcon-step: falcon step设置,请设置为python脚本调用频率,默认是60

--falcon-addr: falcon push接口设置,设置该参数数据直接推送,不再输出到终端。需要安装requests模块

open-falcon监控nginx的更多相关文章

  1. 使用open-falcon监控Nginx

    一.介绍 前段时间部署试用了open-falcon v0.2,官方文档很详细,难度也不是很大.监控Nginx也参考了文档推荐的方式,文档地址:http://book.open-falcon.org/z ...

  2. Zabbix 监控 Nginx(四)

    简介: 如何使用 Zabbix 监控 Nginx 状态 ? 1.获取 Nginx 状态( HTTP Stub Status ) [root@localhost ~]# /apps/product/ng ...

  3. Python 监控nginx服务是否正常

    Python 监控nginx服务是否正常 #!/usr/bin/env python import os, sys, time from time import strftime while True ...

  4. 让keepalived监控NginX的状态

    经过前面的配置,如果主服务器的keepalived停止服务,从服务器会自动接管VIP对外服务:一旦主服务器的keepalived恢复,会重新接管VIP. 但这并不是我们需要的,我们需要的是当NginX ...

  5. ngxtop:在命令行实时监控 Nginx 的神器

    Nginx网站服务器在生产环境中运行的时候需要进行实时监控.实际上,诸如Nagios, Zabbix, Munin 的网络监控软件是支持 Nginx 监控的. 如果你不需要以上软件提供的综合性报告或者 ...

  6. PHP实现简单的监控nginx日志文件功能

    此功能是为了实现,定时监控nginx生成的日志数据,并将新增的数据提交到一个接口(比如大数据的接口,让大数据来进行分析) define("MAX_SHOW", 8192*5); / ...

  7. Zabbix 监控 Nginx 状态

    简介: 如何使用 Zabbix 监控 Nginx 状态 ? 1.获取 Nginx 状态( HTTP Stub Status ) shell > /usr/local/nginx/sbin/ngi ...

  8. zabbix监控nginx

     nginx status详解 active connections – 活跃的连接数量server accepts handled requests — 总共处理了11989个连接 , 成功创建11 ...

  9. 如何监控 Nginx?

    什么是 Nginx? Nginx("engine-x")是一个 HTTP 和反向代理服务器,同时也是一个邮件代理服务器和通用的 TCP 代理服务器.作为一个免费开源的服务器,Ngi ...

  10. 使用zabbix监控nginx

    在zabbix agentd客户端上,查看nginx是否加载了--with-http_stub_status_module.因为zabbix监控nginx是根据 nginx的Stub Status模块 ...

随机推荐

  1. PC/FORTH 下的多任务使用

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  2. JDBC Request

    1.下载jdbc驱动,放至jmeter安装目录的lib目录和lib\ext目录下 PS:自己操作的时候,由于JDBC Connection Configuration中驱动名称写错,前面多了一个空格, ...

  3. Python之元组方法

    def count(self, value): # 计算元素出现的个数 """ T.count(value) -> integer -- return number ...

  4. poj1002总结

    1.之前一直是runtime error,没有找出具体原因,把冒牌排序改成了合并排序,当输入是100000行时,从大约10s变到1s内 2.感觉是atoi指针导致的,当判断atoi的入参不为NULL时 ...

  5. Python基础(条件判断,循环,占位符等)

    Python 自动化 系统开发用的语言和自动化脚本可以不同 学习peython可用于: 网路爬虫,数据分,web开发,人工智能,自动化运维,自动化测试,嵌入式,黑客 第三方库比较全 脚本语言:功能单一 ...

  6. 20175224 2018-2019-2 《Java程序设计》第七周学习总结

    教材学习内容总结 第八章 常用实用类 String类 构造String对象:常量对象:String对象:引用String常量. 字符串的并置:String对象使用“+”进行并置运算,即首尾相接. 字符 ...

  7. 小程序 map组件问题 cover-view问题

    使用小程序的组件map时 在开发者工具上一切顺利 但是在真机预览时 发现地图的层级是最高的 任何标签都覆盖不了它 调整z-index值并没有什么效果 原因是 微信小程序的map.video.canva ...

  8. Docker多主机互联最佳实践

    在公司使用docker多主机互联时碰到了各种坑.搞清楚后才发现如此简单,以下是根据实际经验的总结. 版本信息 Client: Version: 18.09.0 API version: 1.39 Go ...

  9. IDEAL 热更新

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...

  10. JAVAEE期末项目------文章发布系统

    项目文档和代码的GitHub地址:https://github.com/xiangbaobaojojo/- 1.项目介绍 (计科四班  蔡春燕 20150141401)和我 陈香宇(计科四班  201 ...