Collect metrics with Datadog and the Prometheus plugin
Install the Datadog Agent and enable the Prometheus plugin. Configure the Datadog Agent with the Kong Gateway /metrics
endpoint and set kong.*
for metrics
. Restart the Datadog Agent, and send requests to generate metrics. You should see the metrics in Datadog Metrics summary.
Prerequisites
Kong Konnect
This is a Konnect tutorial and requires a Konnect personal access token.
-
Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Export your token to an environment variable:
export KONNECT_TOKEN='YOUR_KONNECT_PAT'
Copied to clipboard! -
Run the quickstart script to automatically provision a Control Plane and Data Plane, and configure your environment:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -k $KONNECT_TOKEN -e KONG_STATUS_LISTEN=0.0.0.0:8100 -p 8100:8100 --deck-output
Copied to clipboard!This sets up a Konnect Control Plane named
quickstart
, provisions a local Data Plane, and prints out the following environment variable exports:export DECK_KONNECT_TOKEN=$KONNECT_TOKEN export DECK_KONNECT_CONTROL_PLANE_NAME=quickstart export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com export KONNECT_PROXY_URL='http://localhost:8000'
Copied to clipboard!Copy and paste these into your terminal to configure your session.
Enable the Prometheus plugin
Before you configure the Datadog Agent to scrape metrics from Kong Gateway, you first need to enable the Prometheus plugin.
The following configuration enables the plugin globally and exports status code metrics, like the total number of HTTP requests:
echo '
_format_version: "3.0"
plugins:
- name: prometheus
config:
status_code_metrics: true
' | deck gateway apply -
Configure the Datadog Agent to collect Kong Gateway metrics
Now that the Prometheus plugin is configured, you can configure the Datadog Agent to scrape Kong Gateway metrics.
Create the conf.yaml
file:
touch ./.datadog-agent/conf.d/openmetrics.d/conf.yaml
This command uses the macOS directory location. For other distributions, see Datadog’s Agent configuration directory.
Copy and paste the following configuration in the conf.yaml
file:
instances:
- openmetrics_endpoint: http://localhost:8100/metrics
namespace: kong
metrics:
- kong.*
This configuration pulls all the kong.
prefixed metrics from the Kong Gateway metrics endpoint (http://localhost:8001/metrics
).
This configuration pulls all the kong.
prefixed metrics from the Kong Gateway Status API metrics endpoint (http://localhost:8100/metrics
).
Important: If you’re running Kong Gateway and the Datadog Agent in Docker, you’ll need to replace
localhost
in theconfig.yaml
with the name of the Kong Gateway container. Also, both containers need to be running on the same network for them to communicate.
Restart the Datadog Agent
You must restart the agent to start collecting metrics:
launchctl stop com.datadoghq.agent
launchctl start com.datadoghq.agent
This example is for macOS, see Datadog’s Agent commands documentation for all restart commands.
The Datadog Agent may take a few minutes to restart.
Validate
Now, you can validate that Datadog can scrape Kong Gateway metrics by first sending requests to generate metrics:
for _ in {1..10}; do
curl "$KONNECT_PROXY_URL/anything"; done
for _ in {1..10}; do
curl "http://localhost:8000/anything"; done
You can validate that Kong Gateway is sending metrics to Datadog by running the following:
curl -X GET "$DD_SITE_API_URL/api/v1/search?q=kong.kong_http_requests.count" \
-H "Accept: application/json" \
-H "DD-API-KEY: $DD_API_KEY" \
-H "DD-APPLICATION-KEY: $DD_APP_KEY"
You should get the following response:
{"results":{"metrics":["kong.kong_http_requests.count"],"hosts":[]}}
Alternatively, you can navigate to the Metrics Explorer page in the Datadog UI and search for kong.kong_http_requests.count
. You should see the 10 requests that you just sent.
Cleanup
Datadog
To stop collecting metrics, you can uninstall the Datadog Agent.