- Constant Scraping (Fixed Scraping): In the fixed scraping method, services to be monitored are defined under static_configs with predetermined fixed IP addresses or DNS names. Prometheus queries these services at regular intervals. This method is useful when service addresses do not change or can be defined manually.
- Dynamic Scraping (Dynamic Scraping): In the dynamic scraping method, Prometheus automatically discovers services through a service discovery mechanism such as Kubernetes. Thanks to kubernetes_sd_config or similar configurations, there is no need to update Prometheus configuration as services change. This method provides great advantages in microservice architectures and constantly changing infrastructures.
Fixed (Constant) Scraping Configuration
For Apinizer Cache to publish metrics via port 9091, theMETRICS_ENABLED=TRUE parameter must be defined as an environment variable to the relevant container.
apinizer-prometheus-svc.yaml
Dynamic (Dynamic) Scraping Configuration
The dynamic scraping method enables Prometheus to automatically discover pods within Kubernetes. Thanks to this method, there is no need to make manual scraping configuration for each new pod. Prometheus automatically pulls metrics using specific annotations added to pods.For Cache metrics to be collected by Prometheus, the
METRICS_ENABLED=TRUE variable must be added by selecting Cache edit deployment option in the Deployments & Services section on the Gateway Environments page.If Kubernetes Management is Not Done with Apinizer
To enable Prometheus to collect metrics from Cache pods, relevant annotations must be added to the spec.template.metadata.annotations section of the relevant Deployment manifest. In addition, for Apinizer Cache to publish metrics via port 9091, theMETRICS_ENABLED=TRUE parameter must be defined as an environment variable to the relevant container. This way, the metrics service will be exported via port 9091 and Prometheus will automatically discover and scrape metrics from the Apinizer Cache pod running on port 9091.
Prometheus Scraping Configuration
Dynamic scraping must be enabled using kubernetes_sd_configs in Prometheus’s ConfigMap configuration to discover annotations in pods.The ConfigMap example below enables Prometheus to dynamically discover Kubernetes pods. This configuration enables Prometheus to automatically discover Kubernetes pods and collect metrics only from pods with the
prometheus.io/scrape: "true" annotation. Thus, metrics can be collected by Prometheus by applying dynamic scraping to Apinizer Cache without the need for manual target definition.
