prometheus-operator 監控 Rabbitmq集羣

  首先咱們監控服務須要知道prometheus-operator是如何去工做的,纔好去寫相關的yaml配置,這裏我劃分紅了5個部分,若是容器服務自己就以k8s來編排的,那就只須要三步,這裏由於個人rabbitmq是部署在外面因此須要5步,它們分別是:python

 1.建立 Endpoints  # 將外部服務映射進來
 2.建立 Service   # 建立servicName,嫌麻煩也能夠不寫,這裏1,2步只是爲了隱藏真實的地址
 3.建立採集工具使用deploy部署
 4.建立採集工具Service ##clusterIP: None
 5.建立ServiceMonitorvim

個人MQ管理地址爲 192.168.100.192 : 15672api

vim prometheus-rabbitmq.yamlapp

apiVersion: v1
kind: Endpoints
metadata:
  name: rabbitmq-management
  labels:
    k8s-app: rabbitmq-management
subsets:
- addresses:
  - ip: 192.168.100.192
  ports:
  - name: api
    port: 15672
    protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq-management
  labels:
    k8s-app: rabbitmq-management
spec:
  type: ClusterIP
  ports:
  - name: api
    port: 15672
    protocol: TCP
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: rabbitmq-exporter
spec:
  replicas: 1
  template:
    metadata:
      labels:
        k8s-app: rabbitmq-exporter
    spec:
      containers:
      - name: rabbitmq-exporter
        image: kbudde/rabbitmq-exporter
        env:
         - name: PUBLISH_PORT
           value: "9099"
         - name: RABBIT_CAPABILITIES
           value: "bert,no_sort"
         - name: RABBIT_USER
           value: "you user"
         - name: RABBIT_PASSWORD
           value: "you password"
         - name: RABBIT_URL
           value: http://rabbitmq-management:15672
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9099
---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq-exporter
  labels:
    k8s-app: rabbitmq-exporter
spec:
  type: ClusterIP
  clusterIP: None
  selector:
    k8s-app: rabbitmq-exporter
  ports:
  - name: api
    port: 9099
    protocol: TCP

 kuctl apply -f prometheus-rabbitmq.yaml -n 指定命名空間 PS:個人是以項目+環境來區分的curl

 

上述能夠進行測試工具

訪問 curl http://10.244.6.145:9099/metrics測試

建立ServiceMonitor 讓其可以自動發現並註冊url

vim prometheus-rabbitmq-k8s-monitoring.yamlspa

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: rabbitmq-exporter
  namespace: monitoring
  labels:
    k8s-app: rabbitmq-exporter
    namespace: monitoring
spec:
  jobLabel: k8s-app
  endpoints:
  - port: api
    interval: 30s
    scheme: http
  selector:
    matchLabels:
      k8s-app: rabbitmq-exporter
  namespaceSelector:
    matchNames:
    - default    #你採集的數據在哪裏,就寫它的namespaces

最後 kubectl apply -f prometheus-rabbitmq-k8s-monitoring.yamlcode

模版是獲取的官網新增了namespaces變量,這樣就方便多了。

至於規則告警,能夠根據本身想要監測的數據來進行報警就很少說了。

相關文章
相關標籤/搜索