prometheus通过blackbox-exporter监控web站点证书

这篇具有很好参考价值的文章主要介绍了prometheus通过blackbox-exporter监控web站点证书。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1 概述

线上站点普遍是https,因此监控https web站点的证书的过期时间,是一个基础性需求。例如,证书过期会导致tls握手失败,进而导致用户无法正常访问web站点。
blackbox-expoter是一个web服务,它暴露了一个接口,访问这个接口能使得它去访问目标站点,并向客户端响应相关的web站点指标信息。prometheus和black-expoter结合使用,可以监控https web站点的响应时间、证书过期时间等。


2 blackbox-expoter

2.1 指标接口

格式:
GET /probe?module=模块名&target=<网址>
例子:
GET /probe?module=http_get_2xx&target=https://www.baidu.com

prometheus 监控ssl证书,prometheus,prometheus


2.2 部署

blackbox-exporter的配置中定义了多种模块,例如ping,http_get_2xx等,模块名称可以自行定义。

apiVersion: v1
kind: Namespace
metadata:
  name: monitoring
  
---

apiVersion: v1
kind: Service
metadata:
  name: blackbox-exporter
  namespace: monitoring
  labels:
    k8s-app: blackbox-exporter
spec:
  type: ClusterIP
  ports:
  - name: http
    port: 9115
    targetPort: 9115
  selector:
    k8s-app: blackbox-exporter
    
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: blackbox-exporter
  namespace: monitoring
  labels:
    k8s-app: blackbox-exporter
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: blackbox-exporter
  template:
    metadata:
      labels:
        k8s-app: blackbox-exporter
    spec:
      containers:
      - name: blackbox-exporter
        image: prom/blackbox-exporter:latest
        args:
        - --config.file=/etc/blackbox_exporter/blackbox.yml
        - --web.listen-address=:9115
        - --log.level=info
        ports:
        - name: http
          containerPort: 9115
        resources:
          limits:
            cpu: 200m
            memory: 256Mi
          requests:
            cpu: 100m
            memory: 50Mi
        livenessProbe:
          tcpSocket:
            port: 9115
          initialDelaySeconds: 5
          timeoutSeconds: 5
          periodSeconds: 10
          successThreshold: 1
          failureThreshold: 3
        readinessProbe:
          tcpSocket:
            port: 9115
          initialDelaySeconds: 5
          timeoutSeconds: 5
          periodSeconds: 10
          successThreshold: 1
          failureThreshold: 3
        volumeMounts:
        - name: config
          mountPath: /etc/blackbox_exporter
      volumes:
      - name: config
        configMap:
          name: blackbox-exporter

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: blackbox-exporter
  namespace: monitoring
  labels:
    app: blackbox-exporter
data:
  blackbox.yml: |-
    modules:
      ## ----------- TCP 检测模块配置 -----------
      tcp_connect:
        prober: tcp
        timeout: 5s
      ## ----------- ICMP 检测配置 -----------
      ping:
        prober: icmp
        timeout: 5s
        icmp:
          preferred_ip_protocol: "ip4"
      ## ----------- HTTP GET 2xx 检测模块配置 -----------
      http_get_2xx:  
        prober: http
        timeout: 10s
        http:
          method: GET
          preferred_ip_protocol: "ip4"
          valid_http_versions: ["HTTP/1.1","HTTP/2"]
          valid_status_codes: [200]           # 验证的HTTP状态码,默认为2xx
          no_follow_redirects: false          # 是否不跟随重定向
      ## ----------- HTTP GET 3xx 检测模块配置 -----------
      http_get_3xx:  
        prober: http
        timeout: 10s
        http:
          method: GET
          preferred_ip_protocol: "ip4"
          valid_http_versions: ["HTTP/1.1","HTTP/2"]
          valid_status_codes: [301,302,304,305,306,307]  # 验证的HTTP状态码,默认为2xx
          no_follow_redirects: false                     # 是否不跟随重定向
      ## ----------- HTTP POST 监测模块 -----------
      http_post_2xx: 
        prober: http
        timeout: 10s
        http:
          method: POST
          preferred_ip_protocol: "ip4"
          valid_http_versions: ["HTTP/1.1", "HTTP/2"]
          #headers:                             # HTTP头设置
          #  Content-Type: application/json
          #body: '{}'                           # 请求体设置

prometheus 监控ssl证书,prometheus,prometheus
prometheus 监控ssl证书,prometheus,prometheus


3 部署prometheus

