Site icon Learning & Doing

Using Prometheus for Monitoring on Google Cloud: Qwik Start

Prometheus

“Using Prometheus for Monitoring on Google Cloud: Qwik Start”

Daftar Isi

Pengantar

Layanan Terkelola untuk Prometheus adalah layanan penyimpanan dan kueri terkelola sepenuhnya dari Google Cloud untuk metrik Prometheus. Layanan ini dibangun di atas Monarch, penyimpanan data yang dapat diskalakan secara global yang sama dengan Cloud Monitoring.

Garpu tipis Prometheus menggantikan penyebaran Prometheus yang ada dan mengirimkan data ke layanan terkelola tanpa campur tangan pengguna. Data ini kemudian dapat dikueri dengan menggunakan PromQL melalui Prometheus Query API yang didukung oleh layanan terkelola dan dengan menggunakan mekanisme kueri Cloud Monitoring yang ada.

Praktikum

Setup a Google Kubernetes Engine cluster

gcloud beta container clusters create gmp-cluster --num-nodes=1 --zone us-central1-f --enable-managed-prometheus
gcloud container clusters get-credentials gmp-cluster --zone us-central1-f
kubectl create ns gmp-test

Deploy the application

kubectl -n gmp-test apply -f https://raw.githubusercontent.com/kyleabenson/flask_telemetry/master/gmp_prom_setup/flask_deployment.yaml
kubectl -n gmp-test apply -f https://raw.githubusercontent.com/kyleabenson/flask_telemetry/master/gmp_prom_setup/flask_service.yaml
url=$(kubectl get services -n gmp-test -o jsonpath='{.items[*].status.loadBalancer.ingress[0].ip}')
curl $url/metrics
kubectl -n gmp-test apply -f https://raw.githubusercontent.com/kyleabenson/flask_telemetry/master/gmp_prom_setup/prom_deploy.yaml
timeout 120 bash -c -- 'while true; do curl $(kubectl get services -n gmp-test -o jsonpath='{.items[*].status.loadBalancer.ingress[0].ip}'); sleep $((RANDOM % 4)) ; done'

Observing the app via metrics

gcloud monitoring dashboards create --config='''
{
  "category": "CUSTOM",
  "displayName": "Prometheus Dashboard Example",
  "mosaicLayout": {
    "columns": 12,
    "tiles": [
      {
        "height": 4,
        "widget": {
          "title": "prometheus/flask_http_request_total/counter [MEAN]",
          "xyChart": {
            "chartOptions": {
              "mode": "COLOR"
            },
            "dataSets": [
              {
                "minAlignmentPeriod": "60s",
                "plotType": "LINE",
                "targetAxis": "Y1",
                "timeSeriesQuery": {
                  "apiSource": "DEFAULT_CLOUD",
                  "timeSeriesFilter": {
                    "aggregation": {
                      "alignmentPeriod": "60s",
                      "crossSeriesReducer": "REDUCE_NONE",
                      "perSeriesAligner": "ALIGN_RATE"
                    },
                    "filter": "metric.type=\"prometheus.googleapis.com/flask_http_request_total/counter\" resource.type=\"prometheus_target\"",
                    "secondaryAggregation": {
                      "alignmentPeriod": "60s",
                      "crossSeriesReducer": "REDUCE_MEAN",
                      "groupByFields": [
                        "metric.label.\"status\""
                      ],
                      "perSeriesAligner": "ALIGN_MEAN"
                    }
                  }
                }
              }
            ],
            "thresholds": [],
            "timeshiftDuration": "0s",
            "yAxis": {
              "label": "y1Axis",
              "scale": "LINEAR"
            }
          }
        },
        "width": 6,
        "xPos": 0,
        "yPos": 0
      }
    ]
  }
}
'''

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Using Prometheus for Monitoring on Google Cloud: Qwik Start. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

Exit mobile version