Grafana ダッシュボードの設定

Grafana ダッシュボードを使用して、Anypoint Platform Private Cloud Edition (Anypoint Platform PCE) インストールとその実行中のアプリケーションの健全性を監視します。これらのダッシュボードでは、Anypoint Platform PCE インストールの監視ツールで収集されたデータが視覚的に表現されます。

Grafana アプリケーションは、サービスを外部ネットワークに公開するために ​NodePort​ 種別の Kubernetes サービスを使用します。Grafana にアクセスするには、トラフィックをポート ​32380​ に転送するようにロードバランサーを設定します。

または、​kubectl port-forward​ コマンドを使用してローカルで Grafana にアクセスします。

kubectl -n monitoring port-forward $(kubectl -n monitoring get svc --selector='app.kubernetes.io/name=grafana' -oname | head -n 1) 3000:80

Grafana ダッシュボードへのアクセス

Grafana のログイン情報を取得するには、次のコマンドを実行します。

kubectl -n monitoring get secrets grafana-creds -ojsonpath='{.data.admin-user}' | base64 --decode
kubectl -n monitoring get secrets grafana-creds -ojsonpath='{.data.admin-password}' | base64 --decode

カスタムダッシュボードの作成

Grafana の Web インターフェースを使用して、カスタムダッシュボードを作成できます。ただし、これらのダッシュボードは Grafana ポッドが再起動すると失われます。再起動が行われても保持されるカスタムダッシュボードを作成するには、​grafana_dashboard=1​ という表示ラベルの ConfigMap を作成します。

次の例は、カスタムダッシュボードが含まれる ConfigMap を作成する方法を示しています。

  1. ダッシュボード設定が含まれるファイル (例: example-redis.yaml​) を作成します。

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-custom-dashboard
  namespace: monitoring
  labels:
    grafana_dashboard: "1"
data:
  example-redis.json: |
    {
      "annotations": {
        "list": [
          {
            "builtIn": 1,
            "datasource": "-- Grafana --",
            "enable": true,
            "hide": true,
            "iconColor": "rgba(0, 211, 255, 1)",
            "name": "Annotations & Alerts",
            "type": "dashboard"
          }
        ]
      },
      "timezone": "browser",
      "title": "My Example Redis Dashboard",
      "description": "",
      "editable": true,
      "gnetId": null,
      "graphTooltip": 0,
      "id": 29,
      "iteration": 1645573265624,
      "links": [],
      "panels": [
        {
          "aliasColors": {
            "Max": "#890F02",
            "Used": "#7EB26D",
            "max": "#BF1B00"
          },
          "bars": false,
          "dashes": false,
          "datasource": null,
          "editable": false,
          "error": false,
          "fieldConfig": {
            "defaults": {},
            "overrides": []
          },
          "fill": 1,
          "fillGradient": 0,
          "hiddenSeries": false,
          "id": 7,
          "isNew": true,
          "legend": {
            "avg": false,
            "current": false,
            "hideEmpty": false,
            "hideZero": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "gridPos": {
            "x": 0,
            "y": 0,
            "h": 11,
            "w": 24
          },
          "lines": true,
          "linewidth": 2,
          "links": [],
          "nullPointMode": "null as zero",
          "options": {
            "alertThreshold": true
          },
          "percentage": false,
          "pluginVersion": "7.5.10",
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "exemplar": true,
              "expr": "sum by (pod)(redis_used_memory{pod=~\"$pod\"})",
              "interval": "",
              "legendFormat": "{{pod}}",
              "refId": "B"
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeRegions": [],
          "timeShift": null,
          "title": "Memory Usage",
          "tooltip": {
            "msResolution": false,
            "shared": true,
            "sort": 0,
            "value_type": "cumulative"
          },
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "bytes",
              "label": "",
              "logBase": 1,
              "max": null,
              "min": 0,
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": false
            }
          ],
          "yaxis": {
            "align": false,
            "alignLevel": null
          }
        }
      ],
      "refresh": false,
      "schemaVersion": 27,
      "style": "dark",
      "tags": [],
      "templating": {
        "list": [
          {
            "allValue": null,
            "current": {
              "selected": false,
              "text": "All",
              "value": "$__all"
            },
            "datasource": null,
            "definition": "label_values(redis_maxmemory, pod)",
            "description": null,
            "error": null,
            "hide": 0,
            "includeAll": true,
            "label": "Pod",
            "multi": true,
            "name": "pod",
            "options": [],
            "query": {
              "query": "label_values(redis_maxmemory, pod)",
              "refId": "StandardVariableQuery"
            },
            "refresh": 2,
            "regex": "",
            "skipUrlSync": false,
            "sort": 0,
            "tagValuesQuery": "",
            "tags": [],
            "tagsQuery": "",
            "type": "query",
            "useTags": false
          }
        ]
      },
      "time": {
        "from": "now-6h",
        "to": "now"
      },
      "timepicker": {
        "refresh_intervals": [
          "5s",
          "10s",
          "30s",
          "1m",
          "5m",
          "15m",
          "30m",
          "1h",
          "2h",
          "1d"
        ],
        "time_options": [
          "5m",
          "15m",
          "1h",
          "6h",
          "12h",
          "24h",
          "2d",
          "7d",
          "30d"
        ]
      }
    }
  1. 次のコマンドで ConfigMap を作成します。

kubectl apply -f example-redis.yaml

ダッシュボードを更新するには、ConfigMap を変更します。これにより、ダッシュボードは自動的に更新されます。

カスタムダッシュボードの削除

カスタムダッシュボードに削除するには、対応する ConfigMap を削除します。ConfigMap に関連付けられたダッシュボードが自動的に削除されます。

kubectl -n monitoring delete cm my-custom-dashboard

すべての永続ダッシュボードのリスト

grafana_dashboard=1​ という表示ラベルのすべての ConfigMap のリストを取得するには、次のコマンドを使用します。

kubectl get configmaps --selector='grafana_dashboard=1' -A