Monitoring with StatsD
StatsD is a network daemon that collects and aggregates performance metrics by listening on the network for text based statistics data, published by applications.
This guide will help you setup a test Kong Gateway and StatsD service. Then you will generate sample requests to Kong Gateway and observe the collected monitoring data.
Prerequisites
- Docker is used to run StatsD and supporting services locally.
-
curl is used to send requests to Kong Gateway.
curl
is pre-installed on most systems. -
Netcat is installed as
nc
on the systemPATH
.nc
is used to send requests to the StatsD management interface.nc
is pre-installed on many systems.
Configure StatsD monitoring
-
Install Kong Gateway:
This step is optional if you wish to use an existing Kong Gateway installation. When using an existing Kong Gateway, you will need to modify the commands to account for network connectivity and installed Kong Gateway services and routes.
curl -Ls https://get.konghq.com/quickstart | bash -s -- -m
The
-m
flag instructs the script to install a mock service that is used in this guide to generate sample metrics.Once the Kong Gateway is ready, you will see the following message:
Kong Gateway Ready
-
Run a StatsD container to capture monitoring data:
docker run -d --rm -p 8126:8126 \ --name kong-quickstart-statsd --network=kong-quickstart-net \ statsd/statsd:latest
-
Install the StatsD Kong Gateway plugin, configuring the hostname and port of the listening StatsD service:
curl -X POST http://localhost:8001/plugins/ \ --data "name=statsd" \ --data "config.host=kong-quickstart-statsd" \ --data "config.port=8125"
You should receive a JSON response with details about the installed plugin.
-
Generate sample traffic to the mock service. This allows you to observe metrics generated from the StatsD plugin. The following command generates 60 requests over one minute. Run the following in a new terminal:
for _ in {1..60}; do {curl localhost:8000/mock/anything; sleep 1; } done
-
Query the StatsD management interface to see the collected metrics from Kong Gateway:
echo "counters" | nc localhost 8126
You should see a response similar to the following:
{ 'statsd.bad_lines_seen': 0, 'statsd.packets_received': 56, 'statsd.metrics_received': 56, 'kong.mock.request.count': 7, 'kong.mock.request.status.200': 7, 'kong.mock.request.status.total': 7 } END
See the StatsD plugin documentation for more information about how to use and configure the plugin.
Clean up
Once you are done experimenting with StatsD and Kong Gateway, you can use the following commands to stop and remove the software ran in this guide:
docker stop kong-quickstart-statsd
curl -Ls https://get.konghq.com/quickstart | bash -s -- -d
More information
-
How to monitor with Prometheus
describes how to use Prometheus to monitor Kong Gateway using the
Prometheus plugin. - See the Tracing API Reference for information about Kong Gateway’s tracing capabilities.