容器化 | 構(gòu)建 RadonDB MySQL 集群監(jiān)控平臺

上一篇文章我們演示了如何《在 S3 備份恢復(fù) RadonDB MySQL 集群數(shù)據(jù)》,本文將演示在 KubeSphere[1] 中使用 Prometheus[2] + Grafana[3] 構(gòu)建 MySQL 監(jiān)控平臺,開啟所需監(jiān)控指標(biāo)。

背景

Prometheus 基于文本的暴露格式,已經(jīng)成為云原生監(jiān)控領(lǐng)域事實上的標(biāo)準(zhǔn)格式。

RadonDB MySQL 監(jiān)控引擎基于 Prometheus MySQLd Exporter[5] 定義。通過 mysqld-exporter 抓取 RadonDB MySQL 服務(wù)指標(biāo),再通過接入第三方應(yīng)用平臺實現(xiàn)監(jiān)控指標(biāo)可視化。

準(zhǔn)備工作

  • 已準(zhǔn)備可用 Kubernetes 或 KubeSphere 集群
  • 已部署 RadonDB MySQL 集群 《部署文檔》
  • RadonDB MySQL Kubernetes 版本 2.1.0+

部署步驟

步驟 1: 配置 serviceMonitor

serviceMonitor 開啟后將自動綁定 mysqld_exporter 與 Prometheus。

serviceMonitor 參數(shù)包含如下字段:

serviceMonitor:
  enabled: true
  ## Additional labels for the serviceMonitor. Useful if you have multiple prometheus operators running to select only specific ServiceMonitors
  # additionalLabels:
  #   prometheus: prom-internal
  interval: 10s
  scrapeTimeout: 3s
  # jobLabel:
  # targetLabels:
  # podTargetLabels:
  namespaceSelector:
    any: true
  selector:
    matchLabels:
      app.kubernetes.io/managed-by: mysql.radondb.com
      app.kubernetes.io/name: mysql

您可以在 charts/mysql-operator/values.yaml 文件中配置 serviceMonitor。

  • 新部署 Operator 時, serviceMonitor.enabled 默認(rèn)為 true,表示默認(rèn)開啟。
  • 已部署 Operator 2.1.0 以下版本的集群,需重新部署 Operator。

步驟 2: 配置 metricsOpts

metricsOpts 是 CRD mysqlclusters.mysql.radondb.com 中定義 RadonDB MySQL 集群監(jiān)控的參數(shù),可通過配置mysql_v1alpha1_mysqlcluster.yaml 文件中參數(shù)值開啟監(jiān)控服務(wù)。

metricsOpts 參數(shù)包含如下字段:

metricsOpts:
    enabled: false  
    image: prom/mysqld-exporter:v0.12.1

    resources:
      requests:
        cpu: 10m
        memory: 32Mi
      limits:
        cpu: 100m
        memory: 128Mi

metricsOpts.enabled 默認(rèn)為 false,需手動設(shè)置為 true。

  • 設(shè)置 metricsOpts.enabledtrue,開啟集群監(jiān)控功能;
  • 設(shè)置資源參數(shù)值,定義監(jiān)控容器資源配額大??;

文件參數(shù)修改完成后,使用如下指令應(yīng)用配置,部署/更新集群回顯信息如下:

$ kubectl apply -f config/sample/mysql_v1alpha1_mysqlcluster.yaml
cluster.mysql.radondb.com/sample created/configured

查看監(jiān)控服務(wù)

通過客戶端查看

您可以通過如下指令查看集群監(jiān)控服務(wù)和 serviceMonitor 信息。

$ kubectl get service,servicemonitor

$ kubectl describe servicemonitor <serviceName>

預(yù)期效果

$ kubectl get service,servicemonitor
NAME                             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/mysql-operator-metrics   ClusterIP   10.96.242.205   <none>        8443/TCP   3h25m
service/sample-follower          ClusterIP   10.96.2.234     <none>        3306/TCP   21h
service/sample-leader            ClusterIP   10.96.30.238    <none>        3306/TCP   21h
service/sample-metrics           ClusterIP   10.96.7.222     <none>        9104/TCP   3h24m
service/sample-mysql             ClusterIP   None            <none>        3306/TCP   21h

