Tuesday, November 12, 2024
GCP Juara GCP

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

  • From Cloud Console, in the Search bar, type in “logs explorer”, then click on the Logs Explorer result.
  • Click the Show Query slide bar.
  • Enter the following parameters to create Log Based Alert:
resource.type="gce_instance" protoPayload.methodName="v1.compute.instances.stop"
  • Click Create alert link.
  • Add the following parameters, click Next to move to the next parameter.
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.
  • Who should be notified (optional):


    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.
  • Click Save.
  • Go to the 2nd Cloud Console tab, and navigate to Navigation menu > Compute Engine > VM instances.
  • Check the box next to instance1, then click Stop at the top of the page, then click Stop again in the pop-up window. The green check mark will turn to a gray circle when the instance has been stopped.
  • In the Search bar, type “monitoring”, then choose the Monitoring option.
  • Click on the Alerting tab. You’ll see that your alert has registered. Under Alert Policies click the View all link and you’ll see the log-based alert you created listed.
Baca Juga :  Cloud Functions Qwik Start - Console

Task 2. Log-based metric

  • At the beginning of the lab you deployed a standard GKE cluster. Run the following command to ensure that the cluster named gmp-cluster has been created:
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
  • Re-run the command until you see the External-IP address populated.
  • Check that the Python Flask app is serving metrics with the following command:
curl $(kubectl get services -n gmp-test -o jsonpath='{.items[*].status.loadBalancer.ingress[0].ip}')/metrics

Task 3. Create a log-based metric

  • Return to Logs Explorer.
  • Click Create metric link.
  • On the Create metric page, input the following:
    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"
  • Click Create metric.

Task 4. Create a metrics-based alert

  • Under Create a metrics-based alert, click Create Alert.
  • Under Select a Metric, the metric parameters will automatically fill in.


    Update the Rolling window to 2 min.

    Accept the other default settings

    Click Next.
  • You will need to set Notifications. Feel free to re-use the channel you created earlier in the lab.
  • Name the alert log based metric alert.
  • Click Create Policy.

Task 5. Generate some errors

  • In Cloud Shell, run the following to 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'
  • Return to the Logs Explorer page, and go to the Severity section on the lower left side. Click on the Error severity. Now you can search for the 404 Error page not found error. View more information by expanding one of the 404 Error messages.
  • Return to the Monitoring page, and click on Alerting. You will see the 2 policies you created.
  • Click on the Alert policies link, and you should see both alerts in the Incidents section. Click on an incident to see details.
Baca Juga :  Belajar Terraform di GCP

Penutup

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

(Visited 83 times, 1 visits today)

Similar Posts