Site icon Learning & Doing

Creating and Alerting on Logs-based Metrics

alerting

“Creating and Alerting on Logs-based Metrics”

Pengantar

Metrik berbasis log adalah metrik Cloud Monitoring yang didasarkan pada konten entri log. Metrik ini dapat membantu Anda mengidentifikasi tren, mengekstrak nilai numerik dari log, dan menyiapkan peringatan saat entri log tertentu terjadi dengan membuat metrik untuk peristiwa tersebut. Anda dapat menggunakan metrik berbasis log yang ditentukan oleh sistem dan pengguna di Cloud Monitoring untuk membuat diagram dan memberi tahu kebijakan.google

Praktikum

Task 1. Log-based alert

resource.type="gce_instance" protoPayload.methodName="v1.compute.instances.stop"
Alert name: stopped vm
Choose logs to include in the alert: will auto-fill with the query you entered
Set notification frequency and autoclose duration: Time between notifications is 5 min and Incident autoclose duration is 1 hr. Click Next.


    Click on the dropdown arrow next to Notification Channels, then click on Manage Notification Channels.

    A Notification channels page will open in the new tab.

    Scroll down the page and click on ADD NEW for Email.

    Enter your personal email in the Email Address field and a Display name.

    Click Save.

    When done, return to the Logs Explorer tab you were in previously.

    Refresh the Notification Channels, then select the channel you just created. Click OK.

Task 2. Log-based metric

gcloud container clusters list

gcloud container clusters get-credentials gmp-cluster

kubectl create ns gmp-test

kubectl -n gmp-test apply -f https://storage.googleapis.com/spls/gsp091/gmp_flask_deployment.yaml

kubectl -n gmp-test apply -f https://storage.googleapis.com/spls/gsp091/gmp_flask_service.yaml

kubectl get services -n gmp-test
curl $(kubectl get services -n gmp-test -o jsonpath='{.items[*].status.loadBalancer.ingress[0].ip}')/metrics

Task 3. Create a log-based metric

    Metric type: leave the default setting, Counter

    Log metric name: hello-app-error

    Filter selection: update the following into the field:
severity=ERROR
resource.labels.container_name="hello-app"
textPayload: "ERROR: 404 Error page not found"

Task 4. Create a metrics-based alert



    Update the Rolling window to 2 min.

    Accept the other default settings

    Click Next.

Task 5. Generate some errors

timeout 120 bash -c -- 'while true; do curl $(kubectl get services -n gmp-test -o jsonpath='{.items[*].status.loadBalancer.ingress[0].ip}')/error; sleep $((RANDOM % 4)) ; done'

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Creating and Alerting on Logs-based Metrics. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

Exit mobile version