prometheus grafana nginx 安装配置和使用

news/2024/5/18 22:44:03 标签: prometheus, nginx, docker

文章目录

  • 前传
  • prometheus exporter容器
  • 监控nginx
    • nginx需要加载stub_status监控
    • 查看有没有,如果有,去配置下nginx
    • 重要,需要重启nginx
    • 测试监控是否成功
  • prometheus中添加nginx-exporter
  • 配置 grafana
  • 外传

前传

prometheus grafana的安装使用:https://nanxiang.blog.csdn.net/article/details/135384541

本文说下监控nginxprometheus grafana nginx 安装配置和使用

Docker 镜像下载地址: https://hub.docker.com
比较好的hub.docker.com///-- https://hub.docker.com/u/bitnami
grafana监控面板:https://grafana.com/grafana/dashboards

prometheus_exporter_10">prometheus exporter容器

docker中下载nginx/nginx-prometheus-exporter镜像,并使用该镜像去运行容器

docker pull nginx/nginx-prometheus-exporter

docker run -itd -p 9113:9113 --name nginx-exporter  --restart=always -v /etc/localtime:/etc/localtime  nginx/nginx-prometheus-exporter -nginx.scrape-uri http://192.168.1.230/stub_status

192.168.1.230 被监控的nginx服务器的地址

nginx_19">监控nginx

nginxstub_status_20">nginx需要加载stub_status监控

[root@test230 ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.1.1g FIPS  21 Apr 2020
TLS SNI support enabled
configure arguments: --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=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --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-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

nginx_29">查看有没有,如果有,去配置下nginx

   location /stub_status {
                stub_status on;
                access_log off;
                #allow 127.0.0.1; # 允许本地访问
                #deny all; # 禁止其他IP访问
        }

nginx_40">重要,需要重启nginx

[root@test230 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@test230 ~]# nginx -s stop
[root@test230 ~]# systemctl start nginx

只是nginx -s reload是不生效的,一定要重启

测试监控是否成功

查看nginx是否已经开启监控stub

    [root@test230 opt]# curl http://127.0.0.1/stub_status
    Active connections: 6 
    server accepts handled requests
     9702 9702 165810 
    Reading: 0 Writing: 1 Waiting: 5 

在浏览器中输入http://192.168.1.230:9113,如果显示出测量数据就表示成功.
需要注意的是输入的IP地址为nginx/nginx-prometheus-exporter容器所配置的IP地址。

prometheusnginxexporter_68">prometheus中添加nginx-exporter

  • job_name: nginx
    static_configs:
  • targets: [‘1192.168.1.230:9113’]
    #192.168.1.230:9113与第三步测试的地址一至

配置 grafana

需要对应应的nginx/nginx-prometheus-exporter支持的仪表盘(dasdbord)
在grafana仪表盘中导入11280模块
或者自行去找合适的监控dasdbord

在这里插入图片描述
这个只是简单的监控,具体负责请自行分析吧。。

外传

😜 原创不易,如若本文能够帮助到您的同学
🎉 支持我:关注我+点赞👍+收藏⭐️
📝 留言:探讨问题,看到立马回复
💬 格言:己所不欲勿施于人 扬帆起航、游历人生、永不言弃!🔥


http://www.niftyadmin.cn/n/5304528.html

相关文章

真机调试HarmonyOS应用报错

问题表现: 01/04 19:00:01: Launching com.example.simplevideo $ hdc shell am force-stop com.example.simplevideo $ hdc shell bm uninstall com.example.simplevideo $ hdc file send E:\harmony\SimpleVideo\entry\build\default\outputs\default\entry-defau…

【.NET Core】记录(Record)详解

【.NET Core】记录(Record)详解 文章目录 【.NET Core】记录(Record)详解一、什么是记录二、定义一个记录2.1 使用record(或record class)定义引用类型2.2 使用record struct定义值类型2.3 创建可变记录类型…

微服务注册中心之Eureka

微服务注册中心之Eureka eureka 搭建集群 版本说明 Spring Boot 2.1.7.RELEASE spring-cloud-starter-netflix-eureka-server Finchley.SR2 spring-boot-starter-security 2.1.7.RELEASE pom.xml 文件 <?xml version"1.0" encoding"UTF-8"?> &l…

【大数据】分布式协调系统 Zookeeper

分布式协调系统 Zookeeper 1.Zookeeper 的特点2.Zookeeper 的数据结构3.Zookeeper 的应用场景3.1 统一命名服务3.2 统一配置管理3.3 统一集群管理3.4 服务器动态上下线3.5 软负载均衡 Zookeeper 是 Apache 开源的一个顶级项目&#xff0c;目的是为分布式应用提供协调服务&#…

Linux第2步_创建虚拟机

VMware软件安装好后&#xff0c;就可以创建虚拟机了。 一、虚拟机对CPU的要求较高 i7 处理器&#xff1a;CPU&#xff1a;Intel(R) Core(TM) i7-8700 CPU 3.20GHz 3.19 GHz 内核数&#xff1a;6 线程数&#xff1a; 12 最大睿频频率&#xff1a; 4.60 GHz 英特尔 睿…

阶段十-分布式-Redis01

第一章 Redis入门 1.1 节 什么是NoSql型数据库 NoSQL ,泛指非关系型的数据库, NoSQL Not Only SQL,它可以作为关系型数据库的良好补充。 NoSQL 不依赖业务逻辑方式存储&#xff0c;而以简单的key-value模式存储。因此大大的增加了数据库的扩展能力。NoSQL与SQL数据库区别对比如…

自由DIY预约小程序源码系统:适用于任何行业+自由DIY你的界面布局+全新升级的UI+多用户系统 带安装部署教程

随着移动互联网的普及&#xff0c;预约服务逐渐成为人们日常生活的一部分。从家政服务、医疗挂号到汽车保养&#xff0c;预约已经渗透到各个行业。然而&#xff0c;市面上的预约小程序大多功能单一&#xff0c;界面老旧&#xff0c;无法满足商家和用户的个性化需求。今天来给大…

计算机网络——多址复用技术

1. 频分多址&#xff08;FDMA&#xff09; 1.1 基本原理 频率分配&#xff1a;在FDMA系统中&#xff0c;整个可用的频带被分割成多个较小的频带或通道。每个通道分配给一个用户。 时间利用&#xff1a;用户在分配给他们的频道上持续进行通信&#xff0c;不受时间限制。 1.2 优…