Prometheus+Grafana-3-Nginx监控-Redis监控

news2024/9/19 10:42:34

一、监控Nginx

1.Nginx需要开启stub_status

这里我的nginx容器名为mynignx,进入容器查看。

docker exec -it mynginx bash #进入容器
nginx -v 2>&1 | grep -o with-http_stub_status_module #查看

修改nginx.conf

...
        location /stub_status {
                stub_status on;
                access_log off;
                #allow nginx_export的ip;
                allow 0.0.0.0/0;
                deny all;
        }
...

#检查配置文件
docker exec -it mynginx nginx -t

#重新加载配置文件
docker restart mynginx

#检查,若监听默认80端口,端口号可不填,192.168.88.129/stub_status
curl http://192.168.88.129:5173/stub_status

2.DockerCompose安装nginx_exporter

容器内默认监听9113,注意端口映射

#注意文件缩进两个空格
cat >docker-compose.yaml <<EOF
version: '3.8'
services:
  nginx_exporter: 
    image: nginx/nginx-prometheus-exporter
    container_name: nginx_exporter
    hostname: nginx_exporter
    #设置nginx配置中的数据地址
    command: 
    - '-nginx.scrape-uri=http://192.168.88.129:5173/stub_status'
    restart: always
    #容器内默认监听9113
    ports:
    - 5174:9113
EOF
#启动
docker compose up -d
#访问
http://192.168.88.129:5174

3.修改Prometheus配置

cat >> prometheus/prometheus.yml << "EOF"
  - job_name: 'nginx_exporter'
    static_configs:
    - targets: ['192.168.88.129:5174']
      labels: 
        instance: Nginx服务器
EOF
#Prometheus热部署更新配置,或者重新启动Prometheus也可
curl -X POST http://localhost:9090/-/reload

4.常用监控数据

 5.添加触发器

cat >>prometheus/alert.yml << "EOF"
- name: nginx
  rules:
  # 对任何实例超过30秒无法联系的情况发出警报,up默认为1,设置为0的时候报警
  - alert: NginxDown
    expr: nginx_up == 0
    for: 30s
    labels:
      severity: critical
    annotations:
      summary: "nginx异常,实例:{{ $labels.instance }}"
      description: "{{ $labels.job }} nginx已关闭"
EOF
#检查
docker exec -it prometheus promtool check config /etc/prometheus/prometheus.yml

curl -X POST http://localhost:9090/-/reload

成功。

二、监控Redis

1.安装exporter

#直接运行
docker run -d --name redis_exporter -p 9121:9121 --restart always oliver006/redis_exporter --redis.addr redis://192.168.88.129:6379 --redis.password '123456'

默认端口为9121,访问192.168.88.129:9121

2.修改Prometheus配置

 shift+y(大写Y)进入可视化模式选中上面的nginx,y 复制,p粘贴

 curl -X POST http://localhost:9090/-/reload

3.常用监控指标

4.触发器配置

创建一个alert.yml存放规则,并且把该文件配置到Prometheus中。

#Prometheus
rule_files:
  - "alert.yml"
  - "rules/*.yml"
# 文件
redis-exporter.yml 
 
groups:
- name: Redis   #报警规则组的名字
  rules:
  - alert: RedisDown
    expr: redis_up == 0
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Redis down (instance {{ $labels.instance }})"
      description: "Redis instance is down\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisMissingMaster
    expr: count(redis_instance_info{role="master"}) == 0
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Redis missing master (instance {{ $labels.instance }})"
      description: "Redis cluster has no node marked as master.\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisTooManyMasters
    expr: count(redis_instance_info{role="master"}) > 1
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Redis too many masters (instance {{ $labels.instance }})"
      description: "Redis cluster has too many nodes marked as master.\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisDisconnectedSlaves
    expr: count without (instance, job) (redis_connected_slaves) - sum without (instance, job) (redis_connected_slaves) - 1 > 1
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Redis disconnected slaves (instance {{ $labels.instance }})"
      description: "Redis not replicating for all slaves. Consider reviewing the redis replication status.\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisReplicationBroken
    expr: delta(redis_connected_slaves[1m]) < 0
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Redis replication broken (instance {{ $labels.instance }})"
      description: "Redis instance lost a slave\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisClusterFlapping
    expr: changes(redis_connected_slaves[5m]) > 2
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Redis cluster flapping (instance {{ $labels.instance }})"
      description: "Changes have been detected in Redis replica connection. This can occur when replica nodes lose connection to the master and reconnect (a.k.a flapping).\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisMissingBackup
    expr: time() - redis_rdb_last_save_timestamp_seconds > 60 * 60 * 24
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Redis missing backup (instance {{ $labels.instance }})"
      description: "Redis has not been backuped for 24 hours\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisOutOfMemory
    expr: redis_memory_used_bytes / redis_total_system_memory_bytes * 100 > 90
    for: 5m
    labels:
      severity: warning
    annotations:
      summary: "Redis out of memory (instance {{ $labels.instance }})"
      description: "Redis is running out of memory (> 90%)\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisTooManyConnections
    expr: redis_connected_clients > 100
    for: 5m
    labels:
      severity: warning
    annotations:
      summary: "Redis too many connections (instance {{ $labels.instance }})"
      description: "Redis instance has too many connections\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisNotEnoughConnections
    expr: redis_connected_clients < 5
    for: 5m
    labels:
      severity: warning
    annotations:
      summary: "Redis not enough connections (instance {{ $labels.instance }})"
      description: "Redis instance should have more connections (> 5)\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
 
   
  - alert: RedisRejectedConnections
    expr: increase(redis_rejected_connections_total[1m]) > 0
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Redis rejected connections (instance {{ $labels.instance }})"
      description: "Some connections to Redis has been rejected\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"
