Apache ActiveMQ

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

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

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

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

מידע על Apache ActiveMQ זמין במאמר ActiveMQ.

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

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

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

  • כדי להשתמש בלוחות הבקרה שזמינים ב-Cloud Monitoring לשילוב של ActiveMQ, צריך להשתמש בגרסה 0.17.0 ואילך של jmx-exporter.

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

אפשר להגדיר את ActiveMQ Brokers ל-JMX על ידי הגדרת משתני הסביבה ACTIVEMQ_JMX ו-ACTIVEMQ_OPTS.

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

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

כדי להתקין את jmx-exporter כקובץ עזר ל-ActiveMQ, צריך לשנות את ההגדרה של ActiveMQ כמו בדוגמה הבאה:

# 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: v1
kind: ConfigMap
metadata:
  name: activemq-exporter
data:
  config.yaml: |
    hostPort: localhost:1099
    lowercaseOutputName: true
    lowercaseOutputLabelNames: true
    blacklistObjectNames:
      - "org.apache.activemq:clientId=*,*"
    whitelistObjectNames:
      - "org.apache.activemq:destinationType=Queue,*"
      - "org.apache.activemq:destinationType=Topic,*"
      - "org.apache.activemq:type=Broker,brokerName=*"
      - "org.apache.activemq:type=Topic,brokerName=*"

    rules:
    - pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Queue, destinationName=(\S*)><>(\w+)
      name: activemq_queue_$3
      attrNameSnakeCase: true
      labels:
        destination: $2

    - pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Topic, destinationName=(\S*)><>(\w+)
      name: activemq_topic_$3
      attrNameSnakeCase: true
      labels:
        destination: $2

    - pattern: org.apache.activemq<type=Broker, brokerName=(\S*)><>CurrentConnectionsCount
      name: activemq_connections
      type: GAUGE

    - pattern: org.apache.activemq<type=Broker, brokerName=(\S*)><>Total(.*)Count
      name: activemq_$2_total
      type: COUNTER

    - pattern: org.apache.activemq<type=Broker, brokerName=(\S*)><>(.*)PercentUsage
      name: activemq_$2_usage_ratio
      type: GAUGE
      valueFactor: 0.01
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: activemq
spec:
  selector:
    matchLabels:
+     app.kubernetes.io/name: activemq
  template:
    metadata:
      labels:
+       app.kubernetes.io/name: activemq
    spec:
      containers:
      - name: activemq
        image: rmohr/activemq:5.15.9-alpine
+       ports:
+         - containerPort: 1099
+           name: jmx
+       env:
+         - name: ACTIVEMQ_JMX
+           value: "1099"
+         - name: ACTIVEMQ_OPTS
+           value: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.rmi.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
+     - name: exporter
+       image: bitnami/jmx-exporter:0.17.0
+       command:
+         - java
+         - -jar
+         - jmx_prometheus_httpserver.jar
+       args:
+         - "9000"
+         - config.yaml
+       ports:
+       - containerPort: 9000
+         name: prometheus
+       volumeMounts:
+       - mountPath: /opt/bitnami/jmx-exporter/config.yaml
+         subPath: config.yaml
+         name: activemq-exporter
+     volumes:
+     - name: activemq-exporter
+       configMap:
+         name: activemq-exporter
+         items:
+         - key: config.yaml
+           path: config.yaml

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

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

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

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

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

כדי לגלות את היעד, ל-שירות מנוהל ל-Prometheus Operator נדרש משאב PodMonitoring שתואם ל-JMX 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: activemq
  labels:
    app.kubernetes.io/name: activemq
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  endpoints:
  - port: prometheus
    scheme: http
    interval: 30s
    path: /metrics
  selector:
    matchLabels:
      app.kubernetes.io/name: activemq

מוודאים שהסלקטורים של התוויות והיציאה תואמים לסלקטורים וליציאה שבהם השתמשתם בקטע התקנת כלי הייצוא של ActiveMQ.

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

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

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

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

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

# 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: activemq-rules
  labels:
    app.kubernetes.io/component: rules
    app.kubernetes.io/name: activemq-rules
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  groups:
  - name: activemq
    interval: 30s
    rules:
    - alert: ActiveMQNoConnections
      annotations:
        description: |-
          ActiveMQ no connections
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: ActiveMQ down (instance {{ $labels.instance }})
      expr: activemq_connections_total{job="activemq"} == 0
      for: 5m
      labels:
        severity: warning
    - alert: ActiveMQHighStoreUsage
      annotations:
        description: |-
          ActiveMQ high store usage
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: ActiveMQ high store usage (instance {{ $labels.instance }})
      expr: activemq_store_usage_ratio{job="activemq"} > 0.9
      for: 5m
      labels:
        severity: warning
    - alert: ActiveMQHighTempStoreUsage
      annotations:
        description: |-
          ActiveMQ high temp store usage
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: ActiveMQ high temp store usage (instance {{ $labels.instance }})
      expr: activemq_temp_usage_ratio{job="activemq"} > 0.9
      for: 5m
      labels:
        severity: warning

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

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

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

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

אימות ההגדרה

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

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

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

    כניסה אל Metrics Explorer

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

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

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

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

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

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

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

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

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

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

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

    עוברים אל Integrations

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

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

פתרון בעיות

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