とんちゃんといっしょ

Cloudに関する技術とか日常とかについて書いたり書かなかったり

プログラムからstackdriver monitoring dashbordを作ってみて諦めたはなし

Spinnakerのspinnaker-monitoringでStackdriverが使えるって書いてあったので試したところ、 どうもうまく動かせない。

github.com

データをStackdriverに送れているようなのだが、メトリクスが多すぎるせいでHTTP status code 429 (APIリクエスト多過ぎ)をもらう。 Filterを書いてみてもうまく動いてる気がしない・・・

また、spinnaker-monitoringからDashboardを作ろうでみようとしてもコードが古くてうまく動かないようなので、 自分でStackdriver Dashboardを作るプログラムを書いてみた。

sample.py

import json

from google.cloud.monitoring_dashboard import v1

client = v1.DashboardsServiceClient()

parent = 'projects/yoru-project-id'

with open('./dashboards/clouddriver-metrics-dashboard.json') as f:
    dashboard = json.load(f)
    response = client.create_dashboard(parent, dashboard)

    print(response)

requirements.txt

cachetools==4.1.1
certifi==2020.6.20
chardet==3.0.4
google-api-core==1.21.0
google-auth==1.18.0
google-cloud-monitoring-dashboards==1.0.0
googleapis-common-protos==1.52.0
grpcio==1.30.0
idna==2.10
protobuf==3.12.2
pyasn1==0.4.8
pyasn1-modules==0.2.8
pytz==2020.1
requests==2.24.0
rsa==4.6
six==1.15.0
urllib3==1.25.9

./dashboards/clouddriver-metrics-dashboard.json

{
  "display_name": "Clouddriver Microservice",
  "row_layout": {
    "rows": [
      {
        "widgets": [
          {
            "title": "Clouddriver Invocations (success)",
            "xy_chart": {
              "data_sets": [
                {
                  "time_series_query": {
                    "time_series_filter": {
                      "filter": "metric.type=\"custom.googleapis.com/spinnaker/clouddriver/controller.invocations__count\" metric.label.status=\"2xx\"",
                      "aggregation": {
                        "per_series_aligner": "ALIGN_DELTA"
                      }
                    }
                  }
                }
              ]
            }
          },
          {
            "title": "Clouddriver Invocations (failure)",
            "xy_chart": {
              "data_sets": [
                {
                  "time_series_query": {
                    "time_series_filter": {
                      "filter": "metric.type=\"custom.googleapis.com/spinnaker/clouddriver/controller.invocations__count\" metric.label.status!=\"2xx\"",
                      "aggregation": {
                        "per_series_aligner": "ALIGN_DELTA"
                      }
                    }
                  }
                }
              ]
            }
          }
        ]
      },
      {
        "widgets": [
          {
            "title": "JVM Memory (clouddriver)",
            "xy_chart": {
              "data_sets": [
                {
                  "time_series_query": {
                    "time_series_filter": {
                      "filter": "metric.type=\"custom.googleapis.com/spinnaker/clouddriver/jvm.memory.used__value\" metric.label.area=\"heap\"",
                      "aggregation": {
                        "per_series_aligner": "ALIGN_MEAN"
                      }
                    }
                  }
                }
              ]
            }
          }
        ]
      }
    ]
  }
}

spinnaker-monitoringに置いてある既存のJSONではうまく表示されなかったので色々書き直したりしていたが埒が明かない。

Spinnaker のSlackで聞いてみたところ、Stackdriverを使ってる人がぜんぜんいなさそうな雰囲気で、 Armoryが作っているobservabilityのPluginをおすすめされたので、こっちを試してみようと思う。

github.com