网站首页 > 技术教程 正文
概述
Prometheus 服务本地已经启动了,接下来,需要安装并运行 Exporter,它的主要作用是持续输出监控的组件信息并格式化,同时提供 Http 接口供 Prometheus 服务来抓取。Exporter 也是通过 GO 语言编写的,Prometheus GitHub 已经为我们提供了很多实用的 Exporter,直接拿来使用即可。
今天主要分享下怎么用prometheus+grafana去监控nginx服务。
一、编译安装nginx
nginx_vts_exporter依赖nginx-module-vts模块,安装此模块无需任何其他依赖。模块与Nginx的版本兼容性如下:
1.11.x (last tested: 1.11.10) 1.10.x (last tested: 1.10.3) 1.8.x (last tested: 1.8.0) 1.6.x (last tested: 1.6.3) 1.4.x (last tested: 1.4.7)
1、下载源码nginx和nginx-module-vts moudle
因为是演示,所以就简单写一下步骤了。
wget http://nginx.org/download/nginx-1.12.1.tar.gz git clone git://github.com/vozlt/nginx-module-vts.git
2、安装组件
yum install -y openssl libssl-dev libxml2-dev libxslt-dev libgd2-xpm libgd2-xpm-dev libgeoip-dev libperl-dev patch
3、添加nginx-http-sysguard模块
从官网上下载这个模块:
https://github.com/alibaba/nginx-http-sysguard/archive/master.zip
解压到/opt/nginx-1.12.1/中,然后打补丁
cd /opt/nginx-1.12.1 patch -p1 < ./nginx-http-sysguard-master/nginx_sysguard_1.3.9.patch
4、编译安装
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-http_ssl_module --with-http_realip_module --with-http_addition_module \ --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module \ --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module \ --with-http_auth_request_module --with-http_slice_module --with-http_v2_module --add-module=/opt/nginx-1.12.1/nginx-http-sysguard-master \ --with-stream --add-module=../nginx-module-vts make &&make install
5、修改nginx配置
添加监控接口/status和sysguard做压测
http { vhost_traffic_status_zone; vhost_traffic_status_filter_by_host on; ... server { ... sysguard on; sysguard_load load=0.01 action=/loadlimit; sysguard_mem swapratio=20% action=/swaplimit; location /loadlimit { return 404; } location /swaplimit { return 503; } location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; } } }
配置建议:
1)打开vhost过滤:
vhost_traffic_status_filter_by_host on;
开启此功能,在Nginx配置有多个server_name的情况下,会根据不同的server_name进行流量的统计,否则默认会把流量全部计算到第一个server_name上。
2)在不想统计流量的server区域禁用vhost_traffic_status,配置示例:
server { ... vhost_traffic_status off; ... }
假如nginx没有规范配置server_name或者无需进行监控的server上,那么建议在此vhost上禁用统计监控功能。否则会出现“127.0.0.1”,hostname等的域名监控信息。
6、监控数据的查看
安装完vts模块后,可以通过nginx status接口进行监控数据的查看
二、部署nginx-vts-exporter
exporter会收集nginx性能指标的JSON格式数据,并汇总后暴露监控接口给Prometheus
1、下载当前最新版本的软件包:
wget -c https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
2、解压后运行:
nohup ./nginx-vts-exporter -nginx.scrape_timeout 10 -nginx.scrape_uri http://172.16.10.123:8000/status/format/json &
推荐exporter和nginx安装在同一台机器上,如果不在同一台主机,把scrape_uri改为nginx主机的地址。
nginx_vts_exporter的默认端口号:9913,对外暴露监控接口http://xxx:9913/metrics.
三、Nginx的监控数据类型
nginx-vts-exporter的数据类型命名空间默认以“nginx”开头,主要有如下9个:
HELP是对监控条目的解释,TYPE的格式是:监控条目名称+Prometheus数据类型:
# HELP nginx_server_bytes request/response bytes # TYPE nginx_server_bytes counter # HELP nginx_server_cache cache counter # TYPE nginx_server_cache counter # HELP nginx_server_connections nginx connections # TYPE nginx_server_connections gauge # HELP nginx_server_requestMsec average of request processing times in milliseconds # TYPE nginx_server_requestMsec gauge # HELP nginx_server_requests requests counter,可以区分状态码 # TYPE nginx_server_requests counter # HELP nginx_upstream_bytes request/response bytes # TYPE nginx_upstream_bytes counter # HELP nginx_upstream_requestMsec average of request processing times in milliseconds # TYPE nginx_upstream_requestMsec gauge # HELP nginx_upstream_requests requests counter,可以区分状态码 # TYPE nginx_upstream_requests counter # HELP nginx_upstream_responseMsec average of only upstream/backend response processing times in milliseconds # TYPE nginx_upstream_responseMsec gauge
篇幅有限,关于nginx服务被监控端部署方面就介绍到这了,后面介绍监控端的一些配置,感兴趣的朋友可以关注下~
猜你喜欢
- 2024-10-10 平台进程监控介绍(系统进程监控软件)
- 2024-10-10 Zabbix监控系统系列之八:监控nginx服务
- 2024-10-10 深度|掌握Nginx监控运维,这一篇足矣!
- 2024-10-10 Nginx 监控(nginx监控工具)
- 2024-10-10 如何轻松监控Nginx?(nginx 监控)
- 2024-09-11 这可能是把Nginx讲解的最透彻的一本新书
- 2024-09-11 nginx动态添加nginx-module-vts监控流量
- 2024-09-11 Docker 容器操作:运行、监控与维护
- 2024-09-11 用groovry做简单的nginx日志实时监控脚本
- 2024-09-11 教你三种方法,用 Python实时监控文件
你 发表评论:
欢迎- 最近发表
-
- Win11学院:如何在Windows 11上使用WSL安装Ubuntu
- linux移植(Linux移植freemodbus)
- 独家解读:Win10预览版9879为何无法识别硬盘
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- Docker镜像瘦身(docker 减小镜像大小)
- 在linux上安装ollama(linux安装locale)
- 渗透测试系统Kali推出Docker镜像(kali linux渗透测试技术详解pdf)
- Linux环境中部署Harbor私有镜像仓库
- linux之间传文件命令之Rsync傻瓜式教程
- 解决ollama在linux中安装或升级时,通过国内镜像缩短安装时长
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)