prometheus监控域名证书到期时间

2023-05-16

参考:https://mp.weixin.qq.com/s/gXffcNzixAiTKSBZcf2sBA

最终效果图:

下面全部使用docker部署:

一、部署prometheus

这是一个默认的prometheus配置文件:


[root@localhost prometheus]# cat prometheus.yml 
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).
​
# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
​
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
​
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
​
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
​
    static_configs:
    - targets: ['localhost:9090']  

[root@localhost prometheus]# docker run -d --name prometheus -p 9090:9090 -v ${PWD}:/etc/prometheus  prom/prometheus:v2.25.0  

网页访问9090测试

二、部署grafana


[root@localhost ~]# docker run -d --name=grafana -p 3000:3000    grafana/grafana:7.2.2  

访问3000端口,并配置prometheus数据源

三、部署blackbox-exporter

Blackbox_exporter是prometheus官方的组件,github地址: https://github.com/prometheus/blackbox_exporter

配置文件使用官方默认的,更多配置可以参考官方example.yml:


[root@localhost blackbox-exporter]# cat blackbox.yml 
modules:
  http_2xx:  # http 检测模块  Blockbox-Exporter 中所有的探针均是以 Module 的信息进行配置
    prober: http
    timeout: 10s
    http:
      valid_http_versions: ["HTTP/1.1", "HTTP/2"]   
      valid_status_codes: [200]  # 这里最好作一个返回状态码,在grafana作图时,有明示---陈刚注释。
      method: GET
      preferred_ip_protocol: "ip4"
  http_post_2xx: # http post 监测模块
    prober: http
    timeout: 10s
    http:
      valid_http_versions: ["HTTP/1.1", "HTTP/2"]
      method: POST
      preferred_ip_protocol: "ip4"
  tcp_connect:  # TCP 检测模块
    prober: tcp
    timeout: 10s
  dns:  # DNS 检测模块
    prober: dns
    dns:
      transport_protocol: "tcp"  # 默认是 udp
      preferred_ip_protocol: "ip4"  # 默认是 ip6
      query_name: "kubernetes.default.svc.cluster.local"  

[root@localhost blackbox-exporter]# docker run  -d -p 9115:9115 --name blackbox_exporter -v `pwd`:/config prom/blackbox-exporter:master --config.file=/config/blackbox.yml  

访问9115端口测试

四、prometheus配置文件里添加job,对blackbox数据进行收集

这段内容从官方文档抄过来的:


[root@localhost prometheus]# tail -17 prometheus.yml 
  - job_name: 'blackbox'
    metrics_path: /probe
    params:
      module: [http_2xx]  # Look for a HTTP 200 response.
    static_configs:
      - targets:
        - http://prometheus.io    # Target to probe with http.
        - https://prometheus.io   # Target to probe with https.
        - https://jd.com # Target to probe with http on port 8080.
        - https://www.bejson.com # Target to probe with http on port 8080.
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 172.17.0.3:9115  # The blackbox exporter's real hostname:port.  

Lifecycle api没有开启(curl -X POST http://127.0.0.1:9090/-/reload),只能手动重载配置:


[root@localhost prometheus]# docker exec -it prometheus kill -1 1  

prometheus页面查看target

五、prometheus导入dashborad

使用的dashboard是这个: https://grafana.com/grafana/dashboards/13230

六、看效果

七、设置prometheus告警

首先在prometheus.yml文件里面通过rule_files指定告警规则文件的访问路径


/etc/prometheus/rules $ cat /etc/prometheus/prometheus.yml
rule_files:
  - "/etc/prometheus/rules/*.rules"  

然后编辑ssl告警规则文件


/etc/prometheus $ mkdir /etc/prometheus/rules
/etc/prometheus/rules $ cat /etc/prometheus/rules/ssl-expire-alert.rules 
groups:
- name: ssl_expiry
  rules:
  - alert: Ssl Cert Will Expire in 30 days
    expr: probe_ssl_earliest_cert_expiry - time() < 86400 * 300
    for: 5m
    labels:
      severity: warning
    annotations:
      summary: "SSL certificate will expire soon on (instance {{ $labels.instance }})"
      description: "SSL certificate expires in 30 days\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"  

prometheus加载配置文件


/etc/prometheus/rules $ kill -1 1  

去prometheus界面查看告警,已经有了

八、配置alertmanager邮件告警

部署alertmanager,配置文件是默认的,没有改


/alertmanager $ cat /etc/alertmanager/alertmanager.yml 
global:
  resolve_timeout: 5m

route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 1h
  receiver: 'web.hook'
receivers:
- name: 'web.hook'
  webhook_configs:
  - url: 'http://127.0.0.1:5001/'
inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'dev', 'instance']  

➜  alertmanager docker run --name alertmanager -d -v $(pwd)/alertmanager.yml:/etc/alertmanager/alertmanager.yml -p 9093:9093 prom/alertmanager:v0.21.0  

网页访问测试:

关联prometheus和alertmanager,此时需要修改prometheus.yml,添加alertmanager配置


/prometheus $ cat /etc/prometheus/prometheus.yml
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - 172.17.0.7:9093  

加载prometheus配置


/prometheus $ kill -1 1  

刷新alertmanager页面,发现告警已经过来了

修改alertmanager配置文件,配置邮件告警:

alertmanager重载配置文件:


/alertmanager $ kill -1 1  

查看邮箱有没有收到邮件(如果没收到的话要看下alertmanager的日志有什么报错,比如smtp服务器连不上,或者配置文件某一行格式不对)

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

prometheus监控域名证书到期时间 的相关文章

