博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用open-falcon监控Nginx
阅读量:6896 次
发布时间:2019-06-27

本文共 2343 字,大约阅读时间需要 7 分钟。

一、介绍

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

本文详细记录一下配置部署的过程。这里使用的是falcon-ngx_metric,github地址:

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支持的数据类型。

汇报字段

1094291-20180207153943795-351822453.png

配置Nginx

  • lua文件部署
mkdir ${NGINX_HOME}/modulescp 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 -hUsage: 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

1094291-20180207154003420-1369917772.png

转载于:https://www.cnblogs.com/bugsbunny/p/8426926.html

你可能感兴趣的文章
裸辞后,从Android转战Web前端的学习以及求职之路
查看>>
Makefile的常用技术总结
查看>>
java时间工具 判断时间大于一个月,小于一年,时间必须以月为单位分割(欢迎测试)...
查看>>
轻松搞定RabbitMQ开篇:Java消息队列与JMS的诞生
查看>>
MySQL:MGR 学习(2):Write set(写集合)的写入过程
查看>>
Docker+Selenium Grid构建分布式Web测试环境
查看>>
操作系统复习题-第七章 中断和信号机构
查看>>
snakemake--我最喜欢的流程管理工具
查看>>
如何用 Python 和 gensim 调用中文词嵌入预训练模型?
查看>>
nginx三种安装方式
查看>>
陷阱:千万不要随便把serlvet.jar之类的包放在系统的classpath下面
查看>>
jQuery拖动、滚轮查看大图-类似地图操作
查看>>
K8S有状态服务-云盘扩容解决方案
查看>>
Java8集合源码解析-Hashtable源码剖析
查看>>
飘刃 v0.0.10 首次发布,超快执行速度的 Vue 项目构建工具
查看>>
数据分析索引【数据分析】
查看>>
微软职位内部推荐-Senior Program Manager
查看>>
Hadoop完全分布式安装Flume
查看>>
一种关于缓存数据何时更新的解决思路
查看>>
【iOS 开发】用 Carthage 摆脱 Bridging-Header.h
查看>>