#检查
docker exec -it prometheus promtool check config /etc/prometheus/prometheus.yml

  curl -X POST http://localhost:9090/-/reload

最大内存为0可以让Redis在内存不足时只读取数据而不写入数据。这种模式被称为noeviction模式。

#进入redis容器,redis-cli连接,设置最大内存
config set maxmemory 3G

 http://192.168.88.129:9090/rules

4.Dashboard

Grafana可以使用11835

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2035272.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

华为od统一考试B卷【AI面板识别】python实现

思路 n int(input())class Light:def __init__(self, id, x1, y1, x2, y2):self.id idself.x1 x1self.y1 y1self.x2 x2self.y2 y2self.height y2 - y1def get_lights_info(n):lights []for _ in range(n):id, x1, y1, x2, y2 map(int, input().strip().split())lights…

量产工具——复习及改进(后附百问网课程视频链接)

目录 一、函数的使用 1.显示系统 1.1 mmap函数 2.输入系统 2.1 ts_setup()函数 2.2 ts_read()函数 2.3 socket()函数 2.4 bind()函数 2.5 recvfrom()函数 2.6 inet_aton()函数 2.7 sendto()函数 2.8 pthread_create()函数 2.9 pthread_cond_signal()函数 2.10 pthre…

思科路由器的基本配置1

#路由技术基础# #路由器的基本配置1# #1调整超级终端的参数 #2退出配置向导&#xff0c;输入“NO”即可进入正常配置方式 #3路由器的模式切换 Router> &#xff01;进入用户模式 Router>enable &#xff01;进入特权模…

opencv-python实战项目一:获取鼠标框选区域的颜色

文章目录 一&#xff1a;简介二&#xff1a;框选区域选择颜色方案三、算法实现步骤3.1 按鼠标事件截取图像3.2将图像模糊后转化为hsv并求均值3.3 判断hsv处于何种颜色 四&#xff1a;整体代码实现五&#xff0c;效果: 一&#xff1a;简介 在计算机视觉领域&#xff0c;颜色检测…

19-ESP32-C3加大固件储存区

1默认编译情况。 2、改flash4M。ESP-IDF Partition Table Editor修改。 3、设置输入Partition Table 改自定义.CSV。保存。 4、查看命令输入Partition Table Editor打开-分区表编辑器UI。按图片增加。 nvs,data,nvs,0x9000,0x6000,, phy_init,data,phy,0xF000,0x1000,, factory…

计算机毕业设计Hadoop+Hive居民用电量分析 居民用电量可视化 电量爬虫 机器学习 深度学习 大数据毕业设计 Spark

《Hadoop居民用电量分析》开题报告 一、研究背景与意义 能源问题在全球范围内一直是热点议题&#xff0c;尤其是随着居民生活水平的提高和城市化进程的加快&#xff0c;居民用电量急剧增长&#xff0c;对电力系统的稳定运行和能源管理提出了更高要求。如何科学合理地管理和分…

Hive3:识别内部表、外部表及相互转换

一、识别方法 查看内部表信息 desc formatted stu;查看外部表信息 desc formatted test_ext1;通过Table Type对应的值&#xff0c;我们可以区分外部表和内部表。 二、相互转换 内部表转外部表 alter table stu set tblproperties(EXTERNALTRUE);外部表转内部表 alter ta…

PCIe学习笔记(21)

读请求的数据返回&#xff08;Data Return for Read Requests&#xff09; •针对内存读取请求的单个完成可能提供少于请求的全部数据量&#xff0c;只要对于给定请求的所有完成在组合起来时返回了读取请求中请求的数据量。 ◦不同请求的完成不能合并。 ◦I/O和Configuratio…

Qt QCustomPlot 图形库详解