随机推荐

  • 令人厌恶的错误MSB3721,以及win10,VS2019,YOLO V4 环境搭建

    总结一下yolo环境的搭建 xff0c 以及MSB3721的一种解决方案 xff0c 如果有相似的背景 xff0c 不妨一试 另外在搭建环境的过程中 xff0c 感觉最浪费时间的就是下载所需的安装包 xff0c 因为是外网 xff0c 速度
  • python&多路归并

    问题 xff1a 在项目中 xff0c 需从待分析的数据中选出最大的前几名 xff0c 但由于数据量太大 xff0c 直接排序会内存报错 xff0c 因此尝试用多路归并的思路来解决问题 接口 xff1a 一个目录下有x个已排序好的csv 最
  • PX4飞控学习(四)

    系统启动 启动文件 xff1a nuttx arch arm stm32 stm32 start c stm32 clockconfig span class hljs regexp span 时钟 stm32 fpuconfig span
  • VSCode 搭建 C++ 开发环境

    文章目录 前言一 获取参考资料二 下载安装 VSCode三 安装编译器四 添加环境变量五 使用VSCode 开发 C 43 43 程序总结 前言 鲁迅曾说过 xff0c 不以敲代码为目的的学编程都是耍流氓 xff01 我最近在撸 C 43
  • Ubuntu安装VMware

    Ubuntu安装VMware xff08 1 xff09 需求 由于windows 的日渐卡顿还有变态的更新 xff0c 我的需求就是稳定单调优化好所以我通过Ubuntu 安装VMware xff0c 然后开启虚拟机继续学习 xff08 2
  • python实现TCP通信

    本例是在Ubuntu虚拟机中本机互传实现的TCP通信 一 TCP服务器端 xff08 server端 xff09 1 创建套接字 xff0c 绑定套接字到本地IP与端口 s 61 socket socket socket AF INET s
  • agrc argv解释

    以前经常看见过 xff1a int main int argc char argv 这样形式的main但是一直没有这样用直到研究点云时发现有个例子是 xff1a gt exe pcd 这样的doc下的命令才想起有这样的两个参数 xff0c
  • 个人面试细节、技巧总结(没有面试题哦!)

    面试除了自身技能过硬外 xff0c 良好的沟通 xff0c 平和的心态 xff0c 细节的拿捏也都是额外的加分项 最后 xff0c 以些许运气加以点缀 xff0c offer 便八九不离十了 参加工作两年有余 xff0c 只大专文凭 xff
  • 【记录】ORB-SLAM3编译以及在realsense D435i运行

    环境 xff1a 最开始用的是源码是ORB SLAM3 的1 0版本 xff0c 但是编译的时候出错太多了 xff0c 超出了能力范围 xff0c 更换了0 4 beta版本 xff0c 但是这个版本在运行的时候会直接segmentatio
  • ArtiPub

    ArtiPub ArtiPub Article Publisher的简称 xff0c 意为 34 文章发布者 34 是一款开源的一文多发平台 xff0c 可以帮助文章作者将编写好的文章自动发布到掘金 SegmentFault CSDN 知乎
  • mac安装配置zsh

    mac安装配置zsh 比mac自带的shell好用太多 一 安装homebrew 参考 xff1a https brew sh index zh cn bin bash c span class token string 34 span c
  • 手把手教你给win10 2004版本的ubuntu1804子系统安装docker

    ubuntu1804子系统安装docker ce 分两种情况 xff1a 1 win10版本小于2004版本2 win10版本大于2004版本 一 说明 win10版本小于2004的话 xff0c 可以使用WSL1 0 xff0c WSL1
  • windows安装scoop

    参考 xff1a https scoop sh 参考 xff1a https github com lukesampson scoop wiki Quick Start 懂不懂 xff0c 先装上 xff0c 这样你就完成了该工具学习的第一
  • PX4飞控学习(五)

    PX4的应用 程序入口为 程序名 main int argc char argv 这里实现应用参数 主循环函数在 task main int argc char argv thread main int argc char argv 等函数
  • 转载kubernetes 1.9 与 CentOS 7.3 内核兼容问题

    20201022转载kubernetes 1 9 与 CentOS 7 3 内核兼容问题 原文 xff1a http www linuxfly org kubernetes 19 conflict with centos7 生产环境发现不定
  • 【转载】为什么说Prometheus是足以取代Zabbix的监控神器?

    原文 xff1a https www infoq cn article 275NDkYNZRpcTIL2R8Ms 原文 xff1a https mp weixin qq com s biz 61 MzI4NTA1MDEwNg 61 61 a
  • 【转载】K8S 问题排查:cgroup 内存泄露问题

    转载 K8S 问题排查 xff1a cgroup 内存泄露问题 原文 xff1a http www xuyasong com p 61 2049 前言 这篇文章的全称应该叫 xff1a 在某些内核版本上 xff0c cgroup 的 kme
  • 【可用】prometheus邮件报警配置

    参考 xff1a https github com prometheus alertmanager issues 384 参考 xff1a https github com easzlab kubeasz issues 448 使用QQ邮箱
  • 【案例】微服务-中台-业务关系图(来自processon)

    微服务 中台 业务关系图 知识云微服务架构 微服务开发平台规划架构图 微服务架构图 物联网微服务无业务架构 阿里中台技术在大型企业数字化转型的架构图 阿里中台战略笔记
  • prometheus监控域名证书到期时间

    参考 xff1a https mp weixin qq com s gXffcNzixAiTKSBZcf2sBA 最终效果图 xff1a 下面全部使用docker部署 xff1a 一 部署prometheus 这是一个默认的promethe