成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

通過Prometheus來做SLI/SLO監控展示

開源
SRE通常通過這兩個指標來衡量系統的穩定性,其主要思路就是通過SLI來判斷SLO,也就是通過一系列的指標來衡量我們的目標是否達到了"幾個9"。

[[391678]]

什么是SLI/SLO

SLI,全名Service Level Indicator,是服務等級指標的簡稱,它是衡定系統穩定性的指標。

SLO,全名Sevice Level Objective,是服務等級目標的簡稱,也就是我們設定的穩定性目標,比如"4個9","5個9"等。

SRE通常通過這兩個指標來衡量系統的穩定性,其主要思路就是通過SLI來判斷SLO,也就是通過一系列的指標來衡量我們的目標是否達到了"幾個9"。

如何選擇SLI

在系統中,常見的指標有很多種,比如:

  • 系統層面:CPU使用率、內存使用率、磁盤使用率等
  • 應用服務器層面:端口存活狀態、JVM的狀態等
  • 應用運行層面:狀態碼、時延、QPS等
  • 中間件層面:QPS、TPS、時延等
  • 業務層面:成功率、增長速度等

這么多指標,應該如何選擇呢?只要遵從兩個原則就可以:

  • 選擇能夠標識一個主體是否穩定的指標,如果不是這個主體本身的指標,或者不能標識主體穩定性的,就要排除在外。
  • 優先選擇與用戶體驗強相關或用戶可以明顯感知的指標。

通常情況下,可以直接使用谷歌的VALET指標方法。

  • V:Volume,容量,服務承諾的最大容量
  • A:Availability,可用性,服務是否正常
  • L:Latency,延遲,服務的響應時間
  • E:Error,錯誤率,請求錯誤率是多少
  • T:Ticket,人工介入,是否需要人工介入

這就是谷歌使用VALET方法給的樣例。

上面僅僅是簡單的介紹了一下SLI/SLO,更多的知識可以學習《SRE:Google運維解密》和趙成老師的極客時間課程《SRE實踐手冊》。下面來簡單介紹如何使用Prometheus來進行SLI/SLO監控。

service-level-operator

Service level operator是為了Kubernetes中的應用SLI/SLO指標來衡量應用的服務指標,并可以通過Grafana來進行展示。

Operator主要是通過SLO來查看和創建新的指標。例如:

  1. apiVersion: monitoring.spotahome.com/v1alpha1 
  2. kind: ServiceLevel 
  3. metadata: 
  4.   name: awesome-service 
  5. spec: 
  6.   serviceLevelObjectives: 
  7.     - name"9999_http_request_lt_500" 
  8.       description: 99.99% of requests must be served with <500 status code. 
  9.       disable: false 
  10.       availabilityObjectivePercent: 99.99 
  11.       serviceLevelIndicator: 
  12.         prometheus: 
  13.           address: http://myprometheus:9090 
  14.           totalQuery: sum(increase(http_request_total{host="awesome_service_io"}[2m])) 
  15.           errorQuery: sum(increase(http_request_total{host="awesome_service_io", code=~"5.."}[2m])) 
  16.       output
  17.         prometheus: 
  18.           labels: 
  19.             team: a-team 
  20.             iteration: "3" 
  • availabilityObjectivePercent:SLO
  • totalQuery:總請求數
  • errorQuery:錯誤請求數

Operator通過totalQuert和errorQuery就可以計算出SLO的指標了。

部署service-level-operator

  • 前提:在Kubernetes集群中部署好Prometheus,我這里是采用Prometheus-Operator方式進行部署的。

(1)首先創建RBAC

  1. apiVersion: v1 
  2. kind: ServiceAccount 
  3. metadata: 
  4.   name: service-level-operator 
  5.   namespace: monitoring 
  6.   labels: 
  7.     app: service-level-operator 
  8.     component: app 
  9.  
  10. --- 
  11. apiVersion: rbac.authorization.k8s.io/v1 
  12. kind: ClusterRole 
  13. metadata: 
  14.   name: service-level-operator 
  15.   labels: 
  16.     app: service-level-operator 
  17.     component: app 
  18. rules: 
  19.   # Register and check CRDs. 
  20.   - apiGroups: 
  21.       - apiextensions.k8s.io 
  22.     resources: 
  23.       - customresourcedefinitions 
  24.     verbs: 
  25.       - "*" 
  26.  
  27.   # Operator logic. 
  28.   - apiGroups: 
  29.       - monitoring.spotahome.com 
  30.     resources: 
  31.       - servicelevels 
  32.       - servicelevels/status 
  33.     verbs: 
  34.       - "*" 
  35.  
  36. --- 
  37. kind: ClusterRoleBinding 
  38. apiVersion: rbac.authorization.k8s.io/v1 
  39. metadata: 
  40.   name: service-level-operator 
  41. subjects: 
  42.   - kind: ServiceAccount 
  43.     name: service-level-operator 
  44.     namespace: monitoring  
  45. roleRef: 
  46.   apiGroup: rbac.authorization.k8s.io 
  47.   kind: ClusterRole 
  48.   name: service-level-operator 

