首页 > 系统相关 >Nginx upstream采集

Nginx upstream采集

时间:2023-04-10 20:33:08浏览次数:43  
标签:http nginx -- module Nginx upstream check 采集

因为nginx无论是开启模块还是添加模块都需要重新编译, 我们首先做一些准备工作。

测试环境

  • 操作系统: CentOS 7.2

安装依赖

这些依赖是我这个环境下的, 你可以根据自己的环境安装对应的依赖。

yum install -y patch
yum install -y gd gd-devel
yum install -y libxslt-devel
yum install perl-ExtUtils-Embed

第三方依赖

下载第三方依赖,并解压到目录/etc/nginx/third-modules/下。 https://github.com/yaoweibin/nginx_upstream_check_module

下载nginx源码

wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar zxvf nginx1.20.2.tar.gz
cd nginx-1.20.2
# 注意,要记得打下对应版本的patch
patch -p1 -i /etc/nginx/third-modules/nginx_upstream_check_module/check_1.20.1+.patch

编译nginx

感谢@Jeff的细心整理。

./configure \
--with-ld-opt="-Wl,-rpath,/usr/local/lib" \
--prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body \
--http-proxy-temp-path=/var/lib/nginx/tmp/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \
--http-scgi-temp-path=/var/lib/nginx/tmp/scgi \
--pid-path=/var/run/nginx.pid \
--lock-path=/run/lock/subsys/nginx \
--user=nginx \
--group=nginx \
--with-compat \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-select_module \
--with-poll_module \
--with-file-aio \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_perl_module=dynamic \
--with-stream=dynamic \
--with-mail=dynamic \
--with-http_xslt_module=dynamic \
--add-module=/etc/nginx/third-modules/nginx_upstream_check_module

验证

至此 编译完成,输入nginx -V查看编译参数,如果有以下参数则表示编译成功。

--add-module=/etc/nginx/third-modules/nginx_upstream_check_module

upstream check配置

进入/etc/nginx ,编辑nginx.conf 输入以下内容

user  nginx;
worker_processes  1;

events {
    worker_connections  1024;
}

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

    sendfile        on;

    keepalive_timeout  65;
    include conf.d/*.conf;
}

创建conf.d 目录, 编辑一个test.conf 输入以下内容

upstream test {
    server 127.0.0.1:18788 weight=10 max_fails=2 fail_timeout=5s;
    check interval=3000 rise=2 fall=5 timeout=1000 type=http;
    check_http_send "GET / HTTP/1.0\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx http_4xx http_5xx;
}

server {
        listen 80;
        server_name 192.168.11.201;

		location /upstream_status {
			check_status;
    		access_log   off;
		}
		location / {
                        add_header Content-Type text/plain;
                        return 200 "User-agent: *\nDisallow: /\n";
		}

		location /test {
            proxy_pass_header Authorization;
            proxy_pass_header Accept;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Scheme $scheme;
            proxy_set_header Authorization $http_authorization;
            proxy_set_header Accept $http_accept;
            proxy_pass http://test;
		}
}

启动nginx

nginx -t # 检查配置文件
  nginx #启动nginx

访问 http://192.168.11.201/upstream_status 查看状态 

Nginx upstream采集_nginx

categraf input.nginx_upstream_check插件

配置 conf/input.nginx_upstream_check/nginx.toml 内容如下

[[instances]]
targets = [
    "http://192.168.11.201/upstream_status?format=json",
]

启动categraf 测试,可以看到已经可以采集到指标了 

Nginx upstream采集_Categraf_02

指标包含了upstream的rise down等指标。

大盘链接

根据指标整理的监控大盘见 https://github.com/flashcatcloud/categraf/blob/main/inputs/nginx_upstream_check/dashboards.json

关于作者

本文作者孔飞,Flashcat工程师,文章内容是Flashcat技术团队共同沉淀的结晶。我们会持续输出监控、稳定性保障相关的技术文章,文章可转载,转载请注明出处,尊重技术人员的成果。

标签:http,nginx,--,module,Nginx,upstream,check,采集
From: https://blog.51cto.com/ulricqin/6179521

相关文章

  • 使用 Nginx 实现域名解析到不同端口的应用
    作为个人网站的服务器,一般都是一台。上面部署了各种应用,都是不同的端口。但是域名只能解析到80端口,而且如果你使用隐形URL转发的话,又需要另外加钱(TX的就是几百块一条....),这就很尴尬了。另一种显性URL又会直接301跳转,体验非常不好。这可如何是好呢?这就需要用到Nginx做反向代理了......
  • 造纸黑液处理设备PLC如何实现数据采集和远程上下载程序
    造纸行业是我国水污染最严重的行业之一,很多中小型造纸厂以麦草为原料生产纸浆,过程中产生的黑液是整个造纸过程主要的污染物,处理成本高、工序多、操作复杂,直接影响到造纸厂的最终效益。因此,黑液处理是造纸厂必须妥善解决的问题。随着工业设备与技术的发展,通过PLC控制造纸黑液的处理......
  • Nginx安装
    一、Nginx安装1、依赖包yuminstall-ygcc-c++pcrepcre-develzlibzlib-developensslopenssl-develwgetvimtelnetnet-tools2、下载1.22.0版本安装包cd/opt/soft&&wgethttp://nginx.org/download/nginx-1.22.0.tar.gz3、解压tar-zxvfnginx-1.22.0.tar.g......
  • nginx更新静态页面客户端缓存不刷新问题
    问题描述:频繁部署静态资源,nginx自带缓存未刷新通过ftp/sftp上传到nginx的静态页(尤其是打包好的单页应用),有可能遇到客户端缓存不刷新的问题,即使重启nginx都无效客户端浏览器也有缓存,一般关闭进程(手机清理,注意某些app光按返回键退回桌面是不会结束进程的),强制刷新网页等方法可以......
  • Loki采集Mysql errorlog,你值得拥有的错误日志聚合系统
    说到分布式日志存储系统,大家肯定对ELK、EFK这些工具并不陌生。可是它们都基于Elasticsearch存储,搭建复杂,耗资源,上手难。所以,个人非常推崇Grafana Labs开源的Loki 轻量级日志聚合分析系统Loki使用标签来作为索引,而不是对全文进行检索,所以在搜索上会有一定的局限性。但是,也能满......
  • Linux&Nginx16_Nginx反向代理6
    一、概念反向代理代理(ReverseProxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。首先我们先理解正向代理,如下图: ......
  • 住友注塑机SE-EV-A 网口数据采集联网方案
        住友注塑机SE-EV-AEVAX22B-25DA50/PMMA专用住友注塑机 SE-EV-A EVAX22B-25DA 50住友注塑机 SE-EV-A-HD EVAX28E-26BA 56住友注塑机 SE-EV-A-HD EVAX28E-26BA 56住友注塑机 SE-EV-A-HD EVAX28E-26BA 56住友注塑机 SE-EV-A-HD EVAX28E-26BA 56住友注塑机 SE-EV-A-HD......
  • nginx
                                 ......
  • nginx配置文件及虚拟主机
    最小配置nginx.conf去掉注释字段后剩余的字段#工作进程数量,配置为对应cpu核数量效果最好worker_processes1;events{#每个worker进程能创建的链接数量,默认即可worker_connections1024;}http{#引入响应头的Content-Type值includemime.t......
  • Nginx配置文件结构
    Nginx配置文件(conf/nginx.conf)整体分为三部分:*全局块和Nginx运行相关的全局配置*events和网络连接相关的配置*http块代理、缓存、日志记录、虚拟主机配置http全局块Server块Server全局块location块注:http......