首页 > 其他分享 >prometheus添加自定义监控与告警(etcd为例)

prometheus添加自定义监控与告警(etcd为例)

时间:2023-11-04 23:46:43浏览次数:29  
标签:monitoring name 自定义 为例 prometheus etcd k8s port

一、步骤及注意事项(前提,部署参考部署篇)

  1. 一般etcd集群会开启HTTPS认证,因此访问etcd需要对应的证书
  2. 使用证书创建etcd的secret
  3. 将etcd的secret挂在到prometheus
  4. 创建etcd的servicemonitor对象(匹配kube-system空间下具有k8s-app=etcd标签的service)
  5. 创建service关联被监控对象

二、实际操作步骤(etcd证书默认路径:/etc/kubernetes/pki/etcd/)

1、创建etcd的secret

cd /etc/kubernetes/pki/etcd/
kubectl create secret generic etcd-certs --from-file=healthcheck-client.crt --from-file=healthcheck-client.key --from-file=ca.crt -n monitoring

2、添加secret到名为k8s的prometheus对象上(kubectl edit prometheus k8s -n monitoring或者修改yaml文件并更新资源)

复制代码
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  labels:
    prometheus: k8s
  name: k8s
  namespace: monitoring
spec:
  alerting:
    alertmanagers:
    - name: alertmanager-main
      namespace: monitoring
      port: web
  baseImage: quay.io/prometheus/prometheus
  nodeSelector:
    kubernetes.io/os: linux
  podMonitorNamespaceSelector: {}
  podMonitorSelector: {}
  replicas: 2
  secrets:
  - etcd-certs
  resources:
    requests:
      memory: 400Mi
  ruleSelector:
    matchLabels:
      prometheus: k8s
      role: alert-rules
  securityContext:
    fsGroup: 2000
    runAsNonRoot: true
    runAsUser: 1000
  serviceAccountName: prometheus-k8s
  serviceMonitorNamespaceSelector: {}
  serviceMonitorSelector: {}
  version: v2.11.0
复制代码

3、创建servicemonitoring对象

复制代码
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: etcd-k8s
  namespace: monitoring
  labels:
    k8s-app: etcd-k8s
spec:
  jobLabel: k8s-app
  endpoints:
  - port: port
    interval: 30s
    scheme: https
    tlsConfig:
      caFile: /etc/prometheus/secrets/etcd-certs/ca.crt
      certFile: /etc/prometheus/secrets/etcd-certs/healthcheck-client.crt
      keyFile: /etc/prometheus/secrets/etcd-certs/healthcheck-client.key
      insecureSkipVerify: true
  selector:
    matchLaels:
      k8s-app: etcd
  namespaceSelector:
    matchNames:
    - kube-system
复制代码

4、创建service并自定义endpoint(考虑到etcd可能部署在kubernetes集群外,因此自定义endpoint)

复制代码
apiVersion: v1
kind: Service
metadata:
  name: etcd-k8s
  namespace: kube-system
  labels:
    k8s-app: etcd
spec:
  type: ClusterIP
  clusterIP: None
  ports:
  - name: port
    port: 2379
    protocol: TCP

---
apiVersion: v1
kind: Endpoints
metadata:
  name: etcd-k8s
  namespace: kube-system
  labels:
    k8s-app: etcd
subsets:
- addresses:
  - ip: 1.1.1.11
- ip: 1.1.1.12
- ip: 1.1.1.13
    nodeName: etcd-master
  ports:
  - name: port
    port: 2379
    protocol: TCP
复制代码

此处正常能通过prometheus的页面看到对应的监控信息了

若监控中出现报错:connection refused,修改/etc/kubernetes/manifests下的etcd.yaml文件

方法一:--listen-client-urls=https://0.0.0.0:2379

方法二:--listen-client-urls=https://127.0.0.1:2379,https://1.1.1.11:2379

 

三、创建自定义告警

  1. 创建一个prometheusRule资源后再prometheus的pod中会生成对应的告警配置文件
  2. 注意:此处的标签一定要匹配
  3. 告警项:若etcd集群有一半以上的节点可用,则认为集群可用,否则产生告警
复制代码
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  labels:
    prometheus: k8s
    role: alert-rules
  name: etcd-rules
  namespace: monitoring
