Halaman ini menguraikan proses untuk mengambil metrik dari workload di lingkungan Google Distributed Cloud (GDC) dengan air gap untuk memfasilitasi pemantauan dan kemampuan observasi data.
Anda dapat mengumpulkan dan mengoleksi metrik yang dihasilkan komponen Anda dari waktu ke waktu. Platform pemantauan menawarkan API kustom untuk mengambil metrik dari workload yang berjalan dalam namespace project Distributed Cloud Anda. Untuk mengambil metrik,
deploy resource kustom MonitoringTarget ke namespace project Anda di
server Management API. Setelah deployment resource ini, platform pemantauan
akan memulai pengumpulan data.
Resource kustom MonitoringTarget mengarahkan pipeline pemantauan untuk mengumpulkan pod yang ditentukan dalam project Anda. Pod ini harus mengekspos endpoint HTTP yang mengirimkan metrik dalam format eksposisi Prometheus, seperti OpenMetrics.
Metrik yang di-scrape kemudian ditampilkan di instance Grafana project Anda,
yang memberikan insight tentang status operasional aplikasi Anda.
Untuk mengonfigurasi resource kustom MonitoringTarget, Anda harus menentukan pod dalam namespace project untuk pengumpulan metrik. Anda dapat menyesuaikan berbagai
setelan, termasuk frekuensi scraping, endpoint metrik pod, label,
dan anotasi.
Sebelum memulai
Untuk mengelola resource kustom MonitoringRule, minta izin yang diperlukan dari administrator Anda.
Peran IAM yang diperlukan
Hubungi Admin Project IAM Anda untuk meminta peran berikut:
- MonitoringRule Creator (
monitoringrule-creator): membuat resource kustomMonitoringRuledi namespace project. - MonitoringRule Editor (
monitoringrule-editor): mengedit atau mengubah resource kustomMonitoringRuledi namespace project. - MonitoringRule Viewer (
monitoringrule-viewer): melihat resource kustomMonitoringRuledi namespace project.
Mengonfigurasi resource kustom MonitoringTarget
Resource kustom MonitoringTarget memberi tahu platform pemantauan tempat untuk mengumpulkan metrik. Anda dapat menentukan pod yang metriknya Anda kumpulkan, endpoint metrik pod tersebut, frekuensi scraping, dan setelan tambahan lainnya.
Resource ini menentukan konfigurasi berikut:
- Target: Pod dan endpoint-nya dalam project Anda yang mengekspos metrik.
- Scrape interval: Seberapa sering Anda ingin mengambil metrik dari endpoint yang dipilih.
- Penyesuaian label: Aturan opsional dengan modifikasi label apa pun untuk metrik.
Pilih salah satu metode berikut untuk menentukan endpoint metrik di resource kustom MonitoringTarget:
- Endpoint statis: Anda secara eksplisit mendeklarasikan endpoint (port, jalur, skema) dalam konfigurasi
MonitoringTarget. Anotasi: Informasi endpoint metrik pod diambil dari anotasi dalam file
Deploymentcontainer. Metode ini menawarkan fleksibilitas lebih besar jika setiap pod memiliki endpoint yang berbeda.
Endpoint statis
Ikuti langkah-langkah berikut untuk mengekspos metrik dari pod yang Anda pilih di endpoint yang ditentukan secara statis:
Tentukan project Distributed Cloud yang ingin Anda kumpulkan metriknya untuk pemantauan.
Dalam spesifikasi pod, deklarasikan port yang menyajikan metrik di kolom
containerPort. Contoh berikut menunjukkan cara mendeklarasikan port2112dalam spesifikasi pod:# ... spec: template: spec: containers: - name: your-container-name ports: - containerPort: 2112 # ...Dalam konfigurasi
MonitoringTarget, tentukan detail endpoint (port, jalur, skema) di bagianpodMetricsEndpointsagar sesuai dengan port yang Anda ekspos dalam spesifikasi pod.File YAML berikut menunjukkan contoh konfigurasi
MonitoringTargettempat setiap pod yang dipilih harus mengekspos metrik di endpoint yang sama,http://your-container-name:2112/metrics:apiVersion: monitoring.gdc.goog/v1 kind: MonitoringTarget metadata: # Choose the same namespace as the workload pods. namespace: your-project-namespace name: your-container-name spec: selector: # Choose pod labels to consider for this job. # Optional: Map of key-value pairs. # Default: No filtering by label. # To consider every pod in the project namespace, remove selector fields. matchLabels: app: your-app-label podMetricsEndpoints: port: value: 2112 path: # Choose any value for your endpoint. # The /metrics value is an example. value: /metrics scheme: value: httpTerapkan konfigurasi
MonitoringTargetke server Management API dalam namespace yang sama dengan pod target Anda:kubectl --kubeconfig KUBECONFIG_PATH apply -f MONITORING_TARGET_NAME.yamlGanti kode berikut:
KUBECONFIG_PATH: jalur ke file kubeconfig untuk server Management API.MONITORING_TARGET_NAME: nama file definisiMonitoringTarget.
Platform pemantauan mulai mengumpulkan metrik.
Anotasi
Ikuti langkah-langkah berikut untuk mengekspos metrik menggunakan anotasi jika setiap pod memiliki endpoint yang berbeda:
Tentukan project Distributed Cloud yang ingin Anda kumpulkan metriknya untuk pemantauan.
Tambahkan anotasi berikut ke bagian
annotationspada fileDeploymentcontainer Anda:prometheus.io/pathprometheus.io/portprometheus.io/scheme
Contoh berikut menunjukkan anotasi untuk metrik di port
2112:apiVersion: apps/v1 kind: Deployment metadata: name: your-container-name namespace: your-project-namespace labels: app: your-app-label annotations: # These annotations are not required. They demonstrate selecting # pod metric endpoints through annotations. prometheus.io/path: /metrics prometheus.io/port: \"2112\" prometheus.io/scheme: httpDalam konfigurasi
MonitoringTarget, tentukan anotasi yang Anda tambahkan ke fileDeploymentcontainer di bagianpodMetricsEndpoints. Spesifikasi ini memberi tahu resource kustom untuk mengumpulkan informasi endpoint metrik dari anotasi pada pod yang dipilih.File YAML berikut menunjukkan contoh konfigurasi
MonitoringTargetmenggunakan anotasi:apiVersion: monitoring.gdc.goog/v1 kind: MonitoringTarget metadata: metadata: # Choose the same namespace as the workload pods. namespace: your-project-namespace name: your-container-name spec: selector: matchLabels: app: your-app-label podMetricsEndpoints: port: annotation: prometheus.io/port path: annotation: prometheus.io/path scheme: annotation: prometheus.io/schemeTerapkan konfigurasi
MonitoringTargetke server Management API dalam namespace yang sama dengan pod target Anda:kubectl --kubeconfig KUBECONFIG_PATH apply -f MONITORING_TARGET_NAME.yamlGanti kode berikut:
KUBECONFIG_PATH: jalur ke file kubeconfig untuk server Management API.MONITORING_TARGET_NAME: nama file definisiMonitoringTarget.
Platform pemantauan mulai mengumpulkan metrik.
Lihat spesifikasi MonitoringTarget lengkap
dan dokumentasi referensi API
untuk kolom dan opsi tambahan.
Lengkapi spesifikasi MonitoringTarget
File YAML berikut menunjukkan contoh spesifikasi lengkap resource kustom MonitoringTarget. Untuk mengetahui informasi selengkapnya dan deskripsi lengkap kolom, lihat dokumentasi referensi API.
apiVersion: monitoring.gdc.goog/v1
kind: MonitoringTarget
metadata:
# Choose the same namespace as the workload pods.
namespace: PROJECT_NAMESPACE
name: MONITORING_TARGET_NAME
spec:
# Choose matching pattern that identifies pods for this job.
# Optional
# Relationship between different selectors: AND
selector:
# Choose clusters to consider for this job.
# Optional: List
# Default: All clusters applicable to this project.
# Relationship between different list elements: OR
matchClusters:
- string
# Choose pod labels to consider for this job.
# Optional: Map of key-value pairs.
# Default: No filtering by label.
# Relationship between different pairs: AND
matchLabels:
key1: value1
# Choose annotations to consider for this job.
# Optional: Map of key-value pairs
# Default: No filtering by annotation
# Relationship between different pairs: AND
matchAnnotations:
key1: value1
# Configure the endpoint exposed for this job.
podMetricsEndpoints:
# Choose a port either through static value or annotation.
# Optional
# Annotation takes priority.
# Default: static port 80
port:
value: integer
annotation: string
# Choose a path either through static value or annotation.
# Optional
# Annotation takes priority
# Default: static path /metrics
path:
value: string
annotation: string
# Choose a scheme either through a static value (http or https) or annotation.
# Optional
# Annotation takes priority
# Default: static scheme http
scheme:
value: string
annotation: string
# Choose the frequency to scrape the metrics endpoint defined in podMetricsEndpoints
# Optional
# Default: 60s
scrapeInterval: string
# Dynamically rewrite the label set of a target before it gets scraped.
# https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
# Optional
# Default: No filtering by label
metricsRelabelings:
- sourceLabels:
- string
separator: string
regex: string
action: string
targetLabel: string
replacement: string
Ganti kode berikut:
PROJECT_NAMESPACE: namespace project Anda.MONITORING_TARGET_NAME: nama file definisiMonitoringTarget.