open-falcon监控nginx
主要逻辑:
通过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的更多相关文章
- 使用open-falcon监控Nginx
一.介绍 前段时间部署试用了open-falcon v0.2,官方文档很详细,难度也不是很大.监控Nginx也参考了文档推荐的方式,文档地址:http://book.open-falcon.org/z ...
- Zabbix 监控 Nginx(四)
简介: 如何使用 Zabbix 监控 Nginx 状态 ? 1.获取 Nginx 状态( HTTP Stub Status ) [root@localhost ~]# /apps/product/ng ...
- Python 监控nginx服务是否正常
Python 监控nginx服务是否正常 #!/usr/bin/env python import os, sys, time from time import strftime while True ...
- 让keepalived监控NginX的状态
经过前面的配置,如果主服务器的keepalived停止服务,从服务器会自动接管VIP对外服务:一旦主服务器的keepalived恢复,会重新接管VIP. 但这并不是我们需要的,我们需要的是当NginX ...
- ngxtop:在命令行实时监控 Nginx 的神器
Nginx网站服务器在生产环境中运行的时候需要进行实时监控.实际上,诸如Nagios, Zabbix, Munin 的网络监控软件是支持 Nginx 监控的. 如果你不需要以上软件提供的综合性报告或者 ...
- PHP实现简单的监控nginx日志文件功能
此功能是为了实现,定时监控nginx生成的日志数据,并将新增的数据提交到一个接口(比如大数据的接口,让大数据来进行分析) define("MAX_SHOW", 8192*5); / ...
- Zabbix 监控 Nginx 状态
简介: 如何使用 Zabbix 监控 Nginx 状态 ? 1.获取 Nginx 状态( HTTP Stub Status ) shell > /usr/local/nginx/sbin/ngi ...
- zabbix监控nginx
nginx status详解 active connections – 活跃的连接数量server accepts handled requests — 总共处理了11989个连接 , 成功创建11 ...
- 如何监控 Nginx?
什么是 Nginx? Nginx("engine-x")是一个 HTTP 和反向代理服务器,同时也是一个邮件代理服务器和通用的 TCP 代理服务器.作为一个免费开源的服务器,Ngi ...
- 使用zabbix监控nginx
在zabbix agentd客户端上,查看nginx是否加载了--with-http_stub_status_module.因为zabbix监控nginx是根据 nginx的Stub Status模块 ...
随机推荐
- EFCore Owned Entity Types,彩蛋乎?鸡肋乎?之彩蛋篇
EFCore Owned Entity Types的定义 EFCore Owned Entity Types的文档在这里:https://docs.microsoft.com/zh-cn/ef/cor ...
- 更改TestStep的request header和获取TestStep的response header
更改TestStep的request header for example def userId = "xxxxxxxxxxxxx" def request = context.t ...
- Markdown中特殊字符的转义字符
上次在用Markdown记笔记时,当正文中写到<PROJECT>_<PATH>_<FILE>_H_时,<>里的内容显示显示不出来,就算用' '也显示不出 ...
- 用几句话说一说CMake add_dependencies & target_link_libraries的使用区别
简单说一说前两天学习使用CMake解决链接问题时遇到的一个问题. 对于编译时遇到的依赖问题,很多时候我们只需要一句target_link_libraries就可以搞定. 但是CMake还有另外一个co ...
- NFS 配置文件及在iptables中的配置
yum 安装nfs即可 ( yum install nfs-utils ) cat /etc/exports /data/nfsdata 10.10.10.194(rw,no_root_squash) ...
- (转) java 通过 jdbc 链接 ms sql server 中出现 "no suitable driver for ..."
原文连接 : http://blog.csdn.net/stewen_001/article/details/19553173/ 前面是 基本操作步骤,按照原博主的方式进行操作即可...() 这里是需 ...
- css a的伪类顺序
a:link {color: #FF0000} /* 未访问的链接 */ a:visited {color: #00FF00} /* 已访问的链接 */ a:hover {color: #FF00FF ...
- 详细集成Redis (一)
1.添加依赖 <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</a ...
- C# 读取 appconfig文件配置数据库连接字符串,和配置文件
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connecti ...
- python中的lambda表达式
lambda是python中匿名函数的写法 我们可以在不定义函数名的情况下一边定义并调用这个函数 例子: 普通方法定义函数:def plus(a,b): return a+b lambda方法 ...