spec:
  groups:
  - name: etcd-exporter.rules
    rules:
    - alert: EtcdClusterUnavailable
      annotations:
        summary: etcd cluster small
        description: If one more etcd peer goes down the cluster will be unavailable
      expr: |
        count(up{job="etcd"} == 0) > (count(up{job="etcd"}) / 2-1)
      for: 3m
      labels:
        severity: critical

标签:monitoring,name,自定义,为例,prometheus,etcd,k8s,port
From: https://www.cnblogs.com/A121/p/17810060.html

相关文章

  • 如何做到像坚果云这样自定义 Windows 文件资源管理器的 UI?
    要像坚果云那样自定义Windows文件资源管理器的UI,你可以尝试以下几个步骤:开发一个Shell扩展:使用WindowsShell编程,你可以开发一个Shell扩展程序,它可以插入到Windows文件资源管理器中,并扩展其功能。可以使用编程语言,如C++或C#来编写Shell扩展。注册Shell扩展:一旦你开发完成Shell扩展,......
  • Layui自定义icon图标
    在使用Layui进行开发时,会使用:<iclass="layui-icon">&#xe60c;</i>或者<iclass="layui-iconlayui-icon-face-smile"style="font-size:30px;color:#1E9FFF;"></i>进行图标的引入,但是官方给的图标毕竟有限,有时候没有自己想要的,但在阿里巴巴矢量图标库(ht......
  • 自定义简单的axios方法
    functionmyAxios(config){returnnewPromise((resolve,reject)=>{constxhr=newXMLHttpRequest()//如果存在想要放在链接后的参数?name=1&password=2if(config.params){constparamsObj=newURLSearchParams(conf......
  • springboot自定义Starter(超简捷)
    啥也不说,新建一个新的Maven项目引入Spring必要依赖autoconfigure这个依赖是SpringBoot框架的自动配置依赖,它包含了大量的自动配置类,用于根据应用程序的配置和环境,在应用程序启动时自动配置各种组件和属性。通过这个依赖,可以实现一些常见的配置,如数据库连接、缓存、消息队列......
  • prometheus docker部署安装
    prometheusprometheusdocker部署安装之前用docker-compose部署过一套自动注册的prometheus,也用k8s的operator部署过一套,详情见promethues栏的文档。时隔许久,今天在自己虚拟机部署一套promethues玩玩准备工作准备三台虚拟机,规格均为1C2G20G,因为是自己玩,所以对性能啥的不要......
  • prometheus Error on ingesting samples that are too old or a re too far into the
    目录prometheusErroroningestingsamplesthataretoooldoraretoofarintothefuture磁盘问题时间问题版本问题历史prometheus旧数据prometheusErroroningestingsamplesthataretoooldoraretoofarintothefuture之前在自己服务器上用docker部署过一个p......
  • Prometheus接入(四、Spring Boot接入)
    环境CentOS7.9+SpringBoot2.6.8安装1、依赖引入<!--预设监控--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-registry-prometheus</artifactId></depen......
  • Linux环境Prometheus接入(三、MySQL监控接入mysqld_exporter)
    环境CentOS7.9安装1、命令下载wgethttps://github.com/prometheus/mysqld_exporter/releases/download/v0.15.0/mysqld_exporter-0.15.0.linux-amd64.tar.gztar-zxfmysqld_exporter-0.15.0.linux-amd64.tar.gzmvmysqld_exporter-0.15.0.linux-amd64.tar.gz/home/mysq......
  • Linux环境Prometheus接入(四、系统监控接入node_exporter)
    环境CentOS7.9安装1、命令下载wgethttps://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gztar-zxfnode_exporter-1.6.1.linux-amd64.tar.gzmvnode_exporter-1.6.1.linux-amd64/home/node_exporter2、配置系......
  • 创建自定义美颜滤镜:使用第三方美颜SDK的步骤指南
    美颜滤镜在现代移动应用和直播平台中变得越来越受欢迎。它们可以让用户在自拍照片、视频聊天或实时直播中看起来更加美丽和自信。如果您是一位应用开发者,想要增加美颜滤镜功能,但又不想从头开始构建整个系统,那么使用第三方美颜SDK可能是一个明智的选择。第1步:选择适合的第三方美颜SD......