+++ title = "Data Plane Metrics to Prometheus" weight = 11 +++ In order to monitor the Kong Data Planes replicas we're going to configure a Service Monitor based on a Kubernetes Service created for the Data Planes. #### Create a Global Prometheus plugin First of all we have to configure the specific Prometheus plugin provided by Kong. After submitting the following declaration, all Ingresses defined will have the plugin enabled and, therefore, include their metrics on the Prometheus endpoint exposed by the Kong Data Plane. Execute the following command ```bash cat <\-\-set env.status_listen=0.0.0.0:8100. You can check the port running: ```bash kubectl describe pod kong-dp-kong -n kong-dp | grep Ports ``` **Expected Output** ```bash Ports: 8000/TCP, 8443/TCP, 8100/TCP Host Ports: 0/TCP, 0/TCP, 0/TCP ``` To create a new Kubernetes Service to expose the Data Plane metrics, execute the following ```bash cat < 8100/TCP 66s ``` #### Test the service. On one local terminal, expose the port 8100 using **port-forward** ```bash kubectl port-forward service/kong-dp-monitoring -n kong-dp 8100 ``` **Expected Output** ```bash Forwarding from 127.0.0.1:8100 -> 8100 Forwarding from [::1]:8100 -> 8100 ``` Now open another tab from your Cloud9 environment (go to **Actions** > **New Tab**) ```bash curl localhost:8100/metrics ``` **Sample Output** ```bash # HELP kong_datastore_reachable Datastore reachable from Kong, 0 is unreachable # TYPE kong_datastore_reachable gauge kong_datastore_reachable 1 # HELP kong_enterprise_license_errors Errors when collecting license info # TYPE kong_enterprise_license_errors counter kong_enterprise_license_errors 1 # HELP kong_memory_lua_shared_dict_bytes Allocated slabs in bytes in a shared_dict # TYPE kong_memory_lua_shared_dict_bytes gauge kong_memory_lua_shared_dict_bytes{shared_dict="kong"} 40960 …………. ``` #### Create the Prometheus Service Monitor Now, let's create the Prometheus Service Monitor collecting metrics from all Data Planes instances. The Service Monitor is based on the new **kong-dp-monitoring** Kubernetes Service we created before: ```bash cat < 8100/TCP 5m36s prometheus-operated ClusterIP None 9090/TCP 4m1s prometheus-operated-lb ClusterIP 10.100.26.253 9090/TCP 5s ``` #### Adding New Prometheus Service to Grafana Create a new Grafana Data Source based on the Prometheus Service URL: **http://prometheus-operated.kong-dp.svc.cluster.local:9090** To do so, copy the **output** from the following command and open in a browser. ```bash echo $GRAFANA_LB/datasources/new ``` Select **Prometheus** , paste **http://prometheus-operated.kong-dp.svc.cluster.local:9090** in HTTP > URL section and hit **Save & Test** ![grafana_newdatasource](/images/grafana_newdatasource.png) Now, based on this new Data Source, import the official Kong Grafana Dashboard with id **7424** To do so, copy the **output** from the following command and open in a browser. ```bash echo $GRAFANA_LB/dashboard/import ``` Enter **7424** under "Import via grafana.com" > **Load** ![grafana_newdashboard](/images/grafana_newdashboard.png) You should be able to see Kong Data Plane metrics now: ![grafana_dashboard1](/images/grafana_dashboard1.png)