apiVersion: v1
kind: Namespace
metadata:
  name: monitoring

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus-app
  namespace: monitoring

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: prometheus-app
  name: prometheus-app
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus-app
  template:
    metadata:
      labels:
        app: prometheus-app
      name: prometheus-app
    spec:
      containers:
      - args:
        - --config.file=/etc/prometheus/prometheus.yml
        - --storage.tsdb.retention=7d
        - --web.enable-lifecycle
        - --log.level=debug
        image: prom/prometheus:v2.31.0
        imagePullPolicy: IfNotPresent
        name: prometheus
        ports:
        - containerPort: 9090
          name: web
          protocol: TCP
        volumeMounts:
        - mountPath: /etc/prometheus
          name: config-volume
        - mountPath: /etc/prometheus/etc.d
          name: blackbox-web-target
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      serviceAccount: prometheus-app
      serviceAccountName: prometheus-app
      volumes:
      - configMap:
          name: prometheus-app
        name: config-volume
      - configMap:
          name: blackbox-web-target
        name: blackbox-web-target

---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: prometheus-app
    name: prometheus-app
  name: prometheus-app
  namespace: monitoring
spec:
  ports:
  - name: http
    port: 9090
    protocol: TCP
    targetPort: 9090
  selector:
    app: prometheus-app
  sessionAffinity: None
  type: ClusterIP

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: prometheus
rules:
- apiGroups:
  - ""
  resources:
  - nodes
  - nodes/proxy
  - services
  - endpoints
  - pods
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - configmaps
  verbs:
  - get
- nonResourceURLs:
  - /metrics
  verbs:
  - get

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
  name: prometheus
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: prometheus
subjects:
- kind: ServiceAccount
  name: prometheus-app
  namespace: monitoring

---
apiVersion: v1
data:
  prometheus.yml: |-
    global:
      scrape_interval: 15s
    scrape_configs:
    - job_name: blackbox
      metrics_path: /probe
      params:
        module: [http_get_2xx]			#  会变成http的参数:module=http_get_2xx
      file_sd_configs:         
      - files: 
        - '/etc/prometheus/etc.d/web.yml'           # 被监控的目标站点是写在此文件
        refresh_interval: 30s 						# 30秒热更新一次,不必重启prometheus
      relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target			# 会变成http的参数:target=目标url
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: blackbox-exporter.monitoring.svc.cluster.local:9115
kind: ConfigMap
metadata:
  name: prometheus-app
  namespace: monitoring

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: blackbox-web-target
  namespace: monitoring
  labels:
    app: blackbox-exporter
data:
  web.yml: |-
    ---
    - targets:
      - https://www.baidu.com         # 被监控的站点
      labels:
        env: prod
        app: baidu-web
        project: baidu
        desc: desc for baidu web
    - targets:
      - https://blog.csdn.net	       # 被监控的站点
      labels:
        env: prod
        app: csdn-web
        project: csdn
        desc: desc for csdn

prometheus 监控ssl证书,prometheus,prometheus

4 promethues界面效果

prometheus 监控ssl证书,prometheus,prometheus

prometheus 监控ssl证书,prometheus,prometheus

指标probe_ssl_earliest_cert_expiry表示证书的过期时间的时间戳,那么以下公式表示多少秒后证书过期:

probe_ssl_earliest_cert_expiry - time()  

5 grafana

5.1 部署

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: monitoring
  labels:
    app: grafana
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      containers:        
        - name: grafana
          image: grafana/grafana
          resources:
            limits:
              memory: "128Mi"
              cpu: "50m"
          readinessProbe:
            httpGet:
              path: /api/health
              port: 3000
            initialDelaySeconds: 15
            periodSeconds: 10
          livenessProbe:
            tcpSocket:
              port: 3000
            initialDelaySeconds: 15
            periodSeconds: 10
          ports:
            - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: monitoring
spec:
  selector:
    app: grafana
  type: NodePort
  ports:
  - protocol: TCP
    port: 3000

prometheus 监控ssl证书,prometheus,prometheus


5.2 配置数据源

添加prometheus数据源,prometheus实例在kubernetes中的service名称为prometheus-app,因此使用http://prometheus-app:9090作为地址即可。
prometheus 监控ssl证书,prometheus,prometheus

5.3 导入模板

使用编号为13230的grafana模板。
prometheus 监控ssl证书,prometheus,prometheus
prometheus 监控ssl证书,prometheus,prometheus
prometheus 监控ssl证书,prometheus,prometheus


6 小结

prometheus和blackbox-exporter一起协同监控web站点,blackbox-exporter作为一个中间层解耦prometheus和目标web站点,blackbox-exporter是真正去获取目标web站点证书并暴露metrics的服务,prometheus只需要抓取blackbox-exporter暴露的指标即可。文章来源地址https://www.toymoban.com/news/detail-808141.html

