All posts
OperationsJun 25, 20243 min read

Apinizer × Prometheus and Grafana: a complete integration guide

Wire Apinizer Gateway and Cache metrics into Prometheus, build Grafana dashboards, and set up alerts — full visibility for your API platform.

AT

Apinizer Team

Operations

A practical guide to integrating Apinizer's metric collection with Prometheus and Grafana for comprehensive monitoring of your API gateway and cache.

Overview of Apinizer's metric system

Apinizer's metric system is built on Micrometer. The platform collects metrics through two main components:

  1. Apinizer Gateway — collects metrics related to API traffic, external connections, JVM health, and system resources.
  2. Apinizer Cache — monitors cache operations, API requests, JVM performance, and system health.

These metrics provide comprehensive visibility into the performance and health of your API management infrastructure, enabling proactive identification of bottlenecks, troubleshooting, and capacity planning.

Metrics collected

Apinizer Gateway metrics

API traffic metrics — track requests passing through the gateway:

  • Total API traffic requests
  • Successful, failed, and blocked API requests
  • Request processing times (pipeline, routing, total)
  • Request and response sizes
  • Cache hit statistics

Each metric is available in two forms: aggregate metrics and tagged metrics with detailed dimensions (e.g. API ID, requests per API name).

External connection metrics — track connections to external services: total external requests, external error count, external response times.

JVM metrics — memory usage (heap, non-heap), garbage collection statistics, thread counts and states.

System metrics — CPU usage, processor count, system load average, file descriptor counts.

Apinizer Cache metrics

Cache operation metrics: cache get / put counts, size and entry counts, operation latencies, memory usage.

API metrics: API request counts, response times, error counts.

JVM and system metrics: similar to the Gateway, the Cache component tracks JVM performance and system resource usage.

Setting up the Prometheus integration

1. Enabling metrics on Apinizer components

For Apinizer Gateway: in the Apinizer UI, go to Gateway Environments and enable the "Prometheus Metric Server" option. This enables metric publishing on port 9091.

For Apinizer Cache: edit the Cache deployment and add the METRICS_ENABLED=TRUE environment variable.

Via Apinizer UI: Gateway Environments → Deployments & Services → Cache → Edit deployment.

Via kubectl:

kubectl edit deploy -n <namespace> cache
# Add the following environment variable
- name: METRICS_ENABLED
  value: "true"

2. Configuring Prometheus to scrape metrics

Constant scraping. Create a service targeting Apinizer components on port 9091, then configure Prometheus to scrape from those services.

Dynamic scraping with Kubernetes service discovery. Add annotations prometheus.io/port: "9091" and prometheus.io/scrape: "true" to the deployment; configure Prometheus to use Kubernetes service discovery.

Analyzing Apinizer metrics with PromQL

Gateway API traffic analysis. Example queries: total API requests in the last hour, requests per API, success rate (%), average response time per API (ms).

Cache performance analysis. Cache get operations, hit rate (%), current cache entries.

JVM analysis. Memory usage (%), garbage collection time.

Creating Grafana dashboards

After configuring Prometheus as a data source in Grafana:

API traffic dashboard. Request volume by type, most-used APIs, processing time distribution, request / response size panels.

Cache performance dashboard. Cache operations (get / put), hit rate, memory usage.

System health dashboard. JVM memory usage, CPU usage, active threads.

Example PromQL expressions:

sum(rate(apinizer_api_traffic_total_count_total[5m]))
topk(5, sum by (api_name) (increase(apinizer_api_traffic_total_count_tagged_total[5m])))

Best practices

  1. Metric retention. Configure appropriate retention in Prometheus (e.g. --storage.tsdb.retention.time=7d). Consider remote storage for longer retention.
  2. Alert configuration. Set up alerts in Prometheus AlertManager or Grafana for critical metrics (high API error rate, high memory, slow response times).
  3. Dashboard organization. Separate dashboards for Gateway and Cache, group related metrics, use variables for filtering by namespace, pod, or API.
  4. Label usage. Filter by API using api_name, analyze by namespace or pod, compare across environments.

Conclusion

Integrating Apinizer with Prometheus and Grafana provides powerful monitoring for your API management infrastructure. This integration leverages the strengths of each component:

  • Apinizer's comprehensive metric collection
  • Prometheus's efficient time-series database and powerful query language
  • Grafana's flexible and rich visualizations

By configuring metric collection correctly, building informative dashboards, and applying alerts, you can ensure optimal performance, quickly detect issues, and make data-driven decisions for your API ecosystem.

  • #api-gateway
  • #monitoring
  • #prometheus
  • #grafana
  • #metrics

See it on your cluster

Walk through the platform with us.

A 30-minute tour of Manager, Worker, AI Gateway, and APIops on a Kubernetes of your choice.