2.9.2. 収集サンプルアラートの作成

以下の場合に通知するアラートを作成できます。

  • ターゲットを収集できず、指定された for の期間利用できない
  • 指定された for の期間、収集サンプルのしきい値に達するか、またはこの値を上回る

前提条件

  • cluster-admin ロールを持つユーザーとして、または openshift-user-workload-monitoring プロジェクトの user-workload-monitoring-config-edit ロールを持つユーザーとして、クラスターにアクセスできる。
  • ユーザー定義プロジェクトのモニタリングを有効にしている。
  • user-workload-monitoring-config ConfigMap オブジェクトを作成している。
  • enforcedSampleLimit を使用して、ユーザー定義プロジェクトのターゲット収集ごとに受け入れ可能なサンプル数を制限している。
  • OpenShift CLI (oc) がインストールされている。

手順

  1. ターゲットがダウンし、実行されたサンプル制限に近づく際に通知するアラートを指定して YAML ファイルを作成します。この例のファイルは monitoring-stack-alerts.yaml という名前です。

    apiVersion: monitoring.coreos.com/v1
    kind: PrometheusRule
    metadata:
      labels:
        prometheus: k8s
        role: alert-rules
      name: monitoring-stack-alerts 1
      namespace: ns1 2
    spec:
      groups:
      - name: general.rules
        rules:
        - alert: TargetDown 3
          annotations:
            message: '{{ printf "%.4g" $value }}% of the {{ $labels.job }}/{{ $labels.service
              }} targets in {{ $labels.namespace }} namespace are down.' 4
          expr: 100 * (count(up == 0) BY (job, namespace, service) / count(up) BY (job,
            namespace, service)) > 10
          for: 10m 5
          labels:
            severity: warning 6
        - alert: ApproachingEnforcedSamplesLimit 7
          annotations:
            message: '{{ $labels.container }} container of the {{ $labels.pod }} pod in the {{ $labels.namespace }} namespace consumes {{ $value | humanizePercentage }} of the samples limit budget.' 8
          expr: scrape_samples_scraped/50000 > 0.8 9
          for: 10m 10
          labels:
            severity: warning 11
    1
    アラートルールの名前を定義します。
    2
    アラートルールをデプロイするユーザー定義のプロジェクトを指定します。
    3
    TargetDown アラートは、 for の期間にターゲットを収集できないか、または利用できない場合に実行されます。
    4
    TargetDown アラートが実行される場合に出力されるメッセージ。
    5
    アラートが実行される前に、TargetDown アラートの条件がこの期間中 true である必要があります。
    6
    TargetDown アラートの重大度を定義します。
    7
    ApproachingEnforcedSamplesLimit アラートは、指定された for の期間に定義された収集サンプルのしきい値に達するか、またはこの値を上回る場合に実行されます。
    8
    ApproachingEnforcedSamplesLimit アラートの実行時に出力されるメッセージ。
    9
    ApproachingEnforcedSamplesLimit アラートのしきい値。この例では、ターゲット収集ごとのサンプル数が実行されたサンプル制限 50000 の 80% を超えるとアラートが実行されます。アラートが実行される前に、for の期間も経過している必要があります。式 scrape_samples_scraped/<number> > <threshold><number>user-workload-monitoring-config ConfigMap オブジェクトで定義される enforcedSampleLimit 値に一致する必要があります。
    10
    アラートが実行される前に、ApproachingEnforcedSamplesLimit アラートの条件がこの期間中 true である必要があります。
    11
    ApproachingEnforcedSamplesLimit アラートの重大度を定義します。
  2. 設定をユーザー定義プロジェクトに適用します。

    $ oc apply -f monitoring-stack-alerts.yaml