Prometheus Setup and Scraping Configuration for Apinizer Cache
Prometheus Setup and Scraping Configuration
Prometheus is a monitoring system that pulls metrics from specific targets and stores them as time series data. Scraping is the process by which Prometheus periodically collects metrics from target services. Apinizer Cache metrics are provided on port 9091, and Prometheus can pull these metrics using two different methods:Constant Scraping
In the static scraping method, services to be monitored are defined under
static_configs with predetermined static 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 manually defined.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 when services change. This method provides great advantages in microservice architectures and constantly changing infrastructures.Static (Constant) Scraping Configuration
For Apinizer Cache to publish metrics on port 9091, the
METRICS_ENABLED=TRUE parameter must be defined as an environment variable for the relevant container.Dynamic Scraping Configuration
The dynamic scraping method enables Prometheus to automatically discover pods within Kubernetes. With 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
Prometheus Scraping Configuration
To discover annotations on pods, dynamic scraping must be enabled in Prometheus’s ConfigMap configuration using kubernetes_sd_configs. The following ConfigMap example 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.Prometheus Installation
Persistent Storage ConfigurationSince Prometheus metrics will be stored on a node in the Kubernetes cluster, PersistentVolume (PV) and PersistentVolumeClaim (PVC) definitions must be made. This configuration ensures that Prometheus preserves its data in shutdown or restart situations.
Prometheus must have the necessary permissions to discover pods and collect their metrics. For this, the following ServiceAccount, ClusterRole, and ClusterRoleBinding definitions must be made.
When Prometheus is deployed on Kubernetes, it creates a Kubernetes service named
prometheus-service of type NodePort. This service is necessary for accessing Prometheus from outside Kubernetes. However, you can adapt this to use Ingress or whatever connection method your organization uses instead of this service.
