Halaman ini menguraikan proses scraping metrik dari workload di lingkungan air-gapped Google Distributed Cloud (GDC) untuk memfasilitasi pemantauan dan kemampuan observasi data.
Anda dapat melakukan scraping dan mengumpulkan metrik yang dihasilkan komponen Anda dari waktu ke waktu. Platform pemantauan menawarkan API kustom untuk melakukan scraping metrik dari workload yang berjalan dalam namespace project Distributed Cloud Anda. Untuk melakukan scraping metrik, Anda men-deploy resource kustom MonitoringTarget ke namespace project di server Management API. Setelah men-deploy resource ini, platform pemantauan akan memulai pengumpulan data.
Resource kustom MonitoringTarget mengarahkan pipeline pemantauan untuk melakukan scraping pod yang ditentukan dalam project Anda. Pod ini harus mengekspos endpoint HTTP yang menampilkan metrik dalam format eksposisi Prometheus, seperti OpenMetrics.
Metrik yang di-scrape kemudian ditampilkan dalam instance Grafana project Anda, sehingga 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 IAM Project 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 akan dikumpulkan, endpoint metrik pod tersebut, frekuensi scraping, dan setelan tambahan apa pun.
Resource ini menentukan konfigurasi berikut:
- Target: Pod dan endpointnya 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 untuk metrik.
Pilih salah satu metode berikut untuk menentukan endpoint metrik di resource kustom MonitoringTarget:
- Static endpoints: Anda secara eksplisit mendeklarasikan endpoint (port,
jalur, skema) dalam konfigurasi
MonitoringTarget. Anotasi: Informasi endpoint metrik pod diambil dari anotasi dalam file
Deploymentpenampung. Metode ini menawarkan lebih banyak fleksibilitas jika setiap pod memiliki endpoint yang berbeda.
Endpoint statis
Ikuti langkah-langkah berikut untuk mengekspos metrik dari pod yang dipilih di endpoint yang ditentukan secara statis:
Tentukan project Distributed Cloud yang metriknya ingin Anda kumpulkan untuk pemantauan.
Dalam spesifikasi pod, deklarasikan port yang menampilkan 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
MonitoringTargetyang mengharuskan setiap pod yang dipilih untuk 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 metriknya ingin Anda kumpulkan untuk pemantauan.
Tambahkan anotasi berikut ke bagian
annotationsfileDeploymentpenampung 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 fileDeploymentpenampung 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 MonitoringTargetlengkap
dan dokumentasi referensi API
untuk mengetahui kolom dan opsi tambahan.
Spesifikasi MonitoringTarget lengkap
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.