Site icon Learning & Doing

Collect Metrics from Exporters using the Managed Service for Prometheus

managed

“Collect Metrics from Exporters using the Managed Service for Prometheus”

Daftar Isi

Pengantar

Di lab ini, Anda akan menjelajahi penggunaan Layanan Terkelola untuk Prometheus guna mengumpulkan metrik dari sumber infrastruktur lain melalui eksportir.

Praktikum

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

Set up a namespace

kubectl create ns gmp-test

Deploy the example application

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

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

Download the prometheus binary

git clone https://github.com/GoogleCloudPlatform/prometheus && cd prometheus

git checkout v2.28.1-gmp.4

wget https://storage.googleapis.com/kochasoft/gsp1026/prometheus

chmod a+x prometheus

Run the prometheus binary

export PROJECT_ID=$(gcloud config get-value project)
export ZONE=us-central1-f
./prometheus \
  --config.file=documentation/examples/prometheus.yml --export.label.project-id=$PROJECT_ID --export.label.location=$ZONE 

Download and run the node exporter

wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz

tar xvfz node_exporter-1.3.1.linux-amd64.tar.gz

cd node_exporter-1.3.1.linux-amd64

 ./node_exporter

Create a config.yaml file

vi config.yaml
global:
  scrape_interval: 15s
scrape_configs:
  - job_name: node
    static_configs:
      - targets: ['localhost:9100']
export PROJECT=$(gcloud config get-value project)
gsutil mb -p $PROJECT gs://$PROJECT
gsutil cp config.yaml gs://$PROJECT
gsutil -m acl set -R -a public-read gs://$PROJECT
./prometheus --config.file=config.yaml --export.label.project-id=$PROJECT --export.label.location=$ZONE

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Collect Metrics from Exporters using the Managed Service for Prometheus. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

Exit mobile version