(2)然后創建Deployment

  1. apiVersion: apps/v1  
  2. kind: Deployment 
  3. metadata: 
  4.   name: service-level-operator 
  5.   namespace: monitoring 
  6.   labels: 
  7.     app: service-level-operator 
  8.     component: app 
  9. spec: 
  10.   replicas: 1 
  11.   selector: 
  12.     matchLabels: 
  13.       app: service-level-operator 
  14.       component: app 
  15.   strategy: 
  16.     rollingUpdate: 
  17.       maxUnavailable: 0 
  18.   template: 
  19.     metadata: 
  20.       labels: 
  21.         app: service-level-operator 
  22.         component: app 
  23.     spec: 
  24.       serviceAccountName: service-level-operator 
  25.       containers: 
  26.         - name: app 
  27.           imagePullPolicy: Always 
  28.           image: quay.io/spotahome/service-level-operator:latest 
  29.           ports: 
  30.             - containerPort: 8080 
  31.               name: http 
  32.               protocol: TCP 
  33.           readinessProbe: 
  34.             httpGet: 
  35.               path: /healthz/ready 
  36.               port: http 
  37.           livenessProbe: 
  38.             httpGet: 
  39.               path: /healthz/live 
  40.               port: http 
  41.           resources: 
  42.             limits: 
  43.               cpu: 220m 
  44.               memory: 254Mi 
  45.             requests: 
  46.               cpu: 120m 
  47.               memory: 128Mi 

(3)創建service

  1. apiVersion: v1 
  2. kind: Service 
  3. metadata: 
  4.   name: service-level-operator 
  5.   namespace: monitoring 
  6.   labels: 
  7.     app: service-level-operator 
  8.     component: app 
  9. spec: 
  10.   ports: 
  11.     - port: 80 
  12.       protocol: TCP 
  13.       name: http 
  14.       targetPort: http 
  15.   selector: 
  16.     app: service-level-operator 
  17.     component: app 

(4)創建prometheus serviceMonitor

  1. apiVersion: monitoring.coreos.com/v1 
  2. kind: ServiceMonitor 
  3. metadata: 
  4.   name: service-level-operator 
  5.   namespace: monitoring 
  6.   labels: 
  7.     app: service-level-operator 
  8.     component: app 
  9.     prometheus: myprometheus 
  10. spec: 
  11.   selector: 
  12.     matchLabels: 
  13.       app: service-level-operator 
  14.       component: app 
  15.   namespaceSelector: 
  16.     matchNames: 
  17.       - monitoring  
  18.   endpoints: 
  19.     - port: http 
  20.       interval: 10s 

到這里,Service Level Operator部署完成了,可以在prometheus上查看到對應的Target,如下:

然后就需要創建對應的服務指標了,如下所示創建一個示例。

  1. apiVersion: monitoring.spotahome.com/v1alpha1 
  2. kind: ServiceLevel 
  3. metadata: 
  4.   name: prometheus-grafana-service 
  5.   namespace: monitoring 
  6. spec: 
  7.   serviceLevelObjectives: 
  8.     - name"9999_http_request_lt_500" 
  9.       description: 99.99% of requests must be served with <500 status code. 
  10.       disable: false 
  11.       availabilityObjectivePercent: 99.99 
  12.       serviceLevelIndicator: 
  13.         prometheus: 
  14.           address: http://prometheus-k8s.monitoring.svc:9090 
  15.           totalQuery: sum(increase(http_request_total{service="grafana"}[2m])) 
  16.           errorQuery: sum(increase(http_request_total{service="grafana", code=~"5.."}[2m])) 
  17.       output
  18.         prometheus: 
  19.           labels: 
  20.             team: prometheus-grafana  
  21.             iteration: "3" 

上面定義了grafana應用"4個9"的SLO。

然后可以在Prometheus上看到具體的指標,如下。

接下來在Grafana上導入ID為8793的Dashboard,即可生成如下圖表。

上面是SLI,下面是錯誤總預算和已消耗的錯誤。

下面可以定義告警規則,當SLO下降時可以第一時間收到,比如:

  1. groups: 
  2.   - name: slo.rules 
  3.     rules: 
  4.       - alert: SLOErrorRateTooFast1h 
  5.         expr: | 
  6.           ( 
  7.             increase(service_level_sli_result_error_ratio_total[1h]) 
  8.             / 
  9.             increase(service_level_sli_result_count_total[1h]) 
  10.           ) > (1 - service_level_slo_objective_ratio) * 14.6 
  11.         labels: 
  12.           severity: critical 
  13.           team: a-team 
  14.         annotations: 
  15.           summary: The monthly SLO error budget consumed for 1h is greater than 2% 
  16.           description: The error rate for 1h in the {{$labels.service_level}}/{{$labels.slo}} SLO error budget is being consumed too fast, is greater than 2% monthly budget. 
  17.       - alert: SLOErrorRateTooFast6h 
  18.         expr: | 
  19.           ( 
  20.             increase(service_level_sli_result_error_ratio_total[6h]) 
  21.             / 
  22.             increase(service_level_sli_result_count_total[6h]) 
  23.           ) > (1 - service_level_slo_objective_ratio) * 6 
  24.         labels: 
  25.           severity: critical 
  26.           team: a-team 
  27.         annotations: 
  28.           summary: The monthly SLO error budget consumed for 6h is greater than 5% 
  29.           description: The error rate for 6h in the {{$labels.service_level}}/{{$labels.slo}} SLO error budget is being consumed too fast, is greater than 5% monthly budget. 

第一條規則表示在1h內消耗的錯誤率大于30天內的2%,應該告警。第二條規則是在6h內的錯誤率大于30天的5%,應該告警。

下面是谷歌的的基準。

最后

說到系統穩定性,這里不得不提到系統可用性,SRE提高系統的穩定性,最終還是為了提升系統的可用時間,減少故障時間。那如何來衡量系統的可用性呢?

目前業界有兩種衡量系統可用性的方式,一個是時間維度,一個是請求維度。時間維度就是從故障出發對系統的穩定性進行評估。請求維度是從成功請求占比的角度出發,對系統穩定性進行評估。

時間維度:可用性 = 服務時間 / (服務時間 + 故障時間)

請求維度:可用性 = 成功請求數 / 總請求數

在SRE實踐中,通常會選擇請求維度來衡量系統的穩定性,就如上面的例子。不過,如果僅僅通過一個維度來判斷系統的穩定性也有點太武斷,還應該結合更多的指標,比如延遲,錯誤率等,而且對核心應用,核心鏈路的SLI應該更細致。

參考

[1] 《SRE實踐手冊》- 趙成

[2] 《SRE:Google運維解密》

[3] https://github.com/spotahome/service-level-operator

 

責任編輯:姜華 來源: 運維開發故事
相關推薦

2021-07-27 11:05:52

云計算

2020-12-02 10:38:13

Prometheus微服務架構

2022-01-05 08:29:22

監控Prometheus Post

2024-11-27 10:44:48

2023-09-06 08:46:47

2022-06-01 17:47:24

運維監控系統

2021-04-30 11:10:24

博睿數據DataViewSLO

2020-06-16 09:17:33

ESRedis監控

2020-05-11 09:00:57

Redis監控Zabbix

2022-05-18 08:32:05

服務監控Prometheus開源

2020-12-30 08:09:46

運維Prometheus 監控

2022-07-11 09:36:38

SpringJava開發

2023-10-09 07:31:25

2022-05-19 08:21:02

vmalert監控

2020-10-20 09:07:11

監控PrometheusZabbix

2022-07-08 08:00:31

Prometheus監控

2022-11-08 00:00:00

監控系統Prometheus

2020-11-20 08:15:40

Grafana + P

2022-12-13 08:01:06

監控黑盒集成

2020-12-29 10:45:22

運維Prometheus-監控
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美国产激情二区三区 | 久久久久久久亚洲精品 | 亚洲风情在线观看 | 国产一级在线观看 | 国产精品免费看 | 国产免费人成xvideos视频 | 成人免费大片黄在线播放 | 亚洲日本成人 | 欧美成人猛片aaaaaaa | www.久久99 | 国产成人免费 | 久久久福利 | 成人av播放 | 国产精品福利在线 | 亚洲天堂中文字幕 | 色吧色综合| 黄色片免费看 | 999精品视频 | 国产精品国产a | 久久鲁视频 | 久久久高清 | 成人精品国产免费网站 | 欧美日韩精品免费观看 | 日韩中文欧美 | 亚洲免费在线播放 | 欧美综合视频在线 | 亚洲中字在线 | 久久视频免费看 | 91精品国产91久久久久久 | 国产a级毛片 | 毛片一级电影 | 91精品国产色综合久久 | av在线免费观看网址 | 日韩三级在线 | 欧美在线a | 久久91| 中文字幕二区 | 午夜在线免费观看 | 一道本不卡视频 | 欧美二区在线 | 激情久久网 |