使用open-falcon监控Nginx
一、介绍
前段时间部署试用了open-falcon v0.2,官方文档很详细,难度也不是很大。监控Nginx也参考了文档推荐的方式,文档地址:http://book.open-falcon.org/zh_0_2/usage/ngx_metric.html。
本文详细记录一下配置部署的过程。这里使用的是falcon-ngx_metric,github地址:https://github.com/GuyCheung/falcon-ngx_metric
falcon-ngx_metric是借助lua-nginx-module的log_by_lua功能实现nginx请求的实时分析,然后借助ngx.shared.DICT存储中间结果。最后通过外部python脚本取出中间结果加以计算、格式化并输出。按falcon格式输出的结果可直接push到falcon agent。
二、安装部署lua-nginx-module
环境需求
- System: Linux
- Python: >= 2.6
- Nginx+Lua
主要逻辑
通过lua nginx module的log_by_lua_file实时记录nginx请求数据,通过外部python脚本定时获取数据解析为Open-Falcon支持的数据类型。
汇报字段

配置Nginx
- lua文件部署
mkdir ${NGINX_HOME}/modules
cp lua/* ${NGINX_HOME}/modules/
- nginx配置文件加载
cp ngx_metric.conf ${NGINX_CONF}/conf.d/
# 确保nginx.conf include 该配置
include conf.d/*.conf;
- 配置uri长度截取【可选】
# 当uri过长,或者使用RESTful uri时,容易把具体ID带到uri进行统计,与实际情况相悖。
# ngx_metric里对uri进行了截断,默认是以"/"分隔,截取三段,可以自由配置
server {
# 该server下uri统计时截取5段
set $ngx_metric_uri_truncation_len 5;
}
lua结果解析
配置好lua模块和脚本目录,执行以下测试通过后,跑Python脚本应该就正常了。否则会出现500错误。
curl http://127.0.0.1:9091/monitor/basic_status
- 测试
pip install requests # 可选,使用`--falcon-addr`时需要执行
python nginx_collect.py
有数据打印出来就可以放到crontab中,定时push到agent中了。
- 将脚本加入crontab
# * * * * * python nginx_collect.py --format=falcon --service=HOSTNAME --falcon-addr=http://127.0.0.1:1988/v1/push
nginx_collect.py 脚本参数说明
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模块
Screenshot

使用open-falcon监控Nginx的更多相关文章
- 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模块 ...
随机推荐
- makefile在编译的过程中出现“except class name”
今天写了部分代码,在添加到项目中后就那些编译,出现问题如下: logistic_regression_layer.h::: error: expected class name public Laye ...
- gulp的流与执行顺序
gulp的关键在于流,这从它的logo就能看出来. 在node中,流是操作文件时一个重要的概念.流是指什么呢?它包含两个含义:“水流”和“流水”. 水流蕴含了源源不断或是一股一股那样流过的意味:而流水 ...
- Redux 介绍
本文主要是对 Redux 官方文档 的梳理以及自身对 Redux 的理解. 单页面应用的痛点 对于复杂的单页面应用,状态(state)管理非常重要.state 可能包括:服务端的响应数据.本地对响应数 ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- UEP-查询方式总结
public void retrieve() { QueryParamList params = getQueryParam("dataWrap"); //获取页面上的参数,即查询 ...
- node学习笔记2 —— npm包管理
全局模式安装包 将包安装为全局可用的可执行命令, 并非可以从任意地方require 将 package.json中bin定义的文件软链到统一的目录下, 该目录可以通过如下方式推算出来: path.re ...
- C语言第二次实验报告
1.实验题目 题1:11-7 找鞍点(20 分) 一个矩阵元素的"鞍点"是指该位置上的元素值在该行上最大.在该列上最小. 本题要求编写程序,求一个给定的n阶方阵的鞍点 题2: ...
- DLL导出全局变量在多个DLL中调用
=================================版权声明================================= 版权声明:原创文章 禁止转载 请通过右侧公告中的“联系邮 ...
- 求助帖:android开发初期:为什么我在活动二设置的singInstance模式跑到活动三去了???
求android开发的高手帮我看看这个问题吧: <activity android:name=".SecondActivity" android:label="Th ...
- Mybatis问题:There is no getter for property named 'unitId' in 'class java.lang.String'
Mybatis遇到的问题 问题: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.re ...