文章目录 原文1. 下载qcustomplot.h与qcustomplot.cpp后,将代码文件拷贝到本地工程,并添加到工程项目2. 看到文件后就是添加成功了3. 在界面中拖拽一个Widget控件,选中并右键选中“提升为”,将原来的Widget控件已成为一个带坐标的 CustomPlot 控件4. 添加printsupport原文 …

【Ai学习】一个技巧,解决99%Comfyui报错!

前言 comfyui以极高灵活度及节点化工作流&#xff0c;深受AI绘画者追捧&#xff0c;每当新的模型开源&#xff0c;comfyui都是最先进行适配。 comfyui高度兼容性及灵活性带来丰富强大的扩展&#xff08;插件&#xff09;生态&#xff0c;同时也带来一系列插件安装的问题&…

Python程序结构

模块 Module 定义&#xff1a;包含一系列数据、函数、类的文件&#xff0c;通常以.py结尾。 作用&#xff1a;让一些相关的数据&#xff0c;函数&#xff0c;类有逻辑的组织在一起&#xff0c;使逻辑结构更加清晰。 有利于多人合作开发。 导入 import 语法&#xff1a; im…

【目标检测实验系列】YOLOv5/YOLOv8改进:CARAFE轻量级上采样算子,聚合上下文信息,助力模型涨点(文内附源码)

1. 文章主要内容 本篇博客主要涉及轻量级上采样算子CARAFE&#xff0c;将YOLOv5/YOLOv8模型中最近邻上采样算子改为CARAFE算子&#xff0c;使模型聚合上下文信息&#xff0c;助力模型涨点。 2. 简要概括 论文地址&#xff1a;CARAFE论文地址 论文Github代码&#xff1a…

Go语言 Defer(延迟)

本文主要内容为Go语言中defer(延迟)介绍及应用文件读取使用defer的示例。 目录 定义 应用场景 代码示例 改为匿名函数 总结 定义 延迟&#xff1a;关键字&#xff0c;可以用于修饰语句、函数&#xff0c; 确保这条语句可以在当前栈退出的时候执行。 应用场景 1.一般用于…

【leetcode】特殊数组I【(炒鸡)简单】

好像这题没啥子好说的欸&#xff0c;那就祝点进来的友友今天有好事发生叭~ AC代码见下&#xff1a; class Solution { public:bool isArraySpecial(vector<int>& nums) {for(int i1; i<nums.size(); i)if(nums[i]%2 nums[i-1]%2) return false;return true;} }…

如何妙用哈希表来优化遍历查找过程?刷题感悟总结,c++实现

先上题目 题目链接&#xff1a;题目链接 这题我最先想到的就是前缀和a&#xff0c;构造好了以后就遍历每一个[l,r]数组&#xff08;满足题目要求的连续区间数组&#xff09;&#xff0c;奈何倒数第二个样例时间超限 先给出原思路代码 class Solution { public:int subarray…

网络如何发送一个数据包

网络如何发送一个数据包 网络消息发送就是点一点屏幕。 骚瑞&#xff0c;这一点都不好笑。&#xff08;小品就是我的本质惹&#xff09; 之前我就是会被这个问题搞的不安宁。是怎么知道对方的IP地址的呢&#xff1f;怎么知道对方的MAC呢&#xff1f;世界上计算机有那么多&…

top250的电影

本次的电影排行来源于豆瓣。材料仅用于自身学习和记录自己学习过程 使用python中的requests、BeautifulSoup、xlwt&#xff0c;三者需要提前下载好。。 预处理&#xff1a; url&#xff1a;反应网页变化 其中start后面的数字变化每次加25&#xff0c;对应一页&#xff0c;故…

用exceljs和file-saver插件实现纯前端表格导出Excel(支持样式配置,多级表头)

exceljs在Jquery&#xff08;HTML&#xff09;和vue项目中实现导出功能 前言Jquery&#xff08;HTML&#xff09;中实现导出第一步&#xff0c;先在项目本地中导入exceljs和file-saver包第二步&#xff0c;封装导出Excel方法&#xff08;可直接复制粘贴使用&#xff09;第三步&…

JJ音乐,听歌自由!

林俊杰&#xff0c;这位才华横溢的音乐才子&#xff0c;用他的音符编织了一个又一个令人陶醉的梦幻世界。作为他的音乐爱好者&#xff0c;每一次倾听都是一次心灵的旅程。 他的歌声仿佛有一种魔力&#xff0c;能够穿透灵魂。从《江南》的诗意浪漫&#xff0c;到《不为谁而作的歌…

探索树莓派Pico 2:新一代RP2350芯片引领的微型开发革命

Raspberry Pi Pico 2 是由树莓派基金会推出的微处理器开发板&#xff0c;作为Pico系列的最新成员&#xff0c;它在原有的基础上进行了多项改进和扩展。这款开发板搭载了全新的RP2350芯片&#xff0c;具有更强大的处理能力和更多的功能特性。 1. Raspberry Pi Pico 2的特性和规格…