Log metrics for a Service, Route (or the deprecated API entity) 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.API
: a legacy entity used to represent your upstream services. Deprecated in favor of Services.
Configuration
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-advanced" \
--data "config.host=127.0.0.1" \
--data "config.port=8125" \
--data "config.allow_status_codes=200-205,400-499"
Without a database
Configure this plugin on a Service by adding this section do your declarative configuration file:
plugins:
- name: statsd-advanced
service: {service}
config:
host: 127.0.0.1
port: 8125
allow_status_codes: 200-205,400-499
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-advanced" \
--data "config.host=127.0.0.1" \
--data "config.port=8125" \
--data "config.allow_status_codes=200-205,400-499"
Without a database
Configure this plugin on a Route by adding this section do your declarative configuration file:
plugins:
- name: statsd-advanced
route: {route}
config:
host: 127.0.0.1
port: 8125
allow_status_codes: 200-205,400-499
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-advanced" \
\
--data "config.host=127.0.0.1" \
--data "config.port=8125" \
--data "config.allow_status_codes=200-205,400-499"
Without a database
Configure this plugin on a Consumer by adding this section do your declarative configuration file:
plugins:
- name: statsd-advanced
consumer: {consumer}
config:
host: 127.0.0.1
port: 8125
allow_status_codes: 200-205,400-499
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-advanced |
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. |
api_id | The id of the API which this plugin will target. Note: The API Entity is deprecated in favor of Services. |
config.host
default value:
|
The IP address or host name of StatsD server to send data to |
config.port
default value:
|
The port of StatsD server to send data to |
config.metrics
default value: All metrics |
List of Metrics to be logged. Available values are described under Metrics. |
config.prefix
default value:
|
String to be prefixed to each metric's name |
config.udp_packet_size
default value:
|
Combine UDP packet up to the size configured |
config.use_tcp
default value:
|
Use TCP instead of UDP |
config.allow_status_codes
default value: All responses are passed to log metrics |
List of status code ranges which are allowed to be logged in metrics |
By default the Plugin sends a packet for each metric it observes. udp_packet_size
configures the greatest datagram size the Plugin can combine. It should be less than 65507 according to UDP protocol. Please consider the MTU of the network when setting this parameter.
Metrics
Metric | description | namespace |
---|---|---|
request_count |
the request count | kong.service.<service_identifier>.request.count |
request_size |
the request's body size in bytes | kong.service.<service_identifier>.request.size |
response_size |
the response's body size in bytes | kong.service.<service_identifier>.response.size |
latency |
the time interval between the request and response | kong.service.<service_identifier>.latency |
status_count |
the status code | kong.service.<service_identifier>.status.<status>.count |
unique_users |
the unique users who made requests to the underlying Service/Route | kong.service.<service_identifier>.user.uniques |
request_per_user |
the request count per Consumer | kong.service.<service_identifier>.user.<consumer_id>.count |
upstream_latency |
the time it took for the final Service to process the request | kong.service.<service_identifier>.upstream_latency |
kong_latency |
the internal IAM latency that it took to run all the Plugins | kong.service.<service_identifier>.kong_latency |
status_count_per_user |
the status code for per Consumer per Service | kong.service.<service_identifier>.user.<customer_id>.status.<status> |
status_count_per_workspace |
the status code per Workspace | kong.service.<service_identifier>.workspace.<workspace_identifier>.status.<status> |
status_count_per_user_per_route |
the status code per Consumer per Route | kong.route.<route_id>.user.<customer_id>.status.<status> |
shdict_usage |
the usage of shared dict, sent once every minute | kong.node.<node_hostname>.shdict.<shdict_name>.free_space and kong.node.<node_hostname>.shdict.<shdict_name>.capacity |
If a request URI doesn't match any Routes, the following metrics will be sent instead:
Metric | description | namespace |
---|---|---|
request_count |
the request count | kong.global.unmatched.request.count |
request_size |
the request's body size in bytes | kong.global.unmatched.request.size |
response_size |
the response's body size in bytes | kong.global.unmatched.response.size |
latency |
the time interval between the request started and response received from the upstream server | kong.global.unmatched.latency |
status_count |
the status code | kong.global.unmatched.status.<status>.count |
kong_latency |
the internal IAM latency that it took to run all the Plugins | kong.global.unmatched.kong_latency |
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 |
service_identifier conditional |
Service detail | service_id , service_name , service_host , service_name_or_host |
workspace_identifier conditional |
Workspace detail | workspace_id , workspace_name |
Metric Behaviors
- 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
,status_count_per_user_per_route
andrequest_per_user
work only withstat_type
ascounter
.shdict_usage
work only withstat_type
asgauge
.status_count_per_user
,request_per_user
,unique_users
andstatus_count_per_user_per_route
must havecustomer_identifier
defined.- All metrics can optionally configure
service_identifier
; by default it's set toservice_name_or_host
. status_count_per_workspace
must haveworkspace_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