Log metrics for a Service, Route to a StatsD server. It can also be used to log metrics on Collectd daemon by enabling its Statsd plugin.
Terminology
plugin
: a plugin executing actions inside IAM before or after a request has been proxied to the upstream API.Service
: the IAM entity representing an external upstream API or microservice.Route
: the IAM entity representing a way to map downstream requests to upstream services.Consumer
: the IAM entity representing a developer or machine using the API. When using IAM, a Consumer only communicates with IAM which proxies every call to the said upstream API.Credential
: a unique string associated with a Consumer, also referred to as an API key.upstream service
: this refers to your own API/service sitting behind IAM, to which client requests are forwarded.
Configuration
This plugin is compatible with requests with the following protocols:
http
https
grpc
grpcs
This plugin is compatible with DB-less mode.
Enabling the plugin on a Service
With a database
Configure this plugin on a Service by making the following request:
$ curl -X POST http://localhost:8001/services/{service}/plugins \
--data "name=statsd" \
--data "config.host=127.0.0.1" \
--data "config.port=8125"
Without a database
Configure this plugin on a Service by adding this section do your declarative configuration file:
plugins:
- name: statsd
service: {service}
config:
host: 127.0.0.1
port: 8125
In both cases, {service}
is the id
or name
of the Service that this plugin configuration will target.
Enabling the plugin on a Route
With a database
Configure this plugin on a Route with:
$ curl -X POST http://localhost:8001/routes/{route}/plugins \
--data "name=statsd" \
--data "config.host=127.0.0.1" \
--data "config.port=8125"
Without a database
Configure this plugin on a Route by adding this section do your declarative configuration file:
plugins:
- name: statsd
route: {route}
config:
host: 127.0.0.1
port: 8125
In both cases, {route}
is the id
or name
of the Route that this plugin configuration will target.
Enabling the plugin on a Consumer
With a database
You can use the http://localhost:8001/plugins
endpoint to enable this plugin
on specific Consumers:
$ curl -X POST http://localhost:8001/consumers/{consumer}/plugins \
--data "name=statsd" \
\
--data "config.host=127.0.0.1" \
--data "config.port=8125"
Without a database
Configure this plugin on a Consumer by adding this section do your declarative configuration file:
plugins:
- name: statsd
consumer: {consumer}
config:
host: 127.0.0.1
port: 8125
In both cases, {consumer}
is the id
or username
of the Consumer that this plugin configuration will target.
You can combine consumer_id
and
service_id
in the same request, to furthermore narrow the scope of the plugin.
Global plugins
- Using a database, all plugins can be configured using the
http://localhost:8001/plugins/
endpoint. - Without a database, all plugins can be configured via the
plugins:
entry on the declarative configuration file.
A plugin which is not associated to any Service, Route or Consumer (or API, if you are using an older version of IAM) is considered "global", and will be run on every request. Read the Plugin Reference and the Plugin Precedence sections for more information.
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
form parameter | description |
---|---|
name | The name of the plugin to use, in this case statsd |
service_id | The id of the Service which this plugin will target. |
route_id | The id of the Route which this plugin will target. |
enabled default value: true | Whether this plugin will be applied. |
consumer_id | The id of the Consumer which this plugin will target. |
config.host
optional default value:
|
The IP address or host name to send data to. |
config.port
optional default value:
|
The port to send data to on the upstream server |
config.metrics
optional default value: All metrics |
List of Metrics to be logged. Available values are described under Metrics. |
config.prefix
optional default value:
|
String to be prefixed to each metric's name. |
Metrics
Metrics the plugin supports logging into the StatsD server.
Metric | description | namespace |
---|---|---|
request_count |
tracks the request | kong.<service_name>.request.count |
request_size |
tracks the request's body size in bytes | kong.<service_name>.request.size |
response_size |
tracks the response's body size in bytes | kong.<service_name>.response.size |
latency |
tracks the time interval between the request started and response received from the upstream server | kong.<service_name>.latency |
status_count |
tracks each status code returned in a response | kong.<service_name>.status.<status>.count and kong.<service_name>.status.<status>.total |
unique_users |
tracks unique users who made a requests to the underlying Service/Route | kong.<service_name>.user.uniques |
request_per_user |
tracks request/user | kong.<service_name>.user.<consumer_id>.count |
upstream_latency |
tracks the time it took for the final service to process the request | kong.<service_name>.upstream_latency |
kong_latency |
tracks the internal IAM latency that it took to run all the plugins | kong.<service_name>.kong_latency |
status_count_per_user |
tracks request/status/user | kong.<service_name>.user.<customer_id>.status.<status> and kong.<service_name>.user.<customer_id>.status.total |
Metric Fields
Plugin can be configured with any combination of Metrics, with each entry containing the following fields.
Field | description | allowed values |
---|---|---|
name |
StatsD metric's name | Metrics |
stat_type |
determines what sort of event the metric represents | gauge , timer , counter , histogram , meter and set |
sample_rate conditional |
sampling rate | number |
customer_identifier conditional |
authenticated user detail | consumer_id , custom_id , username |
Metric Requirements
- By default all metrics get logged.
- Metric with
stat_type
set tocounter
orgauge
must havesample_rate
defined as well. unique_users
metric only works withstat_type
asset
.status_count
,status_count_per_user
andrequest_per_user
work only withstat_type
ascounter
.status_count_per_user
,request_per_user
andunique_users
must havecustomer_identifier
defined.
IAM Process Errors
This logging plugin will only log HTTP request and response data. If you are looking for the IAM process error file (which is the nginx error file), then you can find it at /logs/error.log