博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
curl能访问 nginx转发后404_openfalcon 监控 nginx 状态
阅读量:6643 次
发布时间:2019-06-25

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

3057ed1d9cb67fb5e7a75c0403efc51d.png

openfalcon 监控 nginx 状态

主要使用 通过 agent push 数据至 server

思路

由于我这边有两套nginx 需要计算综合

ed3172f76ce7ed43a216e191958a8041.png

nginx 相关配置

启用nginx status配置

在默认主机里面加上location或者你希望能访问到的主机里面。

server {    listen  *:80 default_server;    server_name _;    location /ngx_status    {        stub_status on;        access_log off;        #allow 127.0.0.1;        #deny all;    }}

打开status页面

curl http://127.0.0.1/ngx_statusActive connections: 11921server accepts handled requests 11989 11989 11991Reading: 0 Writing: 7 Waiting: 42

nginx status详解

  • active connections – 活跃的连接数量
  • server accepts handled requests — 总共处理了11989个连接 , 成功创建11989次握手, 总共处理了11991个请求
  • reading — 读取客户端的连接数.
  • writing — 响应数据到客户端的数量
  • waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.

openfalcon 设置

通过shell 获取nginx 数据值

#!/bin/bashnginx_17=${
1}nginx_18=${
2}nginx_status_name=${
3}nginx_active_connections(){
active_connections_17=`curl -s http://${
nginx_17}:18190/nginx_status | grep connections | awk '{print $3}'` active_connections_18=`curl -s http://${
nginx_18}:18190/nginx_status | grep connections | awk '{print $3}'` let active_connections=($active_connections_17+$active_connections_18) echo $active_connections}nginx_reading(){
reading_17=`curl -s http://${
nginx_17}:18190/nginx_status | grep Reading | awk '{print $2}'` reading_18=`curl -s http://${
nginx_18}:18190/nginx_status | grep Reading | awk '{print $2}'` let reading=($reading_17+$reading_18) echo $reading}nginx_writing(){
writing_17=`curl -s http://${
nginx_17}:18190/nginx_status | grep Reading | awk '{print $4}'` writing_18=`curl -s http://${
nginx_18}:18190/nginx_status | grep Reading | awk '{print $4}'` let writing=($writing_17+$writing_18) echo $writing}nginx_waiting(){
waiting_17=`curl -s http://${
nginx_17}:18190/nginx_status | grep Reading | awk '{print $6}'` waiting_18=`curl -s http://${
nginx_18}:18190/nginx_status | grep Reading | awk '{print $6}'` let waiting=($waiting_17+$waiting_18) echo $waiting}case "$nginx_status_name" innginx_active_connections)nginx_active_connections;;nginx_reading)nginx_reading;;nginx_writing)nginx_writing;;nginx_waiting)nginx_waiting;;*)printf 'Usage: %s {nginx_active_connections|nginx_reading|nginx_writing|nginx_waiting}n' "$prog"exit 1;;esac

通过 python push至 agent http API 接口

需要注意 运行python及shell 需要在同一台服务器

同时需要能访问nginx_status 端口权限

#!-*- coding:utf8 -*-import osimport requestsimport timeimport jsonimport socket## 环境变量hostname = socket.gethostname()nginx_17_ip = "IP"  ## nginx服务器IPnginx_18_ip = "IP"def nginx_active_connections(nginx17_ip,nginx_18_ip):    os.environ['nginx_17_ip']=str(nginx_17_ip)    os.environ['nginx_18_ip']=str(nginx_18_ip)    connections_tmp =os.popen('/root/scripts/nginx_status.sh $nginx_17_ip $nginx_18_ip nginx_active_connections')    connections = connections_tmp.read()    #print(nginx_active_connections)    return connectionsdef nginx_reading(nginx17_ip,nginx_18_ip):    os.environ['nginx_17_ip']=str(nginx_17_ip)    os.environ['nginx_18_ip']=str(nginx_18_ip)    nginx_reading_tmp = os.popen('/root/scripts/nginx_status.sh $nginx_17_ip $nginx_18_ip nginx_reading')    nginx_reading = nginx_reading_tmp.read()    return nginx_readingdef nginx_writing(nginx17_ip,nginx_18_ip):    os.environ['nginx_17_ip']=str(nginx_17_ip)    os.environ['nginx_18_ip']=str(nginx_18_ip)    nginx_writing_tmp = os.popen('/root/scripts/nginx_status.sh $nginx_17_ip $nginx_18_ip nginx_writing')    nginx_writing = nginx_writing_tmp.read()    return nginx_writingdef nginx_waiting(nginx17_ip,nginx_18_ip):    os.environ['nginx_17_ip']=str(nginx_17_ip)    os.environ['nginx_18_ip']=str(nginx_18_ip)    nginx_waiting_tmp = os.popen('/root/scripts/nginx_status.sh $nginx_17_ip $nginx_18_ip nginx_waiting')    nginx_waiting = nginx_waiting_tmp.read()    return nginx_waitingnginx_active_count = int(nginx_active_connections(nginx_17_ip,nginx_18_ip))nginx_reading_count = int(nginx_reading(nginx_17_ip,nginx_18_ip))nginx_writing_count = int(nginx_writing(nginx_17_ip,nginx_18_ip))nginx_waiting_count = int(nginx_waiting(nginx_17_ip,nginx_18_ip))nginx_waiting_count = int(nginx_waiting(nginx_17_ip,nginx_18_ip))ts = int(time.time())payload = [    {
"endpoint": hostname, "metric": "nginx.active.connections", "timestamp": ts, "step": 60, "value": nginx_active_count, "counterType": "GAUGE", "tags": "", }, {
"endpoint": hostname, "metric": "nginx.reading", "timestamp": ts, "step": 60, "value": nginx_reading_count, "counterType": "GAUGE", "tags": "", }, {
"endpoint": hostname, "metric": "nginx.writing", "timestamp": ts, "step": 60, "value": nginx_writing_count, "counterType": "GAUGE", "tags": "", }, {
"endpoint": hostname, "metric": "nginx.waiting", "timestamp": ts, "step": 60, "value": nginx_waiting_count, "counterType": "GAUGE", "tags": "", },]r = requests.post("http://127.0.0.1:1988/v1/push", data=json.dumps(payload))print r.text

openfalcon 效果展示

通过dashboard 查询相关数据

5eb41ecc299c0392b141a2994845c2b3.png

Screen

4c10515f89445b383c4c2ec9551535fd.png

Grafana

f4fb36ce0011efe4ee95e5831b4fa421.png
open-falcon 监控 nginx_status​www.liuwq.com
326f45eb52a5da3a1ea7588fcbbdb8c1.png

转载地址:http://uuevo.baihongyu.com/

你可能感兴趣的文章
Oracle配置网络服务
查看>>
double型转换成string型
查看>>
Yahoo军规
查看>>
UVa 10100 - Longest Match
查看>>
Windows Phone 7 - DatePicker and TimePicker【转】
查看>>
PCH文件设置
查看>>
Fiddler基础使用三之请求过滤
查看>>
JS 7
查看>>
PHP删除目录下的空目录
查看>>
LeetCode-126-Word Ladder II
查看>>
水平居中与垂直居中,以及对齐
查看>>
MSchart IIS发布以后不能正常显示的问题
查看>>
(装)发布Live Writer代码着色插件CNBlogs.CodeHighlighter
查看>>
jQuery
查看>>
国庆经典八日游
查看>>
D3js-堆栈图
查看>>
CodeForces Round#480 div3 第2场
查看>>
Java动态编译技术原理
查看>>
图片360 度旋转
查看>>
WNDCLASS 的用法
查看>>