到了这里,关于prometheus通过blackbox-exporter监控web站点证书的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【kafka 监控】Kafka_exporter+prometheus 监控kafka数据

    一、kafka_exporter 安装步骤: Kafka_exporter是一款用于将Kafka集群的监控指标暴露给Prometheus的开源工具,可以用于监控Kafka集群的各种状态数据。下面是Kafka_exporter的安装和部署步骤: 环境准备 Java环境:Kafka_exporter需要Java环境支持,您可以在Oracle官网下载和安装Java的最新版本。

    2024年02月07日
    浏览(38)
  • 【监控系统】Prometheus监控组件Node-Exporter配置实战

    这一节,我们来配置一下Node-Exporter,那么我们先来了解一下什么是Prometheus的Exporter? 任何向Prometheus提供监控样本数据的程序都可以被称为一个Exporter,它是一种用于将不同数据源的指标提供给Prometheus进行收集和监控的工具。运行在应用程序、计算机、网络设备或者其他系统

    2024年02月15日
    浏览(34)
  • 【监控系统】Prometheus监控组件Mysql-Exporter配置实战

    Mysql-Exporter主要监控Mysql数据库的稳定性、吞吐量、连接情况、缓冲池使用情况、查询性能等各项指标,是我们压测时常常需要监控的一些指标。 目前,Exporter 支持高于5.6版本的 MySQL 和高于10.1版本的 MariaDB。在 MySQL/MariaDB 低于5.6版本时,部分监控指标可能无法被采集。 OK,下

    2024年02月16日
    浏览(30)
  • prometheus+mysql_exporter监控mysql

    prometheus+mysql_exporter监控mysql 一.安装mysql 1.下载: wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 2.安装客户端: yum -y install mysql57-community-release-el7-10.noarch.rpm 3.安装服务端: yum -y install mysql-community-server 4.启动服务: systemctl start mysqld.service 5.查看服务是否启动:

    2024年02月20日
    浏览(30)
  • Prometheus监控之SNMP Exporter介绍和数据展现

    由于技术能力有限,文章仅能进行简要分析和说明,如有不对的地方,请指正,谢谢🙂。 SNMP协议全称是:Simple Network Management Protocol,译为简单网络管理协议,是作为TCP/IP网络管理标准协议,为不同的设备提供统一接口,实现了网络设备之间的统一管理。 SNMP协议分为三个版

    2023年04月26日
    浏览(36)
  • Prometheus监控实战之node_exporter详解

    目录 1 概述 2 功能 2.1 不同操作系统采集端 2.2 linux操作系统采集端 2.3 监控指标 2.4 参数定义 2.4.1 默认启用的参数  2.4.2 默认不启用的参数 2.5 启动参数 3 安装部署 3.1 下载 3.2 安装配置 3.3 测试验证 3.4 prometheus配置 3.5 在 grafana 中添加图表   Exporter是Prometheus的指标数据收

    2024年02月03日
    浏览(36)
  • Prometheus监控Kafka(三种方法JMX Kafka_exporter KMINION监控Kafka)_kafka exporter

    公司需要监控kafka消息队列的消费情况,强调需查看当前Topic中的message的数量。 一句话说明解决: 像Kafka这样的Java进程可以先通过JMX Agent或者第三方Agent(kafka_exporterKMINION等)获取监控数据,再通过Prometheus采集数据、通过Grafana模板展示数据即可。另外具体的message数量需要通

    2024年04月25日
    浏览(31)
  • Kibana+Prometheus+node_exporter 监控告警部署

    下载好三个软件包 一、prometheus安装部署 1、解压  2、修改配置文件的IP地址 3、运行Prometheus 4、打开浏览器根据配置文件的地址和端口访问,如果状态栏看到的跟下图不一样,记得在标签栏中的Status状态选择Targets  二、node_exporter 安装部署 1、解压,运行  2、打开浏览器输入

    2024年02月15日
    浏览(43)
  • 【大数据监控】Prometheus、Node_exporter、Graphite_exporter安装部署详细文档

    Prometheus是一个开源的系统监控和报警系统,现在已经加入到CNCF基金会,成为继k8s之后第二个在CNCF托管的项目,在kubernetes容器管理系统中,通常会搭配prometheus进行监控,同时也支持多种exporter采集数据,还支持pushgateway进行数据上报,Prometheus性能足够支撑上万台规模的集群。

    2023年04月08日
    浏览(31)
  • 二进制部署Prometheus + Grafana监控集群,及各exporter安装

    Prometheus三大组件: Server 主要负责数据采集和存储,提供PromQL查询语言的支持。 Alertmanager 警告管理器,用来进行报警。 Push Gateway 支持临时性Job主动推送指标的中间网关。 Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB)。Prometheus使用Go语言开发,是Google B

    2024年02月13日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包