NAME                                                              AGE
servicemonitor.monitoring.coreos.com/demo-mysql-operator          3h25m

$ kubectl describe servicemonitor demo-mysql-operator 
Name:         test-radondb-mysql-metrics
Namespace:    default
Labels:       app=test-radondb-mysql
              app.kubernetes.io/managed-by=Helm
              app.kubernetes.io/vendor=kubesphere
              chart=radondb-mysql-1.0.0
              heritage=Helm
              release=test
Annotations:  kubesphere.io/creator: admin
API Version:  monitoring.coreos.com/v1
Kind:         ServiceMonitor
......
Spec:
  Endpoints:
    Interval:        1m
    Path:            /metrics
    Port:            metrics
    Scheme:          http
    Scrape Timeout:  10s
......

在 KubeSphere 平臺查看

在 KubeSphere 企業(yè)空間部署的 RadonDB MySQL Operator 和集群,開啟監(jiān)控后,可在如下頁面查看監(jiān)控服務(wù)狀態(tài)。

  • 在項目空間應(yīng)用負載下的服務(wù)頁面,點擊 <集群名稱>-metrics,可查看監(jiān)控服務(wù)信息。
file
  • 在項目空間應(yīng)用負載下的容器組頁面,點擊一個容器的名稱,可查看該容器中 metrics 資源狀態(tài)。
file

查看監(jiān)控內(nèi)容

通過 KubeSphere 自定義監(jiān)控

KubeSphere 的監(jiān)控引擎基于 Prometheus 和 Prometheus Operator。使用 KubeSphere 的自定義監(jiān)控功能支持以可視化的形式監(jiān)控 RadonDB MySQL 指標(biāo)。

  • 在集群同一項目中,選擇 監(jiān)控告警 -> 自定義監(jiān)控 -> 創(chuàng)建;
  • 在對話框中,選擇 MySQL 模版,并繼續(xù)配置監(jiān)控模版;
file
  • 點擊 保存模版,即新創(chuàng)建監(jiān)控面板。
file
  • 新建監(jiān)控面板需等待約十分鐘,即可查看監(jiān)控數(shù)據(jù)。
file

更多詳情,請查看 KubeSphere 自定義監(jiān)控介紹[6] 和 可視化監(jiān)控[7]。

通過 Prometheus + Grafana 平臺

Grafana 是一個跨平臺、開源的數(shù)據(jù)可視化網(wǎng)絡(luò)應(yīng)用程序平臺。通過 Prometheus + Grafana 平臺查看監(jiān)控基本原理如下:

  • 通過 mysql_exporter 獲取 RadonDB MySQL 服務(wù)監(jiān)控數(shù)據(jù).
  • 通過 node_exporter 獲得 RadonDB MySQL 服務(wù)器的監(jiān)控數(shù)據(jù)。
  • 將監(jiān)控數(shù)據(jù)傳到 Prometheus 后,通過配置數(shù)據(jù)源,最終在 Grafana 呈現(xiàn)豐富的監(jiān)控數(shù)據(jù)圖表和警告。
file

更多 Grafana 可視化監(jiān)控使用說明,請參見 Grafana Dashboards[8]。

參考引用

  1. KubeSphere:https://kubesphere.com.cn
  2. Prometheus:https://prometheus.io/
  3. Grafana:https://grafana.org/
  4. RadonDB MySQL Kubernetes 2.1.3:https://radondb.com/projects/mysql/
  5. Prometheus MySQLd Exporter:https://github.com/prometheus/mysqld_exporter
  6. 自定義監(jiān)控:https://kubesphere.io/zh/docs/project-user-guide/custom-application-monitoring/introduction/
  7. 可視化監(jiān)控:https://kubesphere.io/zh/docs/project-user-guide/custom-application-monitoring/visualization/overview/
  8. Grafana Dashboards:https://grafana.com/docs/grafana/latest/dashboards/
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容