自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

通過Prometheus來做SLI/SLO監(jiān)控展示

開源
SRE通常通過這兩個(gè)指標(biāo)來衡量系統(tǒng)的穩(wěn)定性,其主要思路就是通過SLI來判斷SLO,也就是通過一系列的指標(biāo)來衡量我們的目標(biāo)是否達(dá)到了"幾個(gè)9"。

[[391678]]

什么是SLI/SLO

SLI,全名Service Level Indicator,是服務(wù)等級(jí)指標(biāo)的簡(jiǎn)稱,它是衡定系統(tǒng)穩(wěn)定性的指標(biāo)。

SLO,全名Sevice Level Objective,是服務(wù)等級(jí)目標(biāo)的簡(jiǎn)稱,也就是我們?cè)O(shè)定的穩(wěn)定性目標(biāo),比如"4個(gè)9","5個(gè)9"等。

SRE通常通過這兩個(gè)指標(biāo)來衡量系統(tǒng)的穩(wěn)定性,其主要思路就是通過SLI來判斷SLO,也就是通過一系列的指標(biāo)來衡量我們的目標(biāo)是否達(dá)到了"幾個(gè)9"。

如何選擇SLI

在系統(tǒng)中,常見的指標(biāo)有很多種,比如:

  • 系統(tǒng)層面:CPU使用率、內(nèi)存使用率、磁盤使用率等
  • 應(yīng)用服務(wù)器層面:端口存活狀態(tài)、JVM的狀態(tài)等
  • 應(yīng)用運(yùn)行層面:狀態(tài)碼、時(shí)延、QPS等
  • 中間件層面:QPS、TPS、時(shí)延等
  • 業(yè)務(wù)層面:成功率、增長(zhǎng)速度等

這么多指標(biāo),應(yīng)該如何選擇呢?只要遵從兩個(gè)原則就可以:

  • 選擇能夠標(biāo)識(shí)一個(gè)主體是否穩(wěn)定的指標(biāo),如果不是這個(gè)主體本身的指標(biāo),或者不能標(biāo)識(shí)主體穩(wěn)定性的,就要排除在外。
  • 優(yōu)先選擇與用戶體驗(yàn)強(qiáng)相關(guān)或用戶可以明顯感知的指標(biāo)。

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

  • V:Volume,容量,服務(wù)承諾的最大容量
  • A:Availability,可用性,服務(wù)是否正常
  • L:Latency,延遲,服務(wù)的響應(yīng)時(shí)間
  • E:Error,錯(cuò)誤率,請(qǐng)求錯(cuò)誤率是多少
  • T:Ticket,人工介入,是否需要人工介入

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

上面僅僅是簡(jiǎn)單的介紹了一下SLI/SLO,更多的知識(shí)可以學(xué)習(xí)《SRE:Google運(yùn)維解密》和趙成老師的極客時(shí)間課程《SRE實(shí)踐手冊(cè)》。下面來簡(jiǎn)單介紹如何使用Prometheus來進(jìn)行SLI/SLO監(jiān)控。

service-level-operator

Service level operator是為了Kubernetes中的應(yīng)用SLI/SLO指標(biāo)來衡量應(yīng)用的服務(wù)指標(biāo),并可以通過Grafana來進(jìn)行展示。

Operator主要是通過SLO來查看和創(chuàng)建新的指標(biāo)。例如:

  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:總請(qǐng)求數(shù)
  • errorQuery:錯(cuò)誤請(qǐng)求數(shù)

Operator通過totalQuert和errorQuery就可以計(jì)算出SLO的指標(biāo)了。

部署service-level-operator

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

(1)首先創(chuàng)建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)然后創(chuàng)建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)創(chuàng)建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)創(chuàng)建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上查看到對(duì)應(yīng)的Target,如下:

然后就需要?jiǎng)?chuàng)建對(duì)應(yīng)的服務(wù)指標(biāo)了,如下所示創(chuàng)建一個(gè)示例。

  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應(yīng)用"4個(gè)9"的SLO。

然后可以在Prometheus上看到具體的指標(biāo),如下。

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

上面是SLI,下面是錯(cuò)誤總預(yù)算和已消耗的錯(cuò)誤。

下面可以定義告警規(guī)則,當(dāng)SLO下降時(shí)可以第一時(shí)間收到,比如:

  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. 

第一條規(guī)則表示在1h內(nèi)消耗的錯(cuò)誤率大于30天內(nèi)的2%,應(yīng)該告警。第二條規(guī)則是在6h內(nèi)的錯(cuò)誤率大于30天的5%,應(yīng)該告警。

下面是谷歌的的基準(zhǔn)。

最后

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

目前業(yè)界有兩種衡量系統(tǒng)可用性的方式,一個(gè)是時(shí)間維度,一個(gè)是請(qǐng)求維度。時(shí)間維度就是從故障出發(fā)對(duì)系統(tǒng)的穩(wěn)定性進(jìn)行評(píng)估。請(qǐng)求維度是從成功請(qǐng)求占比的角度出發(fā),對(duì)系統(tǒng)穩(wěn)定性進(jìn)行評(píng)估。

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

請(qǐng)求維度:可用性 = 成功請(qǐng)求數(shù) / 總請(qǐng)求數(shù)

在SRE實(shí)踐中,通常會(huì)選擇請(qǐng)求維度來衡量系統(tǒng)的穩(wěn)定性,就如上面的例子。不過,如果僅僅通過一個(gè)維度來判斷系統(tǒng)的穩(wěn)定性也有點(diǎn)太武斷,還應(yīng)該結(jié)合更多的指標(biāo),比如延遲,錯(cuò)誤率等,而且對(duì)核心應(yīng)用,核心鏈路的SLI應(yīng)該更細(xì)致。

參考

[1] 《SRE實(shí)踐手冊(cè)》- 趙成

[2] 《SRE:Google運(yùn)維解密》

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

 

責(zé)任編輯:姜華 來源: 運(yùn)維開發(fā)故事
相關(guān)推薦

2021-07-27 11:05:52

云計(jì)算

2020-12-02 10:38:13

Prometheus微服務(wù)架構(gòu)

2022-01-05 08:29:22

監(jiān)控Prometheus Post

2024-11-27 10:44:48

2023-09-06 08:46:47

2022-06-01 17:47:24

運(yùn)維監(jiān)控系統(tǒng)

2020-06-16 09:17:33

ESRedis監(jiān)控

2020-05-11 09:00:57

Redis監(jiān)控Zabbix

2021-04-30 11:10:24

博睿數(shù)據(jù)DataViewSLO

2022-05-18 08:32:05

服務(wù)監(jiān)控Prometheus開源

2020-12-30 08:09:46

運(yùn)維Prometheus 監(jiān)控

2020-10-20 09:07:11

監(jiān)控PrometheusZabbix

2022-05-19 08:21:02

vmalert監(jiān)控

2023-10-09 07:31:25

2022-07-11 09:36:38

SpringJava開發(fā)

2022-11-08 00:00:00

監(jiān)控系統(tǒng)Prometheus

2022-07-08 08:00:31

Prometheus監(jiān)控

2020-11-20 08:15:40

Grafana + P

2022-12-13 08:01:06

監(jiān)控黑盒集成

2020-12-29 10:45:22

運(yùn)維Prometheus-監(jiān)控
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)