Sunday, February 5, 2023
GCP GKE Juara GCP Monitoring Prometheus

Reduce Costs for the Managed Service for Prometheus

costs

“Reduce Costs for the Managed Service for Prometheus”

Pengantar

Layanan Terkelola Google Cloud untuk Prometheus mengenakan biaya untuk jumlah sampel yang diserap ke dalam Cloud Monitoring dan untuk permintaan baca ke API Monitoring. Jumlah sampel yang diserap adalah penyumbang utama biaya Anda.

Praktikum

Task 1. Deploy GKE 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

Task 2. Deploy managed collection

Configure a PodMonitoring resource

apiVersion: monitoring.googleapis.com/v1alpha1
kind: PodMonitoring
metadata:
  name: prom-example
spec:
  selector:
    matchLabels:
      app: prom-example
  endpoints:
  - port: metrics
    interval: 30s
kubectl -n gmp-test apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/prometheus-engine/v0.2.3/examples/pod-monitoring.yaml

Deploy the example application

kubectl -n gmp-test apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/prometheus-engine/v0.2.3/examples/example-app.yaml

Task 3. Cloud Console for Monitoring

  • In the Google Cloud Console, go to Monitoring.
  • In the Monitoring navigation pane, click Metrics Explorer.
  • Buka MQL tab
  • run query berikut
fetch prometheus_target::prometheus.googleapis.com/up/gauge
  • buka Configuration
  • In the Resource & Metric field, type “up/” to filter the list, then select Prometheus Target > Up > prometheus/up/gauge.
  • klik apply

Task 4. Populates a graph

Go to Monitoring > Managed Prometheus > PromQL Query and run a query to see metrics: “go_memstats_heap_alloc_bytes” is a decent one that populates a graph nicely.

Task 5. Filter exported metrics

  • edit operator config
kubectl -n gmp-public edit operatorconfig config
collection:
  filter:
    matchOneOf:
    - '{job="prom-example"}'
    - '{__name__=~"job:.+"}'
  • save file
  • buat config baru
vi op-config.yaml
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: monitoring.googleapis.com/v1alpha1
collection:
  filter:
    matchOneOf:
    - '{job="prom-example"}'
    - '{__name__=~"job:.+"}'
kind: OperatorConfig
metadata:
  annotations:
    components.gke.io/layer: addon
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"monitoring.googleapis.com/v1alpha1","kind":"OperatorConfig","metadata":{"annotations":{"components.gke.io/layer":"addon"},"labels":{"addonmanager.kubernetes.io/mode":"Reconcile"},"name":"config","namespace":"gmp-public"}}
  creationTimestamp: "2022-03-14T22:34:23Z"
  generation: 1
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
  name: config
  namespace: gmp-public
  resourceVersion: "2882"
  uid: 4ad23359-efeb-42bb-b689-045bd704f295
export PROJECT=$(gcloud config get-value project)
gsutil mb -p $PROJECT gs://$PROJECT
gsutil cp op-config.yaml gs://$PROJECT
gsutil -m acl set -R -a public-read gs://$PROJECT

Task 6. Run the query

Baca Juga :  Building a VPN Between Google Cloud and AWS with Terraform

Go back to the PromQL Query editor in the UI and run the “up” query. Notice that no other metrics except for prom-example show up in the results. This will be the case with other metrics as well.

Task 7. Monitor the app

  • naikan interval
kubectl -n gmp-test edit podmonitoring/prom-example
  • ganti ke 60s from 30s
  • buat yaml
vi prom-example-config.yaml
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: monitoring.googleapis.com/v1alpha1
kind: PodMonitoring
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"monitoring.googleapis.com/v1alpha1","kind":"PodMonitoring","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"prom-example"},"name":"prom-example","namespace":"gmp-test"},"spec":{"endpoints":[{"interval":"30s","port":"metrics"}],"selector":{"matchLabels":{"app":"prom-example"}}}}
  creationTimestamp: "2022-03-14T22:33:55Z"
  generation: 1
  labels:
    app.kubernetes.io/name: prom-example
  name: prom-example
  namespace: gmp-test
  resourceVersion: "2648"
  uid: c10a8507-429e-4f69-8993-0c562f9c730f
spec:
  endpoints:
  - interval: 60s
    port: metrics
  selector:
    matchLabels:
      app: prom-example
status:
  conditions:
  - lastTransitionTime: "2022-03-14T22:33:55Z"
    lastUpdateTime: "2022-03-14T22:33:55Z"
    status: "True"
    type: ConfigurationCreateSuccess
  observedGeneration: 1
export PROJECT=$(gcloud config get-value project)
gsutil cp prom-example-config.yaml gs://$PROJECT
gsutil -m acl set -R -a public-read gs://$PROJECT

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Reduce Costs for the Managed Service for Prometheus. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

(Visited 10 times, 1 visits today)

Similar Posts