Redis

במאמר הזה מוסבר איך להגדיר את הפריסה של Google Kubernetes Engine כדי להשתמש בשירות מנוהל של Google Cloud ל-Prometheus ולאסוף מדדים מ-Redis. במאמר הזה מוסבר איך:

  • מגדירים את כלי הייצוא ל-Redis כדי לדווח על מדדים.
  • אפשר לגשת למרכז בקרה מוגדר מראש ב-Cloud Monitoring כדי לראות את המדדים.
  • הגדרת כללי התראה למעקב אחר המדדים.

ההוראות האלה רלוונטיות רק אם אתם משתמשים ב אוסף מנוהל עם השירות המנוהל ל-Prometheus. אם אתם משתמשים באיסוף שמוטמע באופן עצמאי, תוכלו לעיין במאגר המקור של Redis exporter כדי לקבל מידע על ההתקנה.

ההוראות האלה הן דוגמה, והן אמורות לפעול ברוב סביבות Kubernetes. אם נתקלתם בבעיה בהתקנת אפליקציה או כלי לייצוא בגלל מדיניות אבטחה או מדיניות ארגונית מגבילה, מומלץ לעיין במסמכי קוד פתוח לקבלת תמיכה.

מידע על Redis זמין במאמר Redis.

דרישות מוקדמות

כדי לאסוף מדדים מ-Redis באמצעות שירות מנוהל ל-Prometheus ואיסוף מנוהל, הפריסה צריכה לעמוד בדרישות הבאות:

  • האשכול צריך להריץ את Google Kubernetes Engine בגרסה ‎1.28.15-gke.2475000 ואילך.
  • צריך להפעיל את השירות המנוהל ל-Prometheus עם איסוף מנוהל. מידע נוסף זמין במאמר תחילת השימוש באוסף מנוהל.

  • כדי להשתמש בלוחות הבקרה שזמינים ב-Cloud Monitoring לשילוב של Redis, צריך להשתמש בגרסה v1.43.1 ואילך.redis_exporter

    מידע נוסף על לוחות הבקרה הזמינים מופיע במאמר הצגת לוחות בקרה.

התקנת כלי הייצוא של Redis

מומלץ להתקין את Redis exporter, redis_exporter, כ-sidecar לעומס העבודה של Redis. מידע על שימוש ב-sidecars זמין במאמר הרחבת אפליקציות ב-Kubernetes באמצעות pods מרובי-קונטיינרים.

כדי להתקין את redis_exporter כקונטיינר sidecar ל-Redis, משנים את ההגדרה של Redis כמו בדוגמה הבאה:

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
  labels:
    app.kubernetes.io/name: redis
spec:
  selector:
    matchLabels:
+     app.kubernetes.io/name: redis
  template:
    metadata:
      labels:
+       app.kubernetes.io/name: redis
    spec:
      containers:
      - name: redis
        image: "redis:6.2"
        ... 
+     - name: redis-exporter
+       image: oliver006/redis_exporter:v1.43.1
+       args: [--include-system-metrics]
+       resources:
+         requests:
+           cpu: 100m
+           memory: 100Mi
+       ports:
+       - containerPort: 9121
    ...

צריך להוסיף להגדרה את כל השורות שמופיע לפניהן הסמל +.

ההוראות האלה מניחות שכבר יש לכם התקנה פעילה של Redis ואתם רוצים לשנות אותה כדי לכלול כלי לייצוא. אם אתם צריכים להגדיר גם את Redis, אתם יכולים להגדיר ולהחיל את תרשים Bitnami Helm. מעבירים את ערכי ההגדרה הבאים:
  • metrics.enabled = true
  • metrics.podLabels = {app.kubernetes.io/name: redis}

כדי להחיל שינויים בתצורה מקובץ מקומי, מריצים את הפקודה הבאה:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

אפשר גם להשתמש ב-Terraform כדי לנהל את ההגדרות.

הגדרה של משאב PodMonitoring

לצורך גילוי יעדים, ל-Managed Service for Prometheus Operator נדרש משאב PodMonitoring שתואם ל-Redis exporter באותו מרחב שמות.

אפשר להשתמש בהגדרה הבאה של PodMonitoring:

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
  name: redis
  labels:
    app.kubernetes.io/name: redis
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: redis
  endpoints:
  - port: 9121
    interval: 30s

מוודאים שבוררי התוויות והיציאה תואמים לבוררים וליציאה שבהם השתמשתם בהתקנת כלי הייצוא של Redis.

כדי להחיל שינויים בתצורה מקובץ מקומי, מריצים את הפקודה הבאה:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

אפשר גם להשתמש ב-Terraform כדי לנהל את ההגדרות.

הגדרת כללים והתראות

אתם יכולים להשתמש בהגדרות Rules הבאות כדי להגדיר התראות על מדדי Redis:

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: monitoring.googleapis.com/v1
kind: Rules
metadata:
  name: redis-rules
  labels:
    app.kubernetes.io/component: rules
    app.kubernetes.io/name: redis-rules
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  groups:
  - name: redis
    interval: 30s
    rules:
    - alert: RedisDown
      annotations:
        description: |-
          Redis instance is down 
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: Redis down (instance {{ $labels.instance }})
      expr: redis_up{job="redis"} == 0
      for: 5m
      labels:
        severity: critical
    - alert: RedisOutOfMemory
      annotations:
        description: |-
          Redis is running out of memory (> 90%)
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: Redis out of memory (instance {{ $labels.instance }})
      expr: redis_memory_used_bytes{job="redis"} / redis_total_system_memory_bytes{job="redis"}
        * 100 > 90
      for: 5m
      labels:
        severity: warning
    - alert: RedisTooManyConnections
      annotations:
        description: |-
          Redis instance has too many connections
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: Redis too many connections (instance {{ $labels.instance }})
      expr: redis_connected_clients{job="redis"} > 100
      for: 5m
      labels:
        severity: warning
    - alert: RedisClusterSlotFail
      annotations:
        description: |-
          Redis cluster has slots fail
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: Number of hash slots mapping to a node in FAIL state (instance {{ $labels.instance }})
      expr: redis_cluster_slots_fail{job="redis"} > 0
      for: 5m
      labels:
        severity: warning
    - alert: RedisClusterSlotPfail
      annotations:
        description: |-
          Redis cluster has slots pfail
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: Number of hash slots mapping to a node in PFAIL state (instance {{ $labels.instance }})
      expr: redis_cluster_slots_pfail{job="redis"} > 0
      for: 5m
      labels:
        severity: warning
    - alert: RedisClusterStateNotOk
      annotations:
        description: |-
          Redis cluster is not ok 
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: Redis cluster state is not ok (instance {{ $labels.instance }})
      expr: redis_cluster_state{job="redis"} == 0
      for: 5m
      labels:
        severity: critical
    - expr: redis_memory_used_rss_bytes{job="redis"} / redis_memory_used_bytes{job="redis"}
      record: redis_memory_fragmentation_ratio

כדי להחיל שינויים בתצורה מקובץ מקומי, מריצים את הפקודה הבאה:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

אפשר גם להשתמש ב-Terraform כדי לנהל את ההגדרות.

מידע נוסף על החלת כללים על האשכול זמין במאמר הערכה והתראות של כללים מנוהלים.

ההגדרה Rules הזו מבוססת על הכללים וההתראות שנתרמו למאגר redis_exporter.

אימות ההגדרה

אפשר להשתמש ב-Metrics Explorer כדי לוודא שהגדרתם את Redis exporter בצורה נכונה. יכול להיות שיחלפו דקה או שתיים עד שמערכת Cloud Monitoring תעבד את המדדים.

כדי לוודא שהמדדים נאספים, מבצעים את הפעולות הבאות:

  1. במסוף Google Cloud , עוברים לדף  Metrics explorer:

    כניסה אל Metrics Explorer

    אם משתמשים בסרגל החיפוש כדי למצוא את הדף הזה, בוחרים בתוצאה שכותרת המשנה שלה היא Monitoring.

  2. בסרגל הכלים של חלונית הכלי ליצירת שאילתות, לוחצים על הלחצן ששמו הוא  MQL או  PromQL.
  3. מוודאים שהאפשרות PromQL נבחרה במתג שפה. המתג לשפה נמצא באותו סרגל כלים שבו אפשר לעצב את השאילתה.
  4. מזינים ומריצים את השאילתה הבאה:
    up{job="redis", cluster="CLUSTER_NAME", namespace="NAMESPACE_NAME"}
    

הצגת מרכזי בקרה

השילוב עם Cloud Monitoring כולל את לוח הבקרה Redis Prometheus Overview. לוחות הבקרה מותקנים באופן אוטומטי כשמגדירים את השילוב. אפשר גם לראות תצוגות מקדימות סטטיות של מרכזי בקרה בלי להתקין את האינטגרציה.

כדי לראות מרכז בקרה שהותקן:

  1. במסוף Google Cloud , עוברים לדף  Dashboards:

    מעבר אל מרכזי בקרה

    אם משתמשים בסרגל החיפוש כדי למצוא את הדף הזה, בוחרים בתוצאה שכותרת המשנה שלה היא Monitoring.

  2. לוחצים על הכרטיסייה רשימת מרכזי בקרה.
  3. בוחרים בקטגוריה שילובים.
  4. לוחצים על השם של מרכז הבקרה, לדוגמה, Redis Prometheus Overview.

כדי לראות תצוגה מקדימה סטטית של מרכז הבקרה:

  1. נכנסים לדף  Integrations במסוף Google Cloud :

    עוברים אל Integrations

    אם משתמשים בסרגל החיפוש כדי למצוא את הדף הזה, בוחרים בתוצאה שכותרת המשנה שלה היא Monitoring.

  2. לוחצים על המסנן Kubernetes Engine של פלטפורמת הפריסה.
  3. מאתרים את השילוב של Redis ולוחצים על הצגת פרטים.
  4. לוחצים על הכרטיסייה מרכזי בקרה.

פתרון בעיות

מידע על פתרון בעיות בהוספת מדדים זמין במאמר פתרון בעיות שקשורות להוספה, בקטע בעיות באיסוף נתונים